Class BorrowingController

java.lang.Object
com.example.restapi.controller.BorrowingController

@RestController @RequestMapping("/api/borrows") public class BorrowingController extends Object
  • Field Details

    • borrowingService

      @Autowired private BorrowingService borrowingService
      Service handling borrowing logic.
    • userService

      @Autowired private UserService userService
      Service handling user management logic.
  • Constructor Details

    • BorrowingController

      public BorrowingController()
  • Method Details

    • borrowBook

      @PostMapping("/{bookId}/borrows") public org.springframework.http.ResponseEntity<String> borrowBook(@PathVariable Long bookId, @RequestBody User user)
      Endpoint for borrowing a book by a specific user.
      Parameters:
      bookId - the ID of the book to borrow
      user - the User attempting to borrow the book
      Returns:
      a ResponseEntity with a success or failure message
    • returnBook

      @PostMapping("/{bookId}/returns") public org.springframework.http.ResponseEntity<String> returnBook(@PathVariable Long bookId)
      Endpoint for returning a borrowed book.
      Parameters:
      bookId - the ID of the book to return
      Returns:
      a ResponseEntity with a success or failure message
    • getBorrowedBooksByUser

      @GetMapping("/users/{username}/borrowed-books") public org.springframework.http.ResponseEntity<List<Map<String,Object>>> getBorrowedBooksByUser(@PathVariable String username)
      Endpoint for retrieving the list of books borrowed by a specific user.
      Parameters:
      username - the username of the user
      Returns:
      a ResponseEntity containing a list of borrowed books represented as maps of book attributes
    • deleteBorrowing

      @DeleteMapping("/{id}") public org.springframework.http.ResponseEntity<Void> deleteBorrowing(@PathVariable Long bookId, @PathVariable Long userId)
      Endpoint for deleting a borrowing record based on book and user IDs.
      Parameters:
      bookId - the ID of the book
      userId - the ID of the user
      Returns:
      a ResponseEntity with no content if successful