Files
latosa-escrima/backend/api/get_user.go
2025-01-16 14:12:32 +01:00

52 lines
945 B
Go

package api
import (
"context"
"net/http"
"fr.latosa-escrima/api/core"
)
func HandleGetUser(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
core.JSONError{
Status: core.Error,
Message: "Method is not allowed.",
}.Respond(w, http.StatusMethodNotAllowed)
return
}
uuid := r.PathValue("user_uuid")
var user core.User
count, err := core.DB.NewSelect().
Model(&user).
Where("user_id = ?", uuid).
Limit(1).
ScanAndCount(context.Background())
if count == 0 {
core.JSONError{
Status: core.Error,
Message: "User not found.",
}.Respond(w, http.StatusNotFound)
return
}
if err != nil {
core.JSONError{
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusInternalServerError)
return
}
user.Password = ""
// TODO : Remove password
core.JSONSuccess{
Status: core.Success,
Message: "User found.",
Data: user,
}.Respond(w, http.StatusOK)
}