aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/controller/htmx/article-action.go
diff options
context:
space:
mode:
authorVikas Kushwaha <dev@vikas.rocks>2025-02-11 17:50:21 +0530
committerVikas Kushwaha <dev@vikas.rocks>2025-02-11 17:50:21 +0530
commite44397dcbb9454f89b8263738d5ccf1e20a12074 (patch)
tree1c2b5816c597ddd10c7afb68ed2af7cc2c26d56d /cmd/web/controller/htmx/article-action.go
parentc720f1f85e5ec7c93604462b7a70e1f84a1ce244 (diff)
Substituted 'article' with 'project' in filenamesHEADmaster
Diffstat (limited to 'cmd/web/controller/htmx/article-action.go')
-rw-r--r--cmd/web/controller/htmx/article-action.go105
1 files changed, 0 insertions, 105 deletions
diff --git a/cmd/web/controller/htmx/article-action.go b/cmd/web/controller/htmx/article-action.go
deleted file mode 100644
index a7b1f23..0000000
--- a/cmd/web/controller/htmx/article-action.go
+++ /dev/null
@@ -1,105 +0,0 @@
-package HTMXController
-
-import (
- "errors"
- "projecty/cmd/web/model"
- "projecty/internal/authentication"
- "projecty/internal/database"
- "projecty/internal/helper"
-
- "github.com/gofiber/fiber/v2"
- "gorm.io/gorm"
-)
-
-func ArticleFavoriteAction(c *fiber.Ctx) error {
-
- var article model.Article
- var authenticatedUser model.User
-
- isArticleFavorited := false
-
- isAuthenticated, userID := authentication.AuthGet(c)
- if !isAuthenticated {
- return helper.HTMXRedirectTo("/sign-in", "/htmx/sign-in", c)
-
- }
-
- db := database.Get()
-
- err := db.Model(&article).
- Where("slug = ?", c.Params("slug")).
- Preload("Favorites").
- Find(&article).Error
-
- if err != nil {
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return helper.HTMXRedirectTo("/sign-in", "/htmx/sign-in", c)
- }
- }
-
- authenticatedUser.ID = userID
-
- if article.FavoritedBy(userID) {
- db.Model(&article).Association("Favorites").Delete(&authenticatedUser)
- } else {
- db.Model(&article).Association("Favorites").Append(&authenticatedUser)
- isArticleFavorited = true
- }
-
- return c.Render("articles/partials/favorite-button", fiber.Map{
- "Article": article,
- "Slug": article.Slug,
- "IsArticleFavorited": isArticleFavorited,
- "IsOob": true,
- }, "layouts/app-htmx")
-}
-
-func ArticleFollowAction(c *fiber.Ctx) error {
-
- var article model.Article
- var authenticatedUser model.User
-
- isFollowed := false
-
- isAuthenticated, userID := authentication.AuthGet(c)
- if !isAuthenticated {
- return helper.HTMXRedirectTo("/sign-in", "/htmx/sign-in", c)
- }
-
- db := database.Get()
-
- err := db.Model(&article).
- Where("slug = ?", c.Params("slug")).
- Preload("Favorites").
- Preload("User.Followers").
- Find(&article).Error
-
- if err != nil {
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return helper.HTMXRedirectTo("/sign-in", "/htmx/sign-in", c)
- }
- }
-
- authenticatedUser.ID = userID
-
- if article.User.FollowedBy(userID) {
-
- f := model.Follow{
- FollowerID: article.UserID,
- FollowingID: userID,
- }
-
- db.Model(&article.User).Association("Followers").Find(&f)
- db.Delete(&f)
-
- } else {
- db.Model(&article.User).Association("Followers").Append(&model.Follow{FollowerID: article.UserID, FollowingID: userID})
- isFollowed = true
- }
-
- return c.Render("articles/partials/follow-button", fiber.Map{
- "Article": article,
- "IsFollowed": isFollowed,
- "IsOob": true,
- }, "layouts/app-htmx")
-}