Spaces:
Sleeping
Sleeping
Download Backend/Features/Wishlist/WishlistController.cs from Yuruyuruu/LibraryManagement: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/Yuruyuruu/LibraryManagement/resolve/main/Backend/Features/Wishlist/WishlistController.cs
- Command line
-
hf download hf://spaces/Yuruyuruu/LibraryManagement/Backend/Features/Wishlist/WishlistController.cs
-
curl -L -o WishlistController.cs https://huggingface.co/spaces/Yuruyuruu/LibraryManagement/resolve/main/Backend/Features/Wishlist/WishlistController.cs
1.56 kB
| using LibraryManagement.Shared.Models; | |
| using Microsoft.AspNetCore.Authorization; | |
| using Microsoft.AspNetCore.Mvc; | |
| using System.Security.Claims; | |
| namespace Backend.Features.Wishlist | |
| { | |
| [] | |
| [] | |
| [] | |
| public class WishlistController : ControllerBase | |
| { | |
| private readonly IWishlistService _wishlistService; | |
| public WishlistController(IWishlistService wishlistService) | |
| { | |
| _wishlistService = wishlistService; | |
| } | |
| [] | |
| public async Task<IActionResult> SyncWishlist([FromBody] List<int> bookIds) | |
| { | |
| var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier); | |
| if (string.IsNullOrEmpty(userIdStr) || !Guid.TryParse(userIdStr, out Guid userId)) | |
| { | |
| return Unauthorized(); | |
| } | |
| var success = await _wishlistService.SyncWishlistAsync(userId, bookIds); | |
| if (!success) return BadRequest("Failed to sync wishlist"); | |
| return Ok(new { message = "Wishlist synced successfully" }); | |
| } | |
| [] | |
| public async Task<IActionResult> GetWishlist() | |
| { | |
| var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier); | |
| if (string.IsNullOrEmpty(userIdStr) || !Guid.TryParse(userIdStr, out Guid userId)) | |
| { | |
| return Unauthorized(); | |
| } | |
| var bookIds = await _wishlistService.GetWishlistBookIdsAsync(userId); | |
| return Ok(bookIds); | |
| } | |
| } | |
| } | |