Merge
This commit is contained in:
@@ -2,7 +2,6 @@ package blogs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
core "fr.latosa-escrima/api/core"
|
core "fr.latosa-escrima/api/core"
|
||||||
@@ -34,25 +33,3 @@ func HandleBlog(w http.ResponseWriter, r *http.Request) {
|
|||||||
}.Respond(w, http.StatusOK)
|
}.Respond(w, http.StatusOK)
|
||||||
return
|
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
|
|
||||||
}
|
|
||||||
@@ -8,15 +8,10 @@ import (
|
|||||||
core "fr.latosa-escrima/api/core"
|
core "fr.latosa-escrima/api/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleBlog(w http.ResponseWriter, r *http.Request) {
|
func HandleGetBlogs(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
var blog []core.Blog
|
||||||
|
count, err := core.DB.NewSelect().
|
||||||
blog_uuid := r.PathValue("uuid")
|
|
||||||
|
|
||||||
var blog core.Blog
|
|
||||||
_, err := core.DB.NewSelect().
|
|
||||||
Model(&blog).
|
Model(&blog).
|
||||||
Where("blog_id = ?", blog_uuid).
|
|
||||||
Relation("Author").
|
Relation("Author").
|
||||||
ScanAndCount(context.Background())
|
ScanAndCount(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -29,30 +24,8 @@ func HandleBlog(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
core.JSONSuccess{
|
core.JSONSuccess{
|
||||||
Status: core.Success,
|
Status: core.Success,
|
||||||
Message: "Status OK",
|
Message: fmt.Sprintf("%d blogs objects sent", count),
|
||||||
Data: blog,
|
Data: blog,
|
||||||
}.Respond(w, http.StatusOK)
|
}.Respond(w, http.StatusOK)
|
||||||
return
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
package blogs
|
||||||
|
|||||||
Reference in New Issue
Block a user