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) {