Backend file structure modifications, blogs routes ajustement
This commit is contained in:
52
backend/api/new_blog.go
Normal file
52
backend/api/new_blog.go
Normal 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")
|
||||
}
|
||||
Reference in New Issue
Block a user