From 9ac735666832df04801b03937165ccb96f3fa648 Mon Sep 17 00:00:00 2001 From: Hayden Hargreaves Date: Wed, 9 Jul 2025 22:21:49 -0700 Subject: [PATCH] (DOC/FEAT): Updated doc comments and completed the search redirection! The search is nearly complete for the initial implementation. Just need to figure out what to do with the text search provided, make any required UI changes, and eventual implement pagination via a "load more" button. --- internal/app/handlers/auth_handler.go | 4 +- internal/app/handlers/recipe_handler.go | 12 ++- internal/app/handlers/state_handler.go | 7 +- internal/app/service/auth_service.go | 4 +- internal/app/service/recipe_service.go | 26 ++--- internal/domain/server/routes.go | 6 ++ internal/domain/server/server.go | 4 + .../database/repository/recipe_repository.go | 6 ++ internal/templates/components/dropdowns.templ | 13 ++- .../templates/components/dropdowns_templ.go | 13 +-- .../templates/components/search_bar.templ | 3 +- .../templates/components/search_bar_templ.go | 35 ++++--- internal/templates/pages/create.templ | 2 +- internal/templates/pages/create_templ.go | 15 ++- internal/templates/pages/home.templ | 3 +- internal/templates/pages/home_templ.go | 4 +- internal/templates/pages/search.templ | 2 +- internal/templates/pages/search_templ.go | 2 +- web/static/css/tailwind.css | 97 ++++++++----------- 19 files changed, 149 insertions(+), 109 deletions(-) diff --git a/internal/app/handlers/auth_handler.go b/internal/app/handlers/auth_handler.go index 6b28357..2da9eff 100644 --- a/internal/app/handlers/auth_handler.go +++ b/internal/app/handlers/auth_handler.go @@ -42,7 +42,7 @@ func GoogleCallback(ctx *gin.Context) { jwt, int(time.Now().Add(7*24*time.Hour).Sub(time.Now()).Seconds()), "/", - "localhost", + "", // TODO: Real live domain false, // TODO: True in prod true, ) @@ -60,6 +60,6 @@ func GoogleCallback(ctx *gin.Context) { // This route will direct the user back to the home page. func Logout(ctx *gin.Context) { // TODO: Use same values as the GoogleCallback function - ctx.SetCookie("jwt_token", "", -1, "/", "localhost", false, true) + ctx.SetCookie("jwt_token", "", -1, "/", "", false, true) // TODO: Update settings ctx.Redirect(http.StatusSeeOther, domain.WEB_HOME) } diff --git a/internal/app/handlers/recipe_handler.go b/internal/app/handlers/recipe_handler.go index 8e7b8bc..a256307 100644 --- a/internal/app/handlers/recipe_handler.go +++ b/internal/app/handlers/recipe_handler.go @@ -47,6 +47,7 @@ func toBits(arr []string) (bits int) { func SearchRecipes(ctx *gin.Context) { deps := ctx.MustGet("deps").(*domain.InjectedDependencies) + // create filters filters := domainRecipe.SearchFilters{ Search: ctx.PostForm("search"), // string, search query for titles @@ -61,14 +62,21 @@ func SearchRecipes(ctx *gin.Context) { ctx.SetCookie( "search-filters", string(bytes), - int(time.Now().Add(2*time.Hour).Sub(time.Now()).Seconds()), + int(time.Now().Add(24 * time.Hour).Sub(time.Now()).Seconds()), "/", - "localhost", // TODO: real domain + "", // TODO: Need an actual domain false, // TODO: True in prod true, ) } + redirect := ctx.PostForm("redirect") + if redirect == "true" { + ctx.Header("HX-Redirect", domain.WEB_SEARCH) + ctx.Status(http.StatusOK) + return + } + recipes, err := deps.RecipeService.SearchRecipes(filters) if err != nil { ctx.JSON(http.StatusOK, gin.H{"error": err.Error()}) diff --git a/internal/app/handlers/state_handler.go b/internal/app/handlers/state_handler.go index 274f864..91c2de3 100644 --- a/internal/app/handlers/state_handler.go +++ b/internal/app/handlers/state_handler.go @@ -6,11 +6,12 @@ import ( "strings" "github.com/gin-gonic/gin" + domain "github.com/haydenhargreaves/Potion/internal/domain/server" ) const TAG_HTML = `
  • >pos)&1 == 1 } +// SearchRecipes will search the recipe table using the provided filters and return an unbound list +// of recipes. The filters are fairly complex, they are stored as bit masks. A more details +// description can be found in the recipe service implementation. Any errors will be bubbled to the +// caller. +// +// TODO: Pagination is required, to provide infinite scroll. func (r *RecipeRepository) SearchRecipes(filters domain.SearchFilters) ([]domain.Recipe, error) { tx, err := r.db.Begin() if err != nil { diff --git a/internal/templates/components/dropdowns.templ b/internal/templates/components/dropdowns.templ index 34e71ae..2940e38 100644 --- a/internal/templates/components/dropdowns.templ +++ b/internal/templates/components/dropdowns.templ @@ -1,18 +1,15 @@ package components -import "fmt" import domainRecipe "github.com/haydenhargreaves/Potion/internal/domain/recipe" // isBitActive returns true when the bit at pos (0 indexed) is true. func isBitActive(bits, pos int) bool { -x := (bits>>pos)&1 == 1 -fmt.Printf("BITS: %d, POS: %d, VAL: %v\n", bits, pos, x) -return x +return (bits>>pos)&1 == 1 } templ dropdownButton(content, name, value string, selected bool) {