32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
using Distribution.Infra.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Distribution.Features.Grn;
|
|
|
|
[ApiController]
|
|
public class GrnController(GrnService service, ICurrentUserService currentUser) : ControllerBase
|
|
{
|
|
[HttpGet("api/goods-receipts/{id:guid}")]
|
|
public async Task<IActionResult> GetById(Guid id)
|
|
{
|
|
var result = await service.GetByIdAsync(id);
|
|
return result is null ? NotFound() : Ok(result);
|
|
}
|
|
|
|
[HttpGet("api/purchase-orders/{id:guid}/goods-receipts")]
|
|
public async Task<IActionResult> GetByPurchaseOrder(Guid id) =>
|
|
Ok(await service.GetByPurchaseOrderIdAsync(id));
|
|
|
|
[HttpPost("api/purchase-orders/{id:guid}/goods-receipts")]
|
|
public async Task<IActionResult> Create(Guid id, CreateGrnRequest request, CancellationToken ct)
|
|
{
|
|
var userId = currentUser.UserId ?? throw new UnauthorizedAccessException();
|
|
try
|
|
{
|
|
var result = await service.CreateAsync(id, request, userId, ct);
|
|
return CreatedAtAction(nameof(GetById), new { id = result.Id }, result);
|
|
}
|
|
catch (InvalidOperationException ex) { return Conflict(new { error = ex.Message }); }
|
|
}
|
|
}
|