From 15cb03589c8b40506cbe9bb7bccafabd79783813 Mon Sep 17 00:00:00 2001 From: Hayden Hargreaves Date: Tue, 15 Jul 2025 21:44:20 -0700 Subject: [PATCH] (UI/FIX): Fixed the view engagement to only run on clicks. But that means we have to redirect from the handler. I didn't want to, but I guess that makes it easier when more pages direct to the recipe page. --- internal/app/handlers/engagement_handler.go | 7 ++- internal/app/handlers/page_handler.go | 27 +++++------ internal/app/service/recipe_service.go | 4 +- .../database/repository/recipe_repository.go | 2 - internal/templates/pages/profile.templ | 14 +++--- internal/templates/pages/profile_templ.go | 45 ++++++++++--------- internal/templates/pages/recipe.templ | 1 + internal/templates/pages/recipe_templ.go | 4 +- internal/templates/pages/search.templ | 10 +++-- internal/templates/pages/search_templ.go | 24 +++++----- 10 files changed, 76 insertions(+), 62 deletions(-) diff --git a/internal/app/handlers/engagement_handler.go b/internal/app/handlers/engagement_handler.go index dcca6d5..1f80b7b 100644 --- a/internal/app/handlers/engagement_handler.go +++ b/internal/app/handlers/engagement_handler.go @@ -1,6 +1,7 @@ package handlers import ( + "fmt" "net/http" "strconv" @@ -19,7 +20,8 @@ func EngagementViewRecipe(ctx *gin.Context) { "message": err.Error(), }) } else { - ctx.Status(http.StatusNoContent) + ctx.Header("HX-Redirect", fmt.Sprintf(domain.WEB_RECIPE, recipeId)) + ctx.Status(http.StatusOK) } return } @@ -32,7 +34,8 @@ func EngagementViewRecipe(ctx *gin.Context) { "message": err.Error(), }) } else { - ctx.Status(http.StatusNoContent) + ctx.Header("HX-Redirect", fmt.Sprintf(domain.WEB_RECIPE, recipeId)) + ctx.Status(http.StatusOK) } } diff --git a/internal/app/handlers/page_handler.go b/internal/app/handlers/page_handler.go index 3b36eb4..cadcee1 100644 --- a/internal/app/handlers/page_handler.go +++ b/internal/app/handlers/page_handler.go @@ -129,19 +129,20 @@ func RecipePage(ctx *gin.Context) { } // Add engagement - if loggedIn { - if _, err = deps.EngagementService.UserViewRecipe(*userId, recipe.Id); err != nil { - fmt.Printf("ERROR: %s\n", err.Error()) - ctx.JSON(400, err.Error()) - return - } - } else { - if _, err = deps.EngagementService.ViewRecipe(recipe.Id); err != nil { - fmt.Printf("ERROR: %s\n", err.Error()) - ctx.JSON(400, err.Error()) - return - } - } + // BUG: Don't want to do this here + // if loggedIn { + // if _, err = deps.EngagementService.UserViewRecipe(*userId, recipe.Id); err != nil { + // fmt.Printf("ERROR: %s\n", err.Error()) + // ctx.JSON(400, err.Error()) + // return + // } + // } else { + // if _, err = deps.EngagementService.ViewRecipe(recipe.Id); err != nil { + // fmt.Printf("ERROR: %s\n", err.Error()) + // ctx.JSON(400, err.Error()) + // return + // } + // } title := "Potion - View Recipe" page := pages.RecipePage(*recipe, *user, loggedIn) diff --git a/internal/app/service/recipe_service.go b/internal/app/service/recipe_service.go index 0f5a68b..be4ba73 100644 --- a/internal/app/service/recipe_service.go +++ b/internal/app/service/recipe_service.go @@ -33,7 +33,7 @@ func NewRecipeService(recipeRepository domain.RecipeRepository) domain.RecipeSer // occur. // // TODO: Implement validation in the API. -// TODO: Implement image creation and tag creation. +// TODO: Implement image creation. func (s *RecipeService) CreateRecipe(ctx *gin.Context) (*domain.Recipe, error) { // Ensure user is logged in if !domainServer.IsLoggedIn(ctx) { @@ -110,7 +110,7 @@ func (s *RecipeService) CreateRecipe(ctx *gin.Context) (*domain.Recipe, error) { if image != nil { } - // TODO: Create the tags in the database + // Create the tags if len(tags) > 0 { if err := s.recipeRepository.CreateRecipeTags(recipe, tags); err != nil { return &recipe, fmt.Errorf("Failed to attach/create tags. %s\n", err.Error()) diff --git a/internal/infrastructure/database/repository/recipe_repository.go b/internal/infrastructure/database/repository/recipe_repository.go index da5c6f7..a0a578d 100644 --- a/internal/infrastructure/database/repository/recipe_repository.go +++ b/internal/infrastructure/database/repository/recipe_repository.go @@ -251,8 +251,6 @@ func (r *RecipeRepository) SearchRecipes(filters domain.SearchFilters) ([]domain } } - // TODO: Title search somehow... - // Merge condition strings mealString := fmt.Sprintf("(%s)", strings.Join(mealConditions, " OR ")) timeString := fmt.Sprintf("(%s)", strings.Join(timeConditions, " OR ")) diff --git a/internal/templates/pages/profile.templ b/internal/templates/pages/profile.templ index 1dcf8a2..c13d33e 100644 --- a/internal/templates/pages/profile.templ +++ b/internal/templates/pages/profile.templ @@ -44,8 +44,7 @@ templ userDetailsSection(user domainUser.User, recipeCount int) { } else { }
@@ -67,7 +66,7 @@ templ recipesSection(recipes []domainRecipe.Recipe) {

My Recipes