Class FridgeController
java.lang.Object
edu.ntnu.idatt2106_2023_06.backend.controller.FridgeController
@RestController
@CrossOrigin("*")
@RequestMapping("/fridge")
public class FridgeController
extends Object
The FridgeController class provides API endpoints for managing fridge users.
It uses the FridgeService to handle the logic of adding and deleting
fridge users.
- Author:
- Trym Hamer Gudvangen
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Object>
addUserToFridge
(FridgeUserDTO fridgeUserDTO, org.springframework.security.core.Authentication authentication) This endpoint serves to add a User to a fridge.org.springframework.http.ResponseEntity<Object>
createFridge
(String fridgeName, org.springframework.security.core.Authentication authentication) This endpoint allows an authenticated user to create a new fridge.org.springframework.http.ResponseEntity<Object>
deleteUserFromFridge
(FridgeUserDTO fridgeUserDTO, org.springframework.security.core.Authentication authentication) This endpoint serves to remove a User from a fridge.loadFridgeIdsByUser
(String username) This endpoint retrieves all the fridge ids for a given user.org.springframework.http.ResponseEntity<FridgeLoadAllDTO>
loadFridgesByUser
(String username) This endpoint retrieves all the fridges for a given user.org.springframework.http.ResponseEntity<FridgeMemberLoadAllDTO>
loadUsersByFridgeId
(Long fridgeId, org.springframework.security.core.Authentication authentication) This endpoint retrieves all the users for a given fridge id.org.springframework.http.ResponseEntity<Object>
updateFridgeName
(FridgeDTO fridgeDTO, org.springframework.security.core.Authentication authentication) This endpoint serves to update the fridge name.org.springframework.http.ResponseEntity<Object>
updateUserFromFridge
(FridgeUserDTO fridgeUserDTO, org.springframework.security.core.Authentication authentication) This endpoint serves to update a User from a fridge.
-
Constructor Details
-
FridgeController
public FridgeController()
-
-
Method Details
-
addUserToFridge
@PostMapping("/add/user") public org.springframework.http.ResponseEntity<Object> addUserToFridge(@RequestBody FridgeUserDTO fridgeUserDTO, org.springframework.security.core.Authentication authentication) This endpoint serves to add a User to a fridge.- Parameters:
fridgeUserDTO
- The FridgeUserDTO containing the details of the user to be added to the fridge.authentication
- The Authentication object of the user making the request.- Returns:
- A ResponseEntity indicating whether the operation was successful.
-
deleteUserFromFridge
@DeleteMapping("/delete/user") public org.springframework.http.ResponseEntity<Object> deleteUserFromFridge(@RequestBody FridgeUserDTO fridgeUserDTO, org.springframework.security.core.Authentication authentication) This endpoint serves to remove a User from a fridge.- Parameters:
fridgeUserDTO
- The FridgeUserDTO containing the details of the user to be deleted from the fridge.authentication
- The Authentication object of the user making the request.- Returns:
- A ResponseEntity indicating whether the operation was successful.
-
updateUserFromFridge
@PutMapping("/update/user") public org.springframework.http.ResponseEntity<Object> updateUserFromFridge(@RequestBody FridgeUserDTO fridgeUserDTO, org.springframework.security.core.Authentication authentication) This endpoint serves to update a User from a fridge.- Parameters:
fridgeUserDTO
- The FridgeUserDTO containing the details of the user to be updated from the fridge.authentication
- The Authentication object of the user making the request.- Returns:
- A ResponseEntity indicating whether the operation was successful.
-
loadFridgeIdsByUser
@GetMapping("/loadAllId") public org.springframework.http.ResponseEntity<List<Long>> loadFridgeIdsByUser(@RequestParam(name="user") String username) This endpoint retrieves all the fridge ids for a given user.- Parameters:
username
- The username of the user, given as a String.- Returns:
- Response entity containing the fridge ids.
-
loadFridgesByUser
@GetMapping("/loadAll") public org.springframework.http.ResponseEntity<FridgeLoadAllDTO> loadFridgesByUser(@RequestParam(name="user") String username) This endpoint retrieves all the fridges for a given user.- Parameters:
username
- The username of the user, given as a String.- Returns:
- Response entity containing a FridgeDTO.
-
createFridge
@PostMapping("/create") public org.springframework.http.ResponseEntity<Object> createFridge(@RequestParam(name="fridgeName") String fridgeName, org.springframework.security.core.Authentication authentication) This endpoint allows an authenticated user to create a new fridge.- Parameters:
fridgeName
- Name of the fridge, given as a String.authentication
- The authentication of the HTTP Request sender, given as an Authentication object.- Returns:
- Response entity containing the HTTP status.
-
updateFridgeName
@PutMapping("/update") public org.springframework.http.ResponseEntity<Object> updateFridgeName(@RequestBody FridgeDTO fridgeDTO, org.springframework.security.core.Authentication authentication) This endpoint serves to update the fridge name.- Parameters:
fridgeDTO
- New name of the fridge, given as String.authentication
- The Authentication object of the user making the request.- Returns:
- A ResponseEntity indicating whether the operation was successful.
-
loadUsersByFridgeId
@GetMapping("/loadAllUsers") public org.springframework.http.ResponseEntity<FridgeMemberLoadAllDTO> loadUsersByFridgeId(@RequestParam(name="fridgeId") Long fridgeId, org.springframework.security.core.Authentication authentication) This endpoint retrieves all the users for a given fridge id.- Parameters:
fridgeId
- The id of the fridge to be checked, given as a Long- Returns:
- Response entity containing the users, given as a UserLoadAllDTO
-