(FIX): Removed date requirement from rotf

This commit is contained in:
Hayden Hargreaves 2025-07-26 22:46:45 -07:00
parent 53943dd183
commit 05f67566f8
5 changed files with 9 additions and 14 deletions

View File

@ -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,

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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()