36 lines
744 B
Go
36 lines
744 B
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
core "fr.latosa-escrima/api/core"
|
|
)
|
|
|
|
func handlerCreateUser(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
if r.Method != http.MethodPost {
|
|
w.WriteHeader(http.StatusCreated)
|
|
w.Write([]byte(`{"message": "Resource created successfully"}`))
|
|
}
|
|
|
|
user := &core.User{
|
|
FirstName: "John",
|
|
LastName: "Doe",
|
|
Email: "john.doe@example.com",
|
|
Phone: "1234567890",
|
|
Password: "1234",
|
|
}
|
|
|
|
_, err := core.DB.NewInsert().Model(user).Exec(context.Background())
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
fmt.Println("User inserted successfully")
|
|
w.WriteHeader(http.StatusOK)
|
|
w.Write([]byte(`{"message": "Inserted the user"}`))
|
|
}
|