Files
latosa-escrima/backend/api/blogs.go
2025-01-16 14:45:18 +01:00

45 lines
832 B
Go

package api
import (
"context"
"fmt"
"net/http"
core "fr.latosa-escrima/api/core"
)
func HandleGetBlog(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if r.Method != http.MethodGet {
core.JSONError{
Status: core.Error,
Message: "Method not Allowed",
}.Respond(w, http.StatusMethodNotAllowed)
return
}
blog_uuid := r.PathValue("uuid")
var blog core.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
}