* Added recalculation

This commit is contained in:
2026-06-24 22:56:40 +02:00
parent 7b8dd3ff40
commit beb08f2e6f
14 changed files with 509 additions and 90 deletions

View File

@@ -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 });
}
}
}