first commit

This commit is contained in:
gelaws-hub 2025-07-31 19:39:06 +07:00
commit b344b6a03f
16 changed files with 405 additions and 0 deletions

View file

@ -0,0 +1,50 @@
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
);
}
}
);
}
}