package com.google.sps;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.CollectionReference;
import com.google.cloud.firestore.Firestore;
import com.google.cloud.firestore.Query;
import com.google.cloud.firestore.QueryDocumentSnapshot;
import com.google.cloud.firestore.QuerySnapshot;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.cloud.FirestoreClient;
import com.google.api.core.ApiFuture;

import java.io.IOException;
import java.util.List;

import org.springframework.web.bind.annotation.RestController;

@RestController
public class ValidateUsername {
  @PostMapping("/validateUsername")
  Boolean checkUsername(@RequestBody String username) throws Exception {
    return isUniqueUsername(username);
  }

  private static Boolean isUniqueUsername(String username) throws Exception {
    Firebase.init();
    Firestore db = FirestoreClient.getFirestore();

    CollectionReference users = db.collection("users");

    Query query = users.whereEqualTo("username", username);

    ApiFuture<QuerySnapshot> querySnapshot = query.get();
    List<QueryDocumentSnapshot> queryDocuments = querySnapshot.get().getDocuments();

    if (queryDocuments.isEmpty()) {
      return true;
    }

    return false;
  }
}

@@ -142,57 +142,71 @@
 dy;%0A
-%0A
 import 
-com.google.auth.oauth2.GoogleCredentials;
+org.springframework.web.bind.annotation.RestController;%0A
 %0Aimp
@@ -453,92 +453,8 @@
 ot;%0A
-import com.google.firebase.FirebaseApp;%0Aimport com.google.firebase.FirebaseOptions;%0A
 impo
@@ -554,109 +554,17 @@
 ava.
-io.IOException;%0Aimport java.util.List;%0A%0Aimport org.springframework.web.bind.annotation.RestController
+util.List
 ;%0A%0A@

Remove unused imports.