This commit is contained in:
cdricms
2025-01-29 09:17:09 +01:00
parent 9bb72cd449
commit 7c66353e63
4 changed files with 5 additions and 54 deletions

View File

@@ -2,7 +2,6 @@ package blogs
import (
"context"
"fmt"
"net/http"
core "fr.latosa-escrima/api/core"
@@ -34,25 +33,3 @@ func HandleBlog(w http.ResponseWriter, r *http.Request) {
}.Respond(w, http.StatusOK)
return
}
func HandleGetBlogs(w http.ResponseWriter, r *http.Request) {
var blog []core.Blog
count, err := core.DB.NewSelect().
Model(&blog).
Relation("Author").
ScanAndCount(context.Background())
if err != nil {
core.JSONError{
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusNotAcceptable)
return
}
core.JSONSuccess{
Status: core.Success,
Message: fmt.Sprint("%d blogs objects sent", count),
Data: blog,
}.Respond(w, http.StatusOK)
return
}

View File

@@ -8,15 +8,10 @@ import (
core "fr.latosa-escrima/api/core"
)
func HandleBlog(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
blog_uuid := r.PathValue("uuid")
var blog core.Blog
_, err := core.DB.NewSelect().
func HandleGetBlogs(w http.ResponseWriter, r *http.Request) {
var blog []core.Blog
count, err := core.DB.NewSelect().
Model(&blog).
Where("blog_id = ?", blog_uuid).
Relation("Author").
ScanAndCount(context.Background())
if err != nil {
@@ -29,30 +24,8 @@ func HandleBlog(w http.ResponseWriter, r *http.Request) {
core.JSONSuccess{
Status: core.Success,
Message: "Status OK",
Message: fmt.Sprintf("%d blogs objects sent", count),
Data: blog,
}.Respond(w, http.StatusOK)
return
}
func HandleGetBlogs(w http.ResponseWriter, r *http.Request) {
var blog []core.Blog
count, err := core.DB.NewSelect().
Model(&blog).
Relation("Author").
ScanAndCount(context.Background())
if err != nil {
core.JSONError{
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusNotAcceptable)
return
}
core.JSONSuccess{
Status: core.Success,
Message: fmt.Sprint("%d blogs objects sent", count),
Data: blog,
}.Respond(w, http.StatusOK)
return
}

View File

@@ -0,0 +1 @@
package blogs