Merge pull request '(FIX): Fixed the issue with null returns from the RotW!' (#36) from dev into master
All checks were successful
Deploy application with Docker / build_and_deploy (push) Successful in 38s

Reviewed-on: #36
This commit is contained in:
Hayden Hargreaves 2025-07-26 23:21:34 -07:00
commit c5bbda1b69

View File

@ -3,6 +3,7 @@ package repository
import (
"database/sql"
"encoding/json"
"errors"
"fmt"
"strings"
@ -848,7 +849,8 @@ func (r *RecipeRepository) GetRecipeFavorite(recipe *domain.Recipe, userId int)
// 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.
// table and return it. If there is no entry, nil will be returned 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 {
@ -884,6 +886,9 @@ func (r *RecipeRepository) GetRecipeOfTheWeek(userId *int) (*domain.Recipe, erro
&recipe.Modified,
&recipe.Created,
); err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, nil
}
return nil, fmt.Errorf("Failed to location recipe in database: %s", err.Error())
}