diff --git a/internal/app/service/recipe_service.go b/internal/app/service/recipe_service.go index 6a34016..063db48 100644 --- a/internal/app/service/recipe_service.go +++ b/internal/app/service/recipe_service.go @@ -209,7 +209,7 @@ func (s *RecipeService) GetUserMadeRecipes(userId, limit int) ([]domain.Recipe, } // GetRecipeOfTheWeek searches for the most recent recipe of the week. If there is not a value, -// the recipe will be nil. The +// the recipe will be nil. Any errors will be bubbled to the caller. func (s *RecipeService) GetRecipeOfTheWeek(userId *int) (*domain.Recipe, error) { return s.recipeRepository.GetRecipeOfTheWeek(userId) } diff --git a/internal/infrastructure/database/repository/recipe_repository.go b/internal/infrastructure/database/repository/recipe_repository.go index 6d9fd9e..4b444f6 100644 --- a/internal/infrastructure/database/repository/recipe_repository.go +++ b/internal/infrastructure/database/repository/recipe_repository.go @@ -676,6 +676,9 @@ func (r *RecipeRepository) GetUserRecipes(id int) ([]domain.Recipe, error) { return recipes, nil } +// GetUserRecipes gets a list of a users favorited recipes. This function does not ensure the user is +// authenticated or exists. If nothing is found, a blank slice will be returned. The resulting list +// is sorted by the created dates, newest first. Any errors will be bubbled to the caller. func (r *RecipeRepository) GetUserFavoriteRecipes(id int) ([]domain.Recipe, error) { tx, err := r.db.Begin() if err != nil { @@ -766,8 +769,13 @@ func (r *RecipeRepository) GetUserFavoriteRecipes(id int) ([]domain.Recipe, erro // GetRecipeTags requires a recipe to be filled with at least an ID. This function will use the ID // defined in the provided recipe to fill the Tags array with the recipe's tags from the database. -// The recipe is modified in place and is not returned. Any errors will be bubbled to the caller. +// The recipe is modified in place and is not returned. If the recipe is nil, the function will +// return nothing (skipping). Any errors will be bubbled to the caller. func (r *RecipeRepository) GetRecipeTags(recipe *domain.Recipe) error { + if recipe == nil { + return nil + } + tx, err := r.db.Begin() if err != nil { tx.Rollback() @@ -808,8 +816,13 @@ func (r *RecipeRepository) GetRecipeTags(recipe *domain.Recipe) error { // GetRecipeFavorite requires a recipe to be filled with at least an ID. This function will use the // ID defined in the provided recipe to fill the favorite status of the recipe, based on the provided -// userId. The recipe is modified in place and is not returned. Any errors will be bubbled to the caller. +// userId. The recipe is modified in place and is not returned. If the recipe is nil, the function +// will return nothing (skipping). Any errors will be bubbled to the caller. func (r *RecipeRepository) GetRecipeFavorite(recipe *domain.Recipe, userId int) error { + if recipe == nil { + return nil + } + tx, err := r.db.Begin() if err != nil { tx.Rollback() @@ -833,6 +846,9 @@ func (r *RecipeRepository) GetRecipeFavorite(recipe *domain.Recipe, userId int) return nil } +// GetRecipeOfTheWeek searches for the most recent recipe of the week. If there is not a value, +// the recipe will be nil. This function simply collects the most recent entry in the recipeoftheweek +// table and return it. Any errors will be bubbled to the caller. func (r *RecipeRepository) GetRecipeOfTheWeek(userId *int) (*domain.Recipe, error) { tx, err := r.db.Begin() if err != nil {