diff --git a/internal/app/handlers/page_handler.go b/internal/app/handlers/page_handler.go index ae28e7b..0f3629e 100644 --- a/internal/app/handlers/page_handler.go +++ b/internal/app/handlers/page_handler.go @@ -5,7 +5,6 @@ import ( "fmt" "net/http" "strconv" - "time" "github.com/a-h/templ" "github.com/gin-gonic/gin" @@ -29,7 +28,6 @@ func HomePage(ctx *gin.Context) { loggedIn := domain.IsLoggedIn(ctx) - var page templ.Component if loggedIn { userId := ctx.MustGet("userId").(int) @@ -51,7 +49,7 @@ func HomePage(ctx *gin.Context) { } // Get the recipe of the week - recipeOfTheWeek, err := deps.RecipeService.GetRecipeOfTheWeek(&userId, time.Now()) + recipeOfTheWeek, err := deps.RecipeService.GetRecipeOfTheWeek(&userId) if err != nil { ctx.JSON(http.StatusInternalServerError, gin.H{ "status": http.StatusInternalServerError, @@ -63,7 +61,7 @@ func HomePage(ctx *gin.Context) { page = templates.HomePage(true, viewedRecipes, madeRecipes, recipeOfTheWeek) } else { // Get the recipe of the week - recipeOfTheWeek, err := deps.RecipeService.GetRecipeOfTheWeek(nil, time.Now()) + recipeOfTheWeek, err := deps.RecipeService.GetRecipeOfTheWeek(nil) if err != nil { ctx.JSON(http.StatusInternalServerError, gin.H{ "status": http.StatusInternalServerError, diff --git a/internal/app/service/recipe_service.go b/internal/app/service/recipe_service.go index 1d3f231..6a34016 100644 --- a/internal/app/service/recipe_service.go +++ b/internal/app/service/recipe_service.go @@ -208,6 +208,8 @@ func (s *RecipeService) GetUserMadeRecipes(userId, limit int) ([]domain.Recipe, return s.recipeRepository.GetRecipes(ids, &userId) } -func (s *RecipeService) GetRecipeOfTheWeek(userId *int, date time.Time) (*domain.Recipe, error) { - return s.recipeRepository.GetRecipeOfTheWeek(userId, date) +// GetRecipeOfTheWeek searches for the most recent recipe of the week. If there is not a value, +// the recipe will be nil. The +func (s *RecipeService) GetRecipeOfTheWeek(userId *int) (*domain.Recipe, error) { + return s.recipeRepository.GetRecipeOfTheWeek(userId) } diff --git a/internal/domain/recipe/repository.go b/internal/domain/recipe/repository.go index 55db598..8574035 100644 --- a/internal/domain/recipe/repository.go +++ b/internal/domain/recipe/repository.go @@ -1,7 +1,5 @@ package domain -import "time" - type RecipeRepository interface { CreateRecipe(recipe *Recipe) error GetRecipe(id int, userId *int) (*Recipe, error) @@ -12,5 +10,5 @@ type RecipeRepository interface { GetUserFavoriteRecipes(id int) ([]Recipe, error) GetRecipeTags(recipe *Recipe) error GetRecipeFavorite(recipe *Recipe, userId int) error - GetRecipeOfTheWeek(userId *int, date time.Time) (*Recipe, error) + GetRecipeOfTheWeek(userId *int) (*Recipe, error) } diff --git a/internal/domain/recipe/service.go b/internal/domain/recipe/service.go index 33b83ef..91bf12f 100644 --- a/internal/domain/recipe/service.go +++ b/internal/domain/recipe/service.go @@ -1,8 +1,6 @@ package domain import ( - "time" - "github.com/gin-gonic/gin" ) @@ -14,5 +12,5 @@ type RecipeService interface { GetUserFavoriteRecipes(id int) ([]Recipe, error) GetUserViewedRecipes(userId, limit int) ([]Recipe, error) GetUserMadeRecipes(userId, limit int) ([]Recipe, error) - GetRecipeOfTheWeek(userId *int, date time.Time) (*Recipe, error) + GetRecipeOfTheWeek(userId *int) (*Recipe, error) } diff --git a/internal/infrastructure/database/repository/recipe_repository.go b/internal/infrastructure/database/repository/recipe_repository.go index 960abee..6d9fd9e 100644 --- a/internal/infrastructure/database/repository/recipe_repository.go +++ b/internal/infrastructure/database/repository/recipe_repository.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "strings" - "time" domain "github.com/haydenhargreaves/Potion/internal/domain/recipe" "github.com/lib/pq" @@ -834,7 +833,7 @@ func (r *RecipeRepository) GetRecipeFavorite(recipe *domain.Recipe, userId int) return nil } -func (r *RecipeRepository) GetRecipeOfTheWeek(userId *int, date time.Time) (*domain.Recipe, error) { +func (r *RecipeRepository) GetRecipeOfTheWeek(userId *int) (*domain.Recipe, error) { tx, err := r.db.Begin() if err != nil { tx.Rollback()