Blogs listing + Categories
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user