diff options
author | Vikas Kushwaha <dev@vikas.rocks> | 2025-02-11 16:31:08 +0530 |
---|---|---|
committer | Vikas Kushwaha <dev@vikas.rocks> | 2025-02-11 16:31:08 +0530 |
commit | 57eb8f6712361a3bf75983ce153fac4846dc0273 (patch) | |
tree | 269a168d59c917c4e313c819e2b4c3ff8175f912 /cmd/web/controller/home.go |
Initial commit
Diffstat (limited to 'cmd/web/controller/home.go')
-rw-r--r-- | cmd/web/controller/home.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/cmd/web/controller/home.go b/cmd/web/controller/home.go new file mode 100644 index 0000000..42e585e --- /dev/null +++ b/cmd/web/controller/home.go @@ -0,0 +1,79 @@ +package controller + +import ( + "projecty/cmd/web/model" + "projecty/internal/authentication" + "projecty/internal/database" + + "github.com/gofiber/fiber/v2" +) + +func HomePage(c *fiber.Ctx) error { + + var authenticatedUser model.User + + isAuthenticated, userID := authentication.AuthGet(c) + + if isAuthenticated { + db := database.Get() + db.Model(&authenticatedUser). + Where("id = ?", userID). + First(&authenticatedUser) + } + + return c.Render("home/index", fiber.Map{ + "PageTitle": "Home — Projecty", + "FiberCtx": c, + "NavBarActive": "home", + "AuthenticatedUser": authenticatedUser, + "CurrentPage": c.QueryInt("page"), + }, "layouts/app") +} + +func YourFeedPage(c *fiber.Ctx) error { + + var authenticatedUser model.User + + isAuthenticated, userID := authentication.AuthGet(c) + if isAuthenticated { + db := database.Get() + + db.Model(&authenticatedUser). + Where("id = ?", userID). + First(&authenticatedUser) + } else { + return c.Redirect("/") + } + + return c.Render("home/index", fiber.Map{ + "PageTitle": "Home — Projecty", + "Personal": true, + "FiberCtx": c, + "NavBarActive": "home", + "AuthenticatedUser": authenticatedUser, + "CurrentPage": c.QueryInt("page"), + }, "layouts/app") +} + +func TagFeedPage(c *fiber.Ctx) error { + + var user model.User + + isAuthenticated, userID := authentication.AuthGet(c) + + if isAuthenticated { + db := database.Get() + db.Model(&model.User{ID: userID}). + First(&user) + } + + return c.Render("home/index", fiber.Map{ + "PageTitle": "Home — Projecty", + "Tag": true, + "TagSlug": c.Params("slug"), + "FiberCtx": c, + "NavBarActive": "home", + "User": user, + "CurrentPage": c.QueryInt("page"), + }, "layouts/app") +} |