Spaces:
Sleeping
Sleeping
Download Backend/Features/Loyalty/LoyaltyAccountsController.cs from Yuruyuruu/LibraryManagement: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/Yuruyuruu/LibraryManagement/resolve/main/Backend/Features/Loyalty/LoyaltyAccountsController.cs
- Command line
-
hf download hf://spaces/Yuruyuruu/LibraryManagement/Backend/Features/Loyalty/LoyaltyAccountsController.cs
-
curl -L -o LoyaltyAccountsController.cs https://huggingface.co/spaces/Yuruyuruu/LibraryManagement/resolve/main/Backend/Features/Loyalty/LoyaltyAccountsController.cs
1.36 kB
| using System.Security.Claims; | |
| using Microsoft.AspNetCore.Authorization; | |
| using Microsoft.AspNetCore.Mvc; | |
| namespace Backend.Features.Loyalty | |
| { | |
| [] | |
| [] | |
| [] | |
| public class LoyaltyAccountsController : ControllerBase | |
| { | |
| private readonly ILoyaltyService _loyaltyService; | |
| public LoyaltyAccountsController(ILoyaltyService loyaltyService) | |
| { | |
| _loyaltyService = loyaltyService; | |
| } | |
| [] | |
| public async Task<IActionResult> GetAccountHistory(string accountId) | |
| { | |
| // Librarians may view any account history; members may only view their own. | |
| if (!User.IsInRole("Librarian")) | |
| { | |
| var userIdStr = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; | |
| if (string.IsNullOrEmpty(userIdStr)) return Unauthorized(); | |
| var myAccount = await _loyaltyService.GetUserAccountAsync(userIdStr); | |
| if (myAccount == null) return NotFound("Loyalty account not found."); | |
| if (!string.Equals(myAccount.Id, accountId, StringComparison.OrdinalIgnoreCase)) | |
| return Forbid(); | |
| } | |
| var history = await _loyaltyService.GetPointsHistoryAsync(accountId); | |
| return Ok(history); | |
| } | |
| } | |
| } | |