34 lines
841 B
Go
34 lines
841 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
|
|
// GetRecipeOfTheWeekHandler fetchs the current recipe of the week and returns it.
|
|
// If an error occurs, it will be returned and a recipe will not be returned.
|
|
//
|
|
// Until auth is reimplemented, there is no way to determine what user is making the
|
|
// call.
|
|
func (s *Server) GetRecipeOfTheWeekHandlerV2(ctx *gin.Context) {
|
|
userId := getUserId(ctx)
|
|
recipe, err := s.deps.RecipeService.GetRecipeOfTheWeek(userId)
|
|
|
|
if err != nil {
|
|
ctx.JSON(http.StatusBadRequest, gin.H{
|
|
"status": http.StatusBadRequest,
|
|
"message": fmt.Sprintf("[ERROR] Failed to get recipe of the week. %s", err.Error()),
|
|
})
|
|
return
|
|
}
|
|
|
|
ctx.JSON(http.StatusOK, gin.H{
|
|
"status": http.StatusOK,
|
|
"message": "[OK] Successfully retrieved recipe of the week.",
|
|
"recipe": recipe,
|
|
})
|
|
}
|