Spaces:
Sleeping
Sleeping
Download LibraryManagement.Backend/Features/Books/BookController.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/Books/BookController.cs
- Command line
-
hf download hf://spaces/Yuruyuruu/LibraryManagement@93d516ebdfdf29b5f35ac2ae1405fa1876462cdc/LibraryManagement.Backend/Features/Books/BookController.cs
-
curl -L -o BookController.cs https://huggingface.co/spaces/Yuruyuruu/LibraryManagement/resolve/93d516ebdfdf29b5f35ac2ae1405fa1876462cdc/LibraryManagement.Backend/Features/Books/BookController.cs
2.08 kB
| using Microsoft.AspNetCore.Authorization; | |
| using Microsoft.AspNetCore.Mvc; | |
| namespace LibraryManagement.Backend.Features.Books | |
| { | |
| [] | |
| [] | |
| public class BookController : ControllerBase | |
| { | |
| private readonly IBookService _bookService; | |
| public BookController(IBookService bookService) | |
| { | |
| _bookService = bookService; | |
| } | |
| [] | |
| //[Authorize] | |
| public async Task<ActionResult<IEnumerable<BookDto>>> GetBooks() | |
| { | |
| var books = await _bookService.GetAllBooksAsync(); | |
| return Ok(books); | |
| } | |
| [] | |
| //[Authorize] | |
| public async Task<ActionResult<BookDto>> GetBook(int id) | |
| { | |
| var book = await _bookService.GetBookByIdAsync(id); | |
| if (book == null) return NotFound(); | |
| return Ok(book); | |
| } | |
| [] | |
| //[Authorize(Roles = "Librarian")] | |
| public async Task<ActionResult<BookDto>> CreateBook([FromBody] BookCreateRequest request) | |
| { | |
| try | |
| { | |
| var book = await _bookService.CreateBookAsync(request); | |
| return CreatedAtAction(nameof(GetBook), new { id = book.Id }, book); | |
| } | |
| catch (Exception ex) | |
| { | |
| return BadRequest(new { message = ex.Message }); | |
| } | |
| } | |
| [] | |
| //[Authorize(Roles = "Librarian")] | |
| public async Task<ActionResult<BookDto>> UpdateBook(int id, [FromBody] BookUpdateRequest request) | |
| { | |
| var updatedBook = await _bookService.UpdateBookAsync(id, request); | |
| if (updatedBook == null) return NotFound(); | |
| return Ok(updatedBook); | |
| } | |
| [] | |
| //[Authorize(Roles = "Librarian")] | |
| public async Task<IActionResult> DeleteBook(int id) | |
| { | |
| var success = await _bookService.DeleteBookAsync(id); | |
| if (!success) return NotFound(); | |
| return NoContent(); | |
| } | |
| } | |
| } | |