StudentLoanManagement
com.student_loan.controller.ItemController Class Reference

Public Member Functions

 ItemController (ItemService itemService, UserService userService, LoanService loanService)
 
ResponseEntity< List< Item > > getAllItems ()
 
ResponseEntity< List< Item > > getAvailableItems ()
 
ResponseEntity< List< Item > > getItemsByUser (@PathVariable Long id)
 
ResponseEntity< Item > getItemById (@PathVariable Long id)
 
ResponseEntity< List< Item > > getLentItemsByUser ()
 
ResponseEntity< List< Item > > getBorrowedItemsByUser ()
 
ResponseEntity< String > createItem (@RequestBody ItemRecord itemRecord)
 
ResponseEntity< String > createItem (@RequestBody ItemRecord itemRecord, @RequestParam("token") String token)
 
ResponseEntity< String > deleteItem (@PathVariable Long id, @RequestParam("token") String token)
 
ResponseEntity< String > updateItem (@PathVariable Long id, @RequestBody ItemRecord item, @RequestParam("token") String token)
 

Detailed Description

Controller class for managing items in the system. Handles HTTP requests related to item operations such as creating, updating, deleting, and retrieving items.

Definition at line 32 of file ItemController.java.

Constructor & Destructor Documentation

◆ ItemController()

com.student_loan.controller.ItemController.ItemController ( ItemService  itemService,
UserService  userService,
LoanService  loanService 
)

Constructor for ItemController.

Parameters
itemServiceService for item operations.
userServiceService for user operations.
loanServiceService for loan operations.

Definition at line 51 of file ItemController.java.

Member Function Documentation

◆ createItem() [1/2]

ResponseEntity< String > com.student_loan.controller.ItemController.createItem ( @RequestBody ItemRecord  itemRecord)

Creates a new item.

Parameters
itemRecordThe item data.
Returns
ResponseEntity indicating the result of the operation.

Definition at line 244 of file ItemController.java.

◆ createItem() [2/2]

ResponseEntity< String > com.student_loan.controller.ItemController.createItem ( @RequestBody ItemRecord  itemRecord,
@RequestParam("token") String  token 
)

Creates a new item using a token for authentication.

Parameters
itemRecordThe item data.
tokenThe authentication token.
Returns
ResponseEntity indicating the result of the operation.

Definition at line 278 of file ItemController.java.

◆ deleteItem()

ResponseEntity< String > com.student_loan.controller.ItemController.deleteItem ( @PathVariable Long  id,
@RequestParam("token") String  token 
)

Deletes an item by its ID.

Parameters
idThe ID of the item.
tokenThe authentication token.
Returns
ResponseEntity indicating the result of the operation.

Definition at line 303 of file ItemController.java.

◆ getAllItems()

ResponseEntity< List< Item > > com.student_loan.controller.ItemController.getAllItems ( )

Retrieves all items in the system.

Returns
List of all items.

Definition at line 74 of file ItemController.java.

◆ getAvailableItems()

ResponseEntity< List< Item > > com.student_loan.controller.ItemController.getAvailableItems ( )

Retrieves all available items in the system.

Returns
ResponseEntity containing a list of available items.

Definition at line 96 of file ItemController.java.

◆ getBorrowedItemsByUser()

ResponseEntity< List< Item > > com.student_loan.controller.ItemController.getBorrowedItemsByUser ( )

Retrieves all items borrowed by the authenticated user.

Returns
ResponseEntity containing a list of borrowed items.

Definition at line 214 of file ItemController.java.

◆ getItemById()

ResponseEntity< Item > com.student_loan.controller.ItemController.getItemById ( @PathVariable Long  id)

Retrieves all available items in the system using a token for authentication.

Parameters
tokenThe authentication token.
Returns
ResponseEntity containing a list of available items.

@GetMapping("/available") public ResponseEntity<List<Item>> getAvailableItems(@RequestParam("token") String token) { User user = userService.getUserByToken(token); if (user == null) { return new ResponseEntity<>(new ArrayList<>(),HttpStatus.UNAUTHORIZED); } List<Item> items = itemService.getItemsByAvailability(Item.ItemStatus.AVAILABLE); return new ResponseEntity<>(items, HttpStatus.OK); } Retrieves an item by its ID.

Parameters
idThe ID of the item.
Returns
ResponseEntity containing the item.

Definition at line 159 of file ItemController.java.

◆ getItemsByUser()

ResponseEntity< List< Item > > com.student_loan.controller.ItemController.getItemsByUser ( @PathVariable Long  id)

Retrieves all items owned by a specific user.

Parameters
idThe ID of the user.
Returns
ResponseEntity containing a list of items owned by the user.

Definition at line 116 of file ItemController.java.

◆ getLentItemsByUser()

ResponseEntity< List< Item > > com.student_loan.controller.ItemController.getLentItemsByUser ( )

Retrieves all items lent by the authenticated user.

Returns
ResponseEntity containing a list of lent items.

Definition at line 185 of file ItemController.java.

◆ updateItem()

ResponseEntity< String > com.student_loan.controller.ItemController.updateItem ( @PathVariable Long  id,
@RequestBody ItemRecord  item,
@RequestParam("token") String  token 
)

Updates an item by its ID.

Parameters
idThe ID of the item.
itemThe updated item data.
tokenThe authentication token.
Returns
ResponseEntity indicating the result of the operation.

Definition at line 323 of file ItemController.java.


The documentation for this class was generated from the following file: