Controller and service update for saving recipes
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Seasoned.Backend.Services;
|
||||
using Seasoned.Backend.DTOs;
|
||||
using Seasoned.Backend.Data;
|
||||
using Seasoned.Backend.Models;
|
||||
|
||||
namespace Seasoned.Backend.Controllers;
|
||||
|
||||
@@ -9,10 +11,12 @@ namespace Seasoned.Backend.Controllers;
|
||||
public class RecipeController : ControllerBase
|
||||
{
|
||||
private readonly IRecipeService _recipeService;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public RecipeController(IRecipeService recipeService)
|
||||
public RecipeController(IRecipeService recipeService, ApplicationDbContext context)
|
||||
{
|
||||
_recipeService = recipeService;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpPost("upload")]
|
||||
@@ -27,14 +31,28 @@ public class RecipeController : ControllerBase
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetRecipes()
|
||||
[HttpPost("save")]
|
||||
public async Task<IActionResult> SaveRecipe([FromBody] RecipeResponseDto recipeDto)
|
||||
{
|
||||
// This assumes your DbContext is injected as _context
|
||||
var recipes = await _context.Recipes
|
||||
.OrderByDescending(r => r.CreatedAt)
|
||||
.ToListAsync();
|
||||
if (recipeDto == null)
|
||||
{
|
||||
return BadRequest("Invalid recipe data.");
|
||||
}
|
||||
|
||||
return Ok(recipes);
|
||||
var recipe = new Recipe
|
||||
{
|
||||
Title = recipeDto.Title,
|
||||
Description = recipeDto.Description,
|
||||
Ingredients = recipeDto.Ingredients,
|
||||
Instructions = recipeDto.Instructions,
|
||||
CreatedAt = DateTime.UtcNow
|
||||
};
|
||||
|
||||
_context.Recipes.Add(recipe);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Ok(new { message = "Recipe saved!" });
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class RecipeService : IRecipeService
|
||||
public async Task<RecipeResponseDto> ParseRecipeImageAsync(IFormFile image)
|
||||
{
|
||||
var googleAI = new GoogleAI(_apiKey);
|
||||
var model = googleAI.GenerativeModel("gemini-2.5-flash");
|
||||
var model = googleAI.GenerativeModel("gemini-3.1-flash-lite-preview");
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
await image.CopyToAsync(ms);
|
||||
|
||||
Reference in New Issue
Block a user