diff options
| author | Bobby <[email protected]> | 2025-07-16 13:18:20 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-07-16 13:18:20 +0530 |
| commit | f13506cfba2da90764620dab2c624ac74767de62 (patch) | |
| tree | 1651ed298d3f7c9dc7f6a5ccc03da7f0d133f5d6 /controllers/posts.go | |
| parent | f352d2678f91e4f4ea6902d084fb9590e2819e92 (diff) | |
| download | imageboard-f13506cfba2da90764620dab2c624ac74767de62.tar.xz imageboard-f13506cfba2da90764620dab2c624ac74767de62.zip | |
constants and types refactor; next value for proper redirect on login
Diffstat (limited to 'controllers/posts.go')
| -rw-r--r-- | controllers/posts.go | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/controllers/posts.go b/controllers/posts.go index 6fdcd26..03535c7 100644 --- a/controllers/posts.go +++ b/controllers/posts.go @@ -1,22 +1,38 @@ package controllers
import (
+ "imageboard/config"
+ "imageboard/database"
+ "imageboard/utils/auth"
"imageboard/utils/shortcuts"
"github.com/gofiber/fiber/v2"
)
-func PostsController(ctx *fiber.Ctx) error {
- ctx.Locals("Title", "Posts")
+func PostsPageController(ctx *fiber.Ctx) error {
+ ctx.Locals("Title", config.PT_POST_LIST)
+ preferences := ctx.Locals("Preferences")
+ prefs, ok := preferences.(config.SitePreferences)
+ if !ok {
+ return fiber.NewError(fiber.StatusInternalServerError, "Invalid preferences type")
+ }
+
+ posts, err := database.GetPosts(prefs.PostsPerPage)
- searchQuery := ctx.Query("tags", "")
+ return shortcuts.Render(ctx, config.TEMPLATE_POST_LIST, fiber.Map{
+ "Posts": posts,
+ "Error": err,
+ })
+}
- customdata := struct {
- SearchQuery string
- Posts []interface{}
- }{
- SearchQuery: searchQuery,
- Posts: []interface{}{},
+func PostsUploadPageController(ctx *fiber.Ctx) error {
+ ctx.Locals("Title", config.PT_POST_NEW)
+ if !auth.IsAuthenticated(ctx) {
+ loginURL := auth.GetLoginURLWithRedirect(ctx)
+ ctx.Set("Location", loginURL)
+ ctx.Status(fiber.StatusFound)
+ return nil
}
- return shortcuts.Render(ctx, "posts", customdata)
+
+ return shortcuts.Render(ctx, config.TEMPLATE_POST_NEW, nil)
}
|
