Skip to content
Snippets Groups Projects
Commit e308c371 authored by Torgrim's avatar Torgrim
Browse files

Implemented User Account Deletion Endpoint.

Updated User Registration Endpoint path.
parent aa105406
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
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)
}
......@@ -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:
......
......@@ -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}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment