Backend file structure modifications, blogs routes ajustement
This commit is contained in:
58
backend/api/blogs.go
Normal file
58
backend/api/blogs.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
core "fr.latosa-escrima/api/core"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func HandleGetBlog(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Println("salut")
|
||||
emptyObject := make(map[string]interface{})
|
||||
|
||||
emptyJSON, json_err := json.Marshal(emptyObject)
|
||||
if json_err != nil {
|
||||
fmt.Println("Couldn't create the json object")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(emptyJSON))
|
||||
return
|
||||
}
|
||||
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Wrong method", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
blog := &core.Blog{
|
||||
BaseModel: bun.BaseModel{},
|
||||
BlogID: [16]byte{},
|
||||
Slug: "",
|
||||
Content: "",
|
||||
Label: "",
|
||||
AuthorID: [16]byte{},
|
||||
Published: time.Time{},
|
||||
Summary: "",
|
||||
Image: "",
|
||||
Href: "",
|
||||
Author: &core.User{},
|
||||
}
|
||||
|
||||
blog_uuid := r.PathValue("uuid")
|
||||
fmt.Println(blog_uuid)
|
||||
ctx := context.Background()
|
||||
err_db := core.DB.NewSelect().Model(blog).Where("uuid = ?", blog_uuid).Scan(ctx)
|
||||
if err_db != nil {
|
||||
log.Fatal(err_db)
|
||||
http.Error(w, "Can't use select", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(`{message: "Successfuly responded to request}`))
|
||||
}
|
||||
Reference in New Issue
Block a user