This commit is contained in:
2025-10-01 23:59:31 +03:00
parent 2a29571dbf
commit b6c4b9b6bb
28 changed files with 689 additions and 383 deletions

View File

@@ -11,19 +11,25 @@ namespace LctMonolith.Controllers;
public class InventoryController : ControllerBase
{
private readonly IInventoryService _inventoryService;
public InventoryController(IInventoryService inventoryService) => _inventoryService = inventoryService;
private Guid CurrentUserId() => Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
public InventoryController(IInventoryService inventoryService)
{
_inventoryService = inventoryService;
}
private Guid CurrentUserId()
{
return Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
}
/// <summary>Get inventory for current authenticated user.</summary>
[HttpGet]
public async Task<IActionResult> GetMine(CancellationToken ct)
{
var items = await _inventoryService.GetStoreInventoryAsync(CurrentUserId(), ct);
return Ok(items.Select(i => new { i.StoreItemId, i.Quantity, i.AcquiredAt }));
var shaped = items.Select(i => new { i.StoreItemId, i.Quantity, i.AcquiredAt });
return Ok(shaped);
}
/// <summary>Admin: get inventory for specific user.</summary>
[HttpGet("user/{userId:guid}")]
[Authorize(Roles = "Admin")]
public async Task<IActionResult> GetByUser(Guid userId, CancellationToken ct)