Reorganized API + added db migrations
Read the README file for more informations
This commit is contained in:
47
backend/api/users/new.go
Normal file
47
backend/api/users/new.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
core "fr.latosa-escrima/api/core"
|
||||
)
|
||||
|
||||
func HandleNew(w http.ResponseWriter, r *http.Request) {
|
||||
var user core.User
|
||||
err := json.NewDecoder(r.Body).Decode(&user)
|
||||
if err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
Message: err.Error(),
|
||||
}.Respond(w, http.StatusNotAcceptable)
|
||||
return
|
||||
}
|
||||
log.Println("User : ", 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)
|
||||
}
|
||||
Reference in New Issue
Block a user