Backend file structure modifications, blogs routes ajustement

This commit is contained in:
gom-by
2025-01-15 15:17:41 +01:00
12 changed files with 329 additions and 221 deletions

52
backend/api/new_blog.go Normal file
View File

@@ -0,0 +1,52 @@
package api
import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"time"
core "fr.latosa-escrima/api/core"
"github.com/uptrace/bun"
)
func HandleCreateBlog(w http.ResponseWriter, r *http.Request) {
emptyObject := make(map[string]interface{})
emptyJSON, json_err := json.Marshal(emptyObject)
if json_err != nil {
fmt.Println("Couldn't create the json object")
w.Write(emptyJSON)
}
if r.Method != http.MethodPost {
}
err := r.ParseForm()
if err != nil {
}
user := &core.Blog{
BaseModel: bun.BaseModel{},
BlogID: [16]byte{},
Slug: "",
Content: "",
Label: "",
AuthorID: [16]byte{},
Published: time.Time{},
Summary: "",
Image: "",
Href: "",
Author: &core.User{},
}
_, err_db := core.DB.NewInsert().Model(user).Exec(context.Background())
if err_db != nil {
log.Fatal(err)
}
fmt.Println("User inserted successfully")
}