first commit
This commit is contained in:
commit
b344b6a03f
16 changed files with 405 additions and 0 deletions
50
Controllers/ImageController.cs
Normal file
50
Controllers/ImageController.cs
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue