All checks were successful
Mindforge API Build and Deploy / Build Mindforge API Image (push) Successful in 1m8s
Mindforge Cronjob Build and Deploy / Build Mindforge Cronjob Image (push) Successful in 1m19s
Mindforge API Build and Deploy / Deploy Mindforge API (internal) (push) Successful in 11s
Mindforge Cronjob Build and Deploy / Deploy Mindforge Cronjob (internal) (push) Successful in 10s
Mindforge Web Build and Deploy (internal) / Build Mindforge Web Image (push) Successful in 2m25s
Mindforge Web Build and Deploy (internal) / Deploy Mindforge Web (internal) (push) Successful in 12s
44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Mindforge.API.Exceptions;
|
|
using Mindforge.API.Models.Requests;
|
|
using Mindforge.API.Services.Interfaces;
|
|
|
|
namespace Mindforge.API.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/v1/flashcard")]
|
|
public class FlashcardController : ControllerBase
|
|
{
|
|
private readonly IFlashcardService _flashcardService;
|
|
|
|
public FlashcardController(IFlashcardService flashcardService)
|
|
{
|
|
_flashcardService = flashcardService;
|
|
}
|
|
|
|
[HttpPost("generate")]
|
|
public async Task<IActionResult> Generate([FromBody] FlashcardGenerateRequest request)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.FileContent) || request.Amount <= 0)
|
|
{
|
|
throw new UserException("FileContent is required and Amount must be greater than 0.");
|
|
}
|
|
|
|
try
|
|
{
|
|
var base64Bytes = Convert.FromBase64String(request.FileContent);
|
|
request.FileContent = System.Text.Encoding.UTF8.GetString(base64Bytes);
|
|
}
|
|
catch (FormatException)
|
|
{
|
|
throw new UserException("FileContent must be a valid base64 string.");
|
|
}
|
|
|
|
var response = await _flashcardService.GenerateFlashcardsAsync(request);
|
|
return Ok(new { result = response });
|
|
}
|
|
}
|
|
}
|