From 57eb8f6712361a3bf75983ce153fac4846dc0273 Mon Sep 17 00:00:00 2001 From: Vikas Kushwaha Date: Tue, 11 Feb 2025 16:31:08 +0530 Subject: Initial commit --- cmd/web/controller/home.go | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 cmd/web/controller/home.go (limited to 'cmd/web/controller/home.go') 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") +} -- cgit v1.2.3