refactor: rename namespace to FiscalFlow and upgrade to .NET 10
- Rename InvoiceMaster.* to FiscalFlow.* namespace - Upgrade from .NET 8 to .NET 10 - Update all NuGet packages to latest versions - Update C# language version to 14.0
This commit is contained in:
67
backend/src/FiscalFlow.Api/Controllers/InvoicesController.cs
Normal file
67
backend/src/FiscalFlow.Api/Controllers/InvoicesController.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using FiscalFlow.Application.Commands.Invoices;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace FiscalFlow.API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/v1/invoices")]
|
||||
[Authorize]
|
||||
public class InvoicesController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public InvoicesController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Consumes("multipart/form-data")]
|
||||
public async Task<IActionResult> UploadInvoice([FromForm] UploadInvoiceRequest request)
|
||||
{
|
||||
var userId = GetUserId();
|
||||
|
||||
if (request.File == null || request.File.Length == 0)
|
||||
{
|
||||
return BadRequest(new { success = false, error = "No file uploaded" });
|
||||
}
|
||||
|
||||
if (!request.File.ContentType.Equals("application/pdf", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return BadRequest(new { success = false, error = "Only PDF files are supported" });
|
||||
}
|
||||
|
||||
var command = new UploadInvoiceCommand(
|
||||
userId,
|
||||
request.Provider,
|
||||
request.File.FileName,
|
||||
request.File.OpenReadStream(),
|
||||
request.File.Length,
|
||||
request.File.ContentType);
|
||||
|
||||
var result = await _mediator.Send(command);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
return BadRequest(new { success = false, error = result.ErrorMessage });
|
||||
}
|
||||
|
||||
return Ok(new { success = true, data = result.Invoice });
|
||||
}
|
||||
|
||||
private Guid GetUserId()
|
||||
{
|
||||
var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
return Guid.Parse(userId!);
|
||||
}
|
||||
}
|
||||
|
||||
public class UploadInvoiceRequest
|
||||
{
|
||||
public IFormFile? File { get; set; }
|
||||
public string Provider { get; set; } = "fortnox";
|
||||
public bool AutoProcess { get; set; } = false;
|
||||
}
|
||||
Reference in New Issue
Block a user