33 lines
613 B
Go
33 lines
613 B
Go
package blogs
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
core "fr.latosa-escrima/core"
|
|
"fr.latosa-escrima/core/models"
|
|
)
|
|
|
|
func HandleGetBlogs(w http.ResponseWriter, r *http.Request) {
|
|
var blog []models.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.Sprintf("%d blogs objects sent", count),
|
|
Data: blog,
|
|
}.Respond(w, http.StatusOK)
|
|
return
|
|
}
|