* Added recalculation
This commit is contained in:
@@ -13,13 +13,16 @@ public class RecipeManagementController : ControllerBase
|
||||
{
|
||||
private readonly IRecipeManagementService _managementService;
|
||||
private readonly IRecipeExcelService _excelService;
|
||||
private readonly IRecipeCalorieRecalculationService _calorieRecalculation;
|
||||
|
||||
public RecipeManagementController(
|
||||
IRecipeManagementService managementService,
|
||||
IRecipeExcelService excelService)
|
||||
IRecipeExcelService excelService,
|
||||
IRecipeCalorieRecalculationService calorieRecalculation)
|
||||
{
|
||||
_managementService = managementService;
|
||||
_excelService = excelService;
|
||||
_calorieRecalculation = calorieRecalculation;
|
||||
}
|
||||
|
||||
/// <summary>Creates a new recipe with ingredients and steps.</summary>
|
||||
@@ -90,4 +93,26 @@ public class RecipeManagementController : ControllerBase
|
||||
var result = await _managementService.RecalculateAllMacrosFromCatalogAsync(ct);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>Scales or AI-adjusts ingredient amounts to match a calorie target.</summary>
|
||||
[HttpPost("{id:int}/recalculate-calories")]
|
||||
[ProducesResponseType(typeof(RecalculateRecipeCaloriesResultDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> RecalculateCalories(
|
||||
int id,
|
||||
[FromBody] RecalculateRecipeCaloriesRequestDto request,
|
||||
CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _calorieRecalculation.RecalculateAsync(id, request, ct);
|
||||
return result is null
|
||||
? NotFound(new { error = $"Recipe {id} was not found." })
|
||||
: Ok(result);
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
return BadRequest(new { error = ex.Message });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ builder.Services.AddScoped<ITokenService, TokenService>();
|
||||
builder.Services.AddScoped<IAuthService, AuthService>();
|
||||
builder.Services.AddScoped<IRecipeService, RecipeService>();
|
||||
builder.Services.AddScoped<IRecipeManagementService, RecipeManagementService>();
|
||||
builder.Services.AddScoped<IRecipeCalorieRecalculationService, RecipeCalorieRecalculationService>();
|
||||
builder.Services.AddScoped<IRecipeExcelService, RecipeExcelService>();
|
||||
builder.Services.AddScoped<IDietTrackingService, DietTrackingService>();
|
||||
builder.Services.AddScoped<IIngredientCatalogService, IngredientCatalogService>();
|
||||
|
||||
Reference in New Issue
Block a user