Merging with dev/cedric

This commit is contained in:
gom-by
2025-01-28 18:30:56 +01:00
54 changed files with 1083 additions and 624 deletions

View File

@@ -0,0 +1,40 @@
package blogs
import (
"context"
"encoding/json"
"net/http"
"io"
core "fr.latosa-escrima/api/core"
)
func HandleNew(w http.ResponseWriter, r *http.Request) {
_, err := io.ReadAll(r.Body)
if err != nil {
core.JSONError{
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusNoContent)
return
}
var blog core.Blog
if err := json.NewDecoder(r.Body).Decode(&blog); err != nil {
core.JSONError{
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusBadRequest)
}
if _, err := core.DB.NewInsert().Model(&blog).Exec(context.Background()); err != nil {
core.JSONError{
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusNotAcceptable)
}
core.JSONSuccess{
Status: core.Success,
Message: "Blog inserted",
Data: blog,
}.Respond(w, http.StatusCreated)
}