Blogs listing + Categories

This commit is contained in:
cdricms
2025-02-25 00:13:53 +01:00
parent ae228710e1
commit 793e3748f9
21 changed files with 695 additions and 192 deletions

View File

@@ -10,11 +10,17 @@ import (
)
func HandleGetBlogs(w http.ResponseWriter, r *http.Request) {
category := r.URL.Query().Get("category")
var blog []models.Blog
count, err := core.DB.NewSelect().
q := core.DB.NewSelect().
Model(&blog).
Relation("Author").
ScanAndCount(context.Background())
Relation("Author")
if len(category) > 0 {
q.Where("category = ?", category)
}
count, err := q.ScanAndCount(context.Background())
if err != nil {
core.JSONError{
Status: core.Error,