diff --git a/Go/cmd/globeboard/app.go b/Go/cmd/globeboard/app.go index c07d94b7fdf0a11f604f8f63441bcaf56d5514e6..b929882eb03f63035a616b93dde988d082f5b6de 100644 --- a/Go/cmd/globeboard/app.go +++ b/Go/cmd/globeboard/app.go @@ -39,6 +39,7 @@ func main() { mux := http.NewServeMux() mux.HandleFunc(Paths.Root, handlers.EmptyHandler) mux.HandleFunc(Endpoints.UserRegistration, util.UserRegistrationHandler) + mux.HandleFunc(Endpoints.UserDeletion, util.UserDeletionHandler) mux.HandleFunc(Endpoints.ApiKey, util.APIKeyHandler) mux.HandleFunc(Endpoints.RegistrationsID, dashboard.RegistrationsIdHandler) mux.HandleFunc(Endpoints.Registrations, dashboard.RegistrationsHandler) diff --git a/Go/internal/handlers/endpoint/util/user_delete_handler.go b/Go/internal/handlers/endpoint/util/user_delete_handler.go new file mode 100644 index 0000000000000000000000000000000000000000..30748a08994b4964ed7c788dbce582d44656c0e1 --- /dev/null +++ b/Go/internal/handlers/endpoint/util/user_delete_handler.go @@ -0,0 +1,45 @@ +package util + +import ( + "context" + authenticate "globeboard/auth" + "log" + "net/http" +) + +// UserDeletionHandler handles HTTP Delete requests +func UserDeletionHandler(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case http.MethodDelete: + deleteUser(w, r) + default: + http.Error(w, "REST Method: "+r.Method+" not supported. Only supported methods for this endpoint is:\n"+http.MethodPost, http.StatusNotImplemented) + return + } +} + +func deleteUser(w http.ResponseWriter, r *http.Request) { + ID := r.PathValue("ID") + if ID == "" { + http.Error(w, "Please Provide User ID", http.StatusBadRequest) + return + } + + // Initialize Firebase + client, err := authenticate.GetFireBaseAuthClient() // Assuming you have your initFirebase function from earlier + if err != nil { + http.Error(w, "Error initializing Firebase Auth", http.StatusInternalServerError) + return + } + + ctx := context.Background() + + err = client.DeleteUser(ctx, ID) + if err != nil { + log.Printf("error deleting user: %v\n", err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.WriteHeader(http.StatusNoContent) +} diff --git a/Go/internal/handlers/endpoint/util/user_register_handler.go b/Go/internal/handlers/endpoint/util/user_register_handler.go index 846e481f6868daebb4d7f0dfdc6424a70f381e6c..cee83284e8b1482baff39fe32f867f039688fe43 100644 --- a/Go/internal/handlers/endpoint/util/user_register_handler.go +++ b/Go/internal/handlers/endpoint/util/user_register_handler.go @@ -17,7 +17,7 @@ const ( ISE = "Internal Server Error" ) -// UserRegistrationHandler handles HTTP GET requests to retrieve supported languages. +// UserRegistrationHandler handles HTTP POST requests func UserRegistrationHandler(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodPost: diff --git a/Go/internal/utils/constants/Endpoints/endpoints.go b/Go/internal/utils/constants/Endpoints/endpoints.go index 2b2cf91991f45911cddd3c02c90e8587fb987d52..c9590ba581c3bed80604d82f3d22e042707227a6 100644 --- a/Go/internal/utils/constants/Endpoints/endpoints.go +++ b/Go/internal/utils/constants/Endpoints/endpoints.go @@ -8,7 +8,8 @@ import ( const ( ApiKey = Paths.Util + constants.APIVersion + "/key" - UserRegistration = Paths.Util + constants.APIVersion + "/register" + UserRegistration = Paths.Util + constants.APIVersion + "/user/register" + UserDeletion = Paths.Util + constants.APIVersion + "/user/delete/{ID}" RegistrationsID = Paths.Dashboards + constants.APIVersion + "/registrations/{ID}" Registrations = Paths.Dashboards + constants.APIVersion + "/registrations" Dashboards = Paths.Dashboards + constants.APIVersion + "/dashboard/{ID}"