(FIX): Removed date requirement from rotf
This commit is contained in:
parent
53943dd183
commit
05f67566f8
@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/a-h/templ"
|
"github.com/a-h/templ"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -29,7 +28,6 @@ func HomePage(ctx *gin.Context) {
|
|||||||
|
|
||||||
loggedIn := domain.IsLoggedIn(ctx)
|
loggedIn := domain.IsLoggedIn(ctx)
|
||||||
|
|
||||||
|
|
||||||
var page templ.Component
|
var page templ.Component
|
||||||
if loggedIn {
|
if loggedIn {
|
||||||
userId := ctx.MustGet("userId").(int)
|
userId := ctx.MustGet("userId").(int)
|
||||||
@ -51,7 +49,7 @@ func HomePage(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the recipe of the week
|
// Get the recipe of the week
|
||||||
recipeOfTheWeek, err := deps.RecipeService.GetRecipeOfTheWeek(&userId, time.Now())
|
recipeOfTheWeek, err := deps.RecipeService.GetRecipeOfTheWeek(&userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(http.StatusInternalServerError, gin.H{
|
ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"status": http.StatusInternalServerError,
|
"status": http.StatusInternalServerError,
|
||||||
@ -63,7 +61,7 @@ func HomePage(ctx *gin.Context) {
|
|||||||
page = templates.HomePage(true, viewedRecipes, madeRecipes, recipeOfTheWeek)
|
page = templates.HomePage(true, viewedRecipes, madeRecipes, recipeOfTheWeek)
|
||||||
} else {
|
} else {
|
||||||
// Get the recipe of the week
|
// Get the recipe of the week
|
||||||
recipeOfTheWeek, err := deps.RecipeService.GetRecipeOfTheWeek(nil, time.Now())
|
recipeOfTheWeek, err := deps.RecipeService.GetRecipeOfTheWeek(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(http.StatusInternalServerError, gin.H{
|
ctx.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"status": http.StatusInternalServerError,
|
"status": http.StatusInternalServerError,
|
||||||
|
|||||||
@ -208,6 +208,8 @@ func (s *RecipeService) GetUserMadeRecipes(userId, limit int) ([]domain.Recipe,
|
|||||||
return s.recipeRepository.GetRecipes(ids, &userId)
|
return s.recipeRepository.GetRecipes(ids, &userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RecipeService) GetRecipeOfTheWeek(userId *int, date time.Time) (*domain.Recipe, error) {
|
// GetRecipeOfTheWeek searches for the most recent recipe of the week. If there is not a value,
|
||||||
return s.recipeRepository.GetRecipeOfTheWeek(userId, date)
|
// the recipe will be nil. The
|
||||||
|
func (s *RecipeService) GetRecipeOfTheWeek(userId *int) (*domain.Recipe, error) {
|
||||||
|
return s.recipeRepository.GetRecipeOfTheWeek(userId)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
package domain
|
package domain
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
type RecipeRepository interface {
|
type RecipeRepository interface {
|
||||||
CreateRecipe(recipe *Recipe) error
|
CreateRecipe(recipe *Recipe) error
|
||||||
GetRecipe(id int, userId *int) (*Recipe, error)
|
GetRecipe(id int, userId *int) (*Recipe, error)
|
||||||
@ -12,5 +10,5 @@ type RecipeRepository interface {
|
|||||||
GetUserFavoriteRecipes(id int) ([]Recipe, error)
|
GetUserFavoriteRecipes(id int) ([]Recipe, error)
|
||||||
GetRecipeTags(recipe *Recipe) error
|
GetRecipeTags(recipe *Recipe) error
|
||||||
GetRecipeFavorite(recipe *Recipe, userId int) error
|
GetRecipeFavorite(recipe *Recipe, userId int) error
|
||||||
GetRecipeOfTheWeek(userId *int, date time.Time) (*Recipe, error)
|
GetRecipeOfTheWeek(userId *int) (*Recipe, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,5 +12,5 @@ type RecipeService interface {
|
|||||||
GetUserFavoriteRecipes(id int) ([]Recipe, error)
|
GetUserFavoriteRecipes(id int) ([]Recipe, error)
|
||||||
GetUserViewedRecipes(userId, limit int) ([]Recipe, error)
|
GetUserViewedRecipes(userId, limit int) ([]Recipe, error)
|
||||||
GetUserMadeRecipes(userId, limit int) ([]Recipe, error)
|
GetUserMadeRecipes(userId, limit int) ([]Recipe, error)
|
||||||
GetRecipeOfTheWeek(userId *int, date time.Time) (*Recipe, error)
|
GetRecipeOfTheWeek(userId *int) (*Recipe, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
domain "github.com/haydenhargreaves/Potion/internal/domain/recipe"
|
domain "github.com/haydenhargreaves/Potion/internal/domain/recipe"
|
||||||
"github.com/lib/pq"
|
"github.com/lib/pq"
|
||||||
@ -834,7 +833,7 @@ func (r *RecipeRepository) GetRecipeFavorite(recipe *domain.Recipe, userId int)
|
|||||||
return nil
|
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()
|
tx, err := r.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user