auth layer implemented
This commit is contained in:
@@ -1,16 +1,31 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Distribution.Infra.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Distribution.Features.PriceList;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/price-lists")]
|
||||
public class PriceListController(PriceListService service) : ControllerBase
|
||||
public class PriceListController(
|
||||
PriceListService service,
|
||||
IScopeAccessService scopeAccess,
|
||||
ICurrentUserService currentUser) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll([FromQuery] Guid? regionId) =>
|
||||
Ok(await service.GetAllAsync(regionId));
|
||||
[Authorize("price-list.view")]
|
||||
public async Task<IActionResult> GetAll([FromQuery] Guid? regionId)
|
||||
{
|
||||
if (regionId.HasValue)
|
||||
{
|
||||
var userId = currentUser.UserId;
|
||||
if (userId.HasValue && !await scopeAccess.HasRegionScopeAsync(userId.Value, regionId.Value))
|
||||
return StatusCode(403);
|
||||
}
|
||||
return Ok(await service.GetAllAsync(regionId));
|
||||
}
|
||||
|
||||
[HttpGet("resolve")]
|
||||
[Authorize("price-list.view")]
|
||||
public async Task<IActionResult> Resolve([FromQuery] Guid itemId, [FromQuery] Guid storeId, [FromQuery] DateTime saleDate)
|
||||
{
|
||||
var result = await service.ResolveByStoreAsync(itemId, storeId, saleDate);
|
||||
@@ -18,6 +33,7 @@ public class PriceListController(PriceListService service) : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("{id:guid}")]
|
||||
[Authorize("price-list.view")]
|
||||
public async Task<IActionResult> GetById(Guid id)
|
||||
{
|
||||
var result = await service.GetByIdAsync(id);
|
||||
@@ -25,6 +41,7 @@ public class PriceListController(PriceListService service) : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize("price-list.manage")]
|
||||
public async Task<IActionResult> Create(CreatePriceListRequest request, CancellationToken ct)
|
||||
{
|
||||
var result = await service.CreateAsync(request, ct);
|
||||
@@ -32,6 +49,7 @@ public class PriceListController(PriceListService service) : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}")]
|
||||
[Authorize("price-list.manage")]
|
||||
public async Task<IActionResult> Update(Guid id, UpdatePriceListRequest request, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
@@ -46,6 +64,7 @@ public class PriceListController(PriceListService service) : ControllerBase
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}")]
|
||||
[Authorize("price-list.manage")]
|
||||
public async Task<IActionResult> Delete(Guid id, CancellationToken ct)
|
||||
{
|
||||
var deleted = await service.DeleteAsync(id, ct);
|
||||
@@ -53,6 +72,7 @@ public class PriceListController(PriceListService service) : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}/items/{sku}")]
|
||||
[Authorize("price-list.manage")]
|
||||
public async Task<IActionResult> UpsertItem(Guid id, string sku, UpsertPriceListItemRequest request, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
@@ -67,6 +87,7 @@ public class PriceListController(PriceListService service) : ControllerBase
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}/items/{sku}")]
|
||||
[Authorize("price-list.manage")]
|
||||
public async Task<IActionResult> RemoveItem(Guid id, string sku, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user