Spaces:
Sleeping
Sleeping
Download Backend/Features/Users/UserController.cs from Yuruyuruu/LibraryManagement: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/spaces/Yuruyuruu/LibraryManagement/resolve/da200f8e5e321f9c064b73fa2ecb41ec2b950ff1/Backend/Features/Users/UserController.cs
- Command line
-
hf download hf://spaces/Yuruyuruu/LibraryManagement@da200f8e5e321f9c064b73fa2ecb41ec2b950ff1/Backend/Features/Users/UserController.cs
-
curl -L -o UserController.cs https://huggingface.co/spaces/Yuruyuruu/LibraryManagement/resolve/da200f8e5e321f9c064b73fa2ecb41ec2b950ff1/Backend/Features/Users/UserController.cs
2.46 kB
| using Microsoft.AspNetCore.Authorization; | |
| using Microsoft.AspNetCore.Mvc; | |
| namespace Backend.Features.Users | |
| { | |
| [] | |
| [] | |
| public class UserController : ControllerBase | |
| { | |
| private readonly IUserService _userService; | |
| public UserController(IUserService userService) | |
| { | |
| _userService = userService; | |
| } | |
| [] | |
| [] | |
| public async Task<ActionResult<IEnumerable<UserDto>>> GetUsers() | |
| { | |
| var users = await _userService.GetAllUsersAsync(); | |
| return Ok(users); | |
| } | |
| [] | |
| [] | |
| public async Task<ActionResult<UserDto>> GetUser(Guid id) | |
| { | |
| var user = await _userService.GetUserByIdAsync(id); | |
| if (user == null) return NotFound(); | |
| return Ok(user); | |
| } | |
| [] | |
| [] | |
| public async Task<ActionResult<UserDto>> CreateUser([FromBody] UserCreateRequest request) | |
| { | |
| try | |
| { | |
| var response = await _userService.CreateUserAsync(request); | |
| return CreatedAtAction(nameof(GetUser), new { id = response.Id }, response); | |
| } | |
| catch (Exception ex) | |
| { | |
| return BadRequest(new { message = ex.Message }); | |
| } | |
| } | |
| [] | |
| [] | |
| public async Task<ActionResult<UserDto>> UpdateUser(Guid id, [FromBody] UserUpdateRequest request) | |
| { | |
| var updatedUser = await _userService.UpdateUserAsync(id, request); | |
| if (updatedUser == null) return NotFound(); | |
| return Ok(updatedUser); | |
| } | |
| [] | |
| [] | |
| public async Task<IActionResult> UpdateUserRole(Guid id, [FromBody] UserRoleUpdateRequest request) | |
| { | |
| var success = await _userService.UpdateUserRoleAsync(id, request.Role); | |
| if (!success) return NotFound(); | |
| return NoContent(); | |
| } | |
| [] | |
| [] | |
| public async Task<IActionResult> DeleteUser(Guid id) | |
| { | |
| var success = await _userService.DeleteUserAsync(id); | |
| if (!success) return NotFound(); | |
| return NoContent(); | |
| } | |
| } | |
| } | |