@@ -0,0 +1,1782 @@
+package com.google.sps;%0A%0Aimport org.springframework.web.bind.annotation.PostMapping;%0Aimport org.springframework.web.bind.annotation.RequestBody;%0A%0Aimport com.google.auth.oauth2.GoogleCredentials;%0Aimport com.google.cloud.firestore.CollectionReference;%0Aimport com.google.cloud.firestore.Firestore;%0Aimport com.google.cloud.firestore.Query;%0Aimport com.google.cloud.firestore.QueryDocumentSnapshot;%0Aimport com.google.cloud.firestore.QuerySnapshot;%0Aimport com.google.firebase.FirebaseApp;%0Aimport com.google.firebase.FirebaseOptions;%0Aimport com.google.firebase.cloud.FirestoreClient;%0Aimport com.google.api.core.ApiFuture;%0A%0Aimport java.io.IOException;%0Aimport java.util.List;%0A%0Aimport org.springframework.web.bind.annotation.RestController;%0A%0A@RestController%0Apublic class ValidateUsername %7B%0A  @PostMapping(%22/validateUsername%22)%0A  String checkUsername(@RequestBody String username) throws Exception %7B%0A    return isUniqueUsername(username);%0A  %7D%0A%0A  private static String isUniqueUsername(String username) throws IOException %7B%0A    String projectId = %22phoebeliang-step%22;%0A    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault();%0A%0A    FirebaseOptions options = new FirebaseOptions.Builder().setCredentials(credentials).setProjectId(projectId).build();%0A    FirebaseApp.initializeApp(options);%0A%0A    Firestore db = FirestoreClient.getFirestore();%0A%0A    CollectionReference users = db.collection(%22users%22);%0A%0A    Query query = users.whereEqualTo(%22username%22, username);%0A%0A    try %7B%0A      ApiFuture%3CQuerySnapshot%3E querySnapshot = query.get();%0A      List%3CQueryDocumentSnapshot%3E queryDocuments = querySnapshot.get().getDocuments();%0A%0A      if (queryDocuments.isEmpty()) %7B%0A        return %22true%22;%0A      %7D%0A    %7D catch (Exception e) %7B%0A      System.out.println(e);%0A    %7D%0A%0A    return %22false%22;%0A  %7D%0A%7D%0A

Implement backend unique usernames check.