using Microsoft.AspNetCore.Mvc; using StitcherApi.Models; using StitcherApi.Services; namespace StitcherApi.Controllers; public static class ImageController { public static void MapImageEndpoints(this IEndpointRouteBuilder app) { var group = app.MapGroup("/api/image"); group.MapPost( "/generate", async ( [FromBody] GenerateImageRequest request, [FromServices] IImageService imageService ) => { try { var imageBytes = await imageService.GenerateImageAsync(request); return Results.File(imageBytes, "image/png"); } catch (FileNotFoundException ex) { return Results.Problem( detail: ex.Message, statusCode: StatusCodes.Status404NotFound ); } catch (ArgumentException ex) { return Results.Problem( detail: ex.Message, statusCode: StatusCodes.Status400BadRequest ); } catch (Exception) { // In a real app, log the exception here. return Results.Problem( detail: "An internal error occurred.", statusCode: StatusCodes.Status500InternalServerError ); } } ); } }