37 lines
687 B
Go
37 lines
687 B
Go
package blogs
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
core "fr.latosa-escrima/core"
|
|
"fr.latosa-escrima/core/models"
|
|
)
|
|
|
|
func HandleBlog(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
blog_uuid := r.PathValue("uuid")
|
|
|
|
var blog models.Blog
|
|
_, err := core.DB.NewSelect().
|
|
Model(&blog).
|
|
Where("blog_id = ?", blog_uuid).
|
|
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: "Status OK",
|
|
Data: blog,
|
|
}.Respond(w, http.StatusOK)
|
|
return
|
|
}
|