Added some routes for users
And some fixes
This commit is contained in:
39
backend/api/delete_user.go
Normal file
39
backend/api/delete_user.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"fr.latosa-escrima/api/core"
|
||||
)
|
||||
|
||||
func HandleDeleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodDelete {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
Message: "Method is not allowed.",
|
||||
}.Respond(w, http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
uuid := r.PathValue("user_uuid")
|
||||
_, err := core.DB.NewDelete().
|
||||
Model((*core.User)(nil)).
|
||||
Where("user_id = ?", uuid).
|
||||
Exec(context.Background())
|
||||
|
||||
if err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
Message: err.Error(),
|
||||
}.Respond(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO : Remove password
|
||||
core.JSONSuccess{
|
||||
Status: core.Success,
|
||||
Message: "User deleted.",
|
||||
Data: nil,
|
||||
}.Respond(w, http.StatusOK)
|
||||
}
|
||||
Reference in New Issue
Block a user