new flashcards
All checks were successful
Mindforge API Build and Deploy / Build Mindforge API Image (push) Successful in 4m4s
Mindforge Web Build and Deploy (internal) / Build Mindforge Web Image (push) Successful in 5m29s
Mindforge Web Build and Deploy (internal) / Deploy Mindforge Web (internal) (push) Successful in 9s
Mindforge API Build and Deploy / Deploy Mindforge API (internal) (push) Successful in 8s
All checks were successful
Mindforge API Build and Deploy / Build Mindforge API Image (push) Successful in 4m4s
Mindforge Web Build and Deploy (internal) / Build Mindforge Web Image (push) Successful in 5m29s
Mindforge Web Build and Deploy (internal) / Deploy Mindforge Web (internal) (push) Successful in 9s
Mindforge API Build and Deploy / Deploy Mindforge API (internal) (push) Successful in 8s
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Mindforge.API.Exceptions;
|
||||
using Mindforge.API.Models.Requests;
|
||||
@@ -21,23 +19,41 @@ namespace Mindforge.API.Controllers
|
||||
[HttpPost("generate")]
|
||||
public async Task<IActionResult> Generate([FromBody] FlashcardGenerateRequest request)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.FileContent) || request.Amount <= 0)
|
||||
request ??= new FlashcardGenerateRequest();
|
||||
if (request.FilePaths is null || request.FilePaths.Count == 0)
|
||||
{
|
||||
throw new UserException("FileContent is required and Amount must be greater than 0.");
|
||||
throw new UserException("Selecione ao menos um arquivo para gerar flashcards.");
|
||||
}
|
||||
|
||||
try
|
||||
var libraries = await _flashcardService.GenerateFlashcardsAsync(request);
|
||||
return Ok(new { libraries });
|
||||
}
|
||||
|
||||
[HttpGet("libraries")]
|
||||
public async Task<IActionResult> GetLibraries()
|
||||
{
|
||||
var libraries = await _flashcardService.GetLibrariesAsync();
|
||||
return Ok(libraries);
|
||||
}
|
||||
|
||||
[HttpGet("libraries/{id:long}")]
|
||||
public async Task<IActionResult> GetLibraryById([FromRoute] long id)
|
||||
{
|
||||
var library = await _flashcardService.GetLibraryByIdAsync(id);
|
||||
if (library is null)
|
||||
{
|
||||
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.");
|
||||
return NotFound(new { error = "Biblioteca de flashcards nao encontrada." });
|
||||
}
|
||||
|
||||
var response = await _flashcardService.GenerateFlashcardsAsync(request);
|
||||
return Ok(new { result = response });
|
||||
return Ok(library);
|
||||
}
|
||||
|
||||
[HttpPost("review-session")]
|
||||
public async Task<IActionResult> BuildReviewSession([FromBody] FlashcardReviewSessionRequest request)
|
||||
{
|
||||
request ??= new FlashcardReviewSessionRequest();
|
||||
var cards = await _flashcardService.BuildReviewSessionAsync(request);
|
||||
return Ok(new { cards });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user