Package com.example.restapi.controller
Class BorrowingController
java.lang.Object
com.example.restapi.controller.BorrowingController
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BorrowingServiceService handling borrowing logic.private UserServiceService handling user management logic. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<String>borrowBook(Long bookId, User user) Endpoint for borrowing a book by a specific user.org.springframework.http.ResponseEntity<Void>deleteBorrowing(Long bookId, Long userId) Endpoint for deleting a borrowing record based on book and user IDs.getBorrowedBooksByUser(String username) Endpoint for retrieving the list of books borrowed by a specific user.org.springframework.http.ResponseEntity<String>returnBook(Long bookId) Endpoint for returning a borrowed book.
-
Field Details
-
borrowingService
Service handling borrowing logic. -
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 borrowuser- theUserattempting to borrow the book- Returns:
- a
ResponseEntitywith 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
ResponseEntitywith 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
ResponseEntitycontaining 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 bookuserId- the ID of the user- Returns:
- a
ResponseEntitywith no content if successful
-