package service import ( "net/http" "time" "github.com/gin-gonic/gin" domain "github.com/haydenhargreaves/Potion/internal/domain/recipe" ) // RecipeService implements the domain.RecipeService defined in the domain module. type RecipeService struct { recipeRepository domain.RecipeRepository } // Compile-time check to ensure the RecipeService implements domain.RecipeService var _ domain.RecipeService = (*RecipeService)(nil) // NewRecipeService creates a user service object which can be passed into the context. The service // requires a recipe repository which it will use to hit the database when needed. func NewRecipeService(recipeRepository domain.RecipeRepository) domain.RecipeService { return &RecipeService{recipeRepository: recipeRepository} } func (s *RecipeService) CreateRecipe(ctx *gin.Context) domain.Recipe { // TODO: Implement recipe := domain.Recipe{ Title: "Delicious Go Curry", Description: "A savory and easy-to-make curry, perfect for weeknights.", Instructions: []string{ "Chop all vegetables.", "Sauté onions and garlic until fragrant.", "Add curry paste and stir for 1 minute.", "Add coconut milk and vegetables, simmer until cooked.", "Serve with rice.", }, Serves: 4, Difficulty: 3, Duration: domain.RecipeDuration{ Total: 45, Prep: 15, Cook: 30, }, Category: domain.MealDinner, // Using our EMeal type. Ensure this matches an updated enum value. Ingredients: []domain.RecipeIngredient{ {Name: "Onion", Quantity: "1 large"}, {Name: "Garlic", Quantity: "3 cloves"}, {Name: "Curry Paste", Quantity: "2 tbsp"}, {Name: "Coconut Milk", Quantity: "400ml can"}, {Name: "Broccoli", Quantity: "1 head"}, {Name: "Bell Pepper", Quantity: "1 red"}, {Name: "Rice", Quantity: "As needed"}, }, UserId: 3, Created: time.Now(), } if err := s.recipeRepository.CreateRecipe(&recipe); err != nil { ctx.JSON(http.StatusOK, gin.H{"err": err.Error()}) return domain.Recipe{} } ctx.JSON(http.StatusCreated, gin.H{"recipe": recipe}) return recipe }