Spaces:
Sleeping
Sleeping
Download LibraryManagement.Backend/Features/Subscriptions/SubscriptionController.cs from Yuruyuruu/LibraryManagement: direct link, hf CLI and curl.
- Browser
- Download file 2.08 kB
-
https://huggingface.co/spaces/Yuruyuruu/LibraryManagement/resolve/93d516ebdfdf29b5f35ac2ae1405fa1876462cdc/LibraryManagement.Backend/Features/Subscriptions/SubscriptionController.cs
- Command line
-
hf download hf://spaces/Yuruyuruu/LibraryManagement@93d516ebdfdf29b5f35ac2ae1405fa1876462cdc/LibraryManagement.Backend/Features/Subscriptions/SubscriptionController.cs
-
curl -L -o SubscriptionController.cs https://huggingface.co/spaces/Yuruyuruu/LibraryManagement/resolve/93d516ebdfdf29b5f35ac2ae1405fa1876462cdc/LibraryManagement.Backend/Features/Subscriptions/SubscriptionController.cs
2.08 kB
| using Microsoft.AspNetCore.Authorization; | |
| using Microsoft.AspNetCore.Mvc; | |
| using System.Security.Claims; | |
| namespace LibraryManagement.Backend.Features.Subscriptions | |
| { | |
| [] | |
| [] | |
| public class SubscriptionController : ControllerBase | |
| { | |
| private readonly ISubscriptionService _subscriptionService; | |
| public SubscriptionController(ISubscriptionService subscriptionService) | |
| { | |
| _subscriptionService = subscriptionService; | |
| } | |
| [] | |
| [] | |
| public async Task<ActionResult<IEnumerable<MembershipDto>>> GetMemberships() | |
| { | |
| return Ok(await _subscriptionService.GetMembershipsAsync()); | |
| } | |
| [] | |
| //[Authorize] | |
| public async Task<ActionResult<SubscriptionDto>> GetMySubscription() | |
| { | |
| var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier); | |
| if (string.IsNullOrEmpty(userIdStr)) return Unauthorized(); | |
| var userId = int.Parse(userIdStr); | |
| var subscription = await _subscriptionService.GetUserSubscriptionAsync(userId); | |
| if (subscription == null) return NotFound(new { message = "No active subscription found." }); | |
| return Ok(subscription); | |
| } | |
| [] | |
| //[Authorize] | |
| public async Task<ActionResult<SubscriptionDto>> Subscribe([FromBody] SubscribeRequest request) | |
| { | |
| try | |
| { | |
| var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier); | |
| if (string.IsNullOrEmpty(userIdStr)) return Unauthorized(); | |
| var userId = int.Parse(userIdStr); | |
| var subscription = await _subscriptionService.SubscribeUserAsync(userId, request.MembershipId); | |
| return Ok(subscription); | |
| } | |
| catch (Exception ex) | |
| { | |
| return BadRequest(new { message = ex.Message }); | |
| } | |
| } | |
| } | |
| } | |