46 lines
826 B
Go
46 lines
826 B
Go
package users
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"fr.latosa-escrima/core"
|
|
"fr.latosa-escrima/core/models"
|
|
)
|
|
|
|
func HandleUser(w http.ResponseWriter, r *http.Request) {
|
|
uuid := r.PathValue("user_uuid")
|
|
var user models.User
|
|
count, err := core.DB.NewSelect().
|
|
Model(&user).
|
|
Where("user_id = ?", uuid).
|
|
Relation("Roles").
|
|
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)
|
|
}
|