using MediatR; using FnbEngine.Domain.AggregatesModel.RecipeAggregate; namespace FnbEngine.API.Application.Queries; public record GetRecipesByShopQuery(Guid ShopId) : IRequest>; public record RecipeDto(Guid Id, Guid ProductId, Guid ShopId, string Name, string? Instructions, int PrepTimeMinutes, bool IsActive, DateTime CreatedAt, List Ingredients); public record RecipeIngredientDto(Guid Id, string IngredientName, decimal Quantity, string Unit, decimal CostPerUnit); public class GetRecipesByShopQueryHandler : IRequestHandler> { private readonly IRecipeRepository _repo; public GetRecipesByShopQueryHandler(IRecipeRepository repo) => _repo = repo; public async Task> Handle(GetRecipesByShopQuery req, CancellationToken ct) { var recipes = await _repo.GetByShopIdAsync(req.ShopId, ct); return recipes.Select(r => new RecipeDto( r.Id, r.ProductId, r.ShopId, r.Name, r.Instructions, r.PrepTimeMinutes, r.IsActive, r.CreatedAt, r.Ingredients.Select(i => new RecipeIngredientDto(i.Id, i.IngredientName, i.Quantity, i.Unit, i.CostPerUnit)).ToList() )); } }