package api import ( "context" "encoding/json" "io" "log" "net/http" core "fr.latosa-escrima/api/core" ) func HandleCreateUser(w http.ResponseWriter, r *http.Request) { body, err := io.ReadAll(r.Body) if err != nil { core.JSONError{ Status: core.Error, Message: "The body of your message is invalid.", }.Respond(w, http.StatusNotAcceptable) return } var user core.User err = json.Unmarshal(body, &user) if err != nil { core.JSONError{ Status: core.Error, Message: "It seems your body in invalid JSON.", }.Respond(w, http.StatusNotAcceptable) return } log.Println(user) res, err := user.Insert(context.Background()) log.Println(res) // if res == nil { // core.JSONError{ // Status: core.Error, // Message: "The user couldn't be inserted.", // }.Respond(w, http.StatusNotAcceptable) // return // } if err != nil { core.JSONError{ Status: core.Error, Message: err.Error(), }.Respond(w, http.StatusInternalServerError) return } core.JSONSuccess{ Status: core.Success, Message: "User inserted successfully.", Data: nil, }.Respond(w, http.StatusCreated) }