aboutsummaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
authorBobby <[email protected]>2025-07-16 15:28:11 +0530
committerBobby <[email protected]>2025-07-16 15:28:11 +0530
commitbb54eaf6623acdcfb2e9056eb803260dff2150a5 (patch)
tree3a7fb956911f8e40c4e86ca9fde48b4ebef1a217 /controllers
parentf13506cfba2da90764620dab2c624ac74767de62 (diff)
downloadimageboard-bb54eaf6623acdcfb2e9056eb803260dff2150a5.tar.xz
imageboard-bb54eaf6623acdcfb2e9056eb803260dff2150a5.zip
enhance requests queries for posts; integrate backend with search
Diffstat (limited to 'controllers')
-rw-r--r--controllers/home.go9
-rw-r--r--controllers/posts.go33
2 files changed, 36 insertions, 6 deletions
diff --git a/controllers/home.go b/controllers/home.go
index 9fd0d33..dfa5d13 100644
--- a/controllers/home.go
+++ b/controllers/home.go
@@ -9,5 +9,12 @@ import (
func HomePageController(ctx *fiber.Ctx) error {
ctx.Locals("Title", config.PT_HOME)
- return shortcuts.Render(ctx, config.TEMPLATE_HOME, nil)
+ queryRatings := map[string]bool{
+ "safe": true,
+ "questionable": true,
+ "sensitive": true,
+ }
+ return shortcuts.Render(ctx, config.TEMPLATE_HOME, fiber.Map{
+ "QueryRatings": queryRatings,
+ })
}
diff --git a/controllers/posts.go b/controllers/posts.go
index 03535c7..c14d793 100644
--- a/controllers/posts.go
+++ b/controllers/posts.go
@@ -11,17 +11,40 @@ import (
func PostsPageController(ctx *fiber.Ctx) error {
ctx.Locals("Title", config.PT_POST_LIST)
- preferences := ctx.Locals("Preferences")
- prefs, ok := preferences.(config.SitePreferences)
+ preferences, ok := ctx.Locals("Preferences").(config.SitePreferences)
if !ok {
return fiber.NewError(fiber.StatusInternalServerError, "Invalid preferences type")
}
- posts, err := database.GetPosts(prefs.PostsPerPage)
+ request, ok := ctx.Locals("Request").(config.Request)
+ if !ok {
+ return fiber.NewError(fiber.StatusInternalServerError, "Invalid request type")
+ }
+
+ queryTags := ""
+ queryRatings := map[string]bool{}
+ for _, param := range request.Query {
+ switch param.Key {
+ case "tags":
+ queryTags = param.Value
+ case "rating":
+ queryRatings[param.Value] = true
+ }
+ }
+
+ if len(queryRatings) == 0 {
+ for _, rating := range []string{"safe", "questionable", "sensitive"} {
+ queryRatings[rating] = true
+ }
+ }
+
+ posts, err := database.GetPosts(preferences.PostsPerPage)
return shortcuts.Render(ctx, config.TEMPLATE_POST_LIST, fiber.Map{
- "Posts": posts,
- "Error": err,
+ "Posts": posts,
+ "Error": err,
+ "QueryTags": queryTags,
+ "QueryRatings": queryRatings,
})
}