Class GoalController
java.lang.Object
org.ntnu.idi.idatt2106.sparesti.sparestibackend.controller.GoalController
Handles all requests directed to goal endpoints. All the endpoints
under the currently authenticated user, meaning they are private.
This prevents other users from accessing/modifying data of each other.
- Since:
- 22.4.24
- Version:
- 1.0
- Author:
- Harry L.X
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity
<GoalResponseDTO> completeUserGoal
(Long id, org.springframework.security.core.userdetails.UserDetails userDetails) Completes a user's saving goalorg.springframework.http.ResponseEntity
<GoalResponseDTO> createUserGoal
(GoalCreateDTO goalDTO, org.springframework.security.core.userdetails.UserDetails userDetails) Creates a saving goalorg.springframework.http.ResponseEntity
<Void> deleteUserGoal
(Long id, org.springframework.security.core.userdetails.UserDetails userDetails) Deletes a user's saving goalorg.springframework.http.ResponseEntity
<org.springframework.core.io.Resource> Gets the image of a goalorg.springframework.http.ResponseEntity
<List<GoalResponseDTO>> getActiveGoals
(org.springframework.security.core.userdetails.UserDetails userDetails) Gets a list of active user goals.org.springframework.http.ResponseEntity
<org.springframework.data.domain.Page<GoalResponseDTO>> getCompletedGoals
(org.springframework.data.domain.Pageable pageable, org.springframework.security.core.userdetails.UserDetails userDetails) Gets a page of a user's completed saving goalsorg.springframework.http.ResponseEntity
<GoalResponseDTO> getUserGoal
(Long id, org.springframework.security.core.userdetails.UserDetails userDetails) Get specific user's saving goalorg.springframework.http.ResponseEntity
<org.springframework.data.domain.Page<GoalResponseDTO>> getUserGoals
(org.springframework.data.domain.Pageable pageable, org.springframework.security.core.userdetails.UserDetails userDetails) Gets a page of a user's saving goalsorg.springframework.http.ResponseEntity
<String> handleFileUpload
(String id, org.springframework.web.multipart.MultipartFile file, org.springframework.security.core.userdetails.UserDetails userDetails) Uploads an mage of a goalorg.springframework.http.ResponseEntity
<List<GoalResponseDTO>> updatePriorities
(List<Long> goalIds, org.springframework.security.core.userdetails.UserDetails userDetails) Updates goal priority orderorg.springframework.http.ResponseEntity
<GoalResponseDTO> updateUserGoal
(Long id, GoalUpdateDTO goalDTO, org.springframework.security.core.userdetails.UserDetails userDetails) Updates a user's saving goal
-
Constructor Details
-
GoalController
public GoalController()
-
-
Method Details
-
getUserGoals
@GetMapping public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<GoalResponseDTO>> getUserGoals(org.springframework.data.domain.Pageable pageable, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) Gets a page of a user's saving goals- Parameters:
pageable
- Config for page objectuserDetails
- Current user- Returns:
- Page of saving goals
-
getActiveGoals
@GetMapping("/active") public org.springframework.http.ResponseEntity<List<GoalResponseDTO>> getActiveGoals(@AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) Gets a list of active user goals. Max 10 goals can be active at the same time- Parameters:
userDetails
- Current user- Returns:
- List of active goals
-
getCompletedGoals
@GetMapping("/completed") public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<GoalResponseDTO>> getCompletedGoals(org.springframework.data.domain.Pageable pageable, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) Gets a page of a user's completed saving goals- Parameters:
pageable
- Config for page objectuserDetails
- current user- Returns:
- Page of completed saving goals
-
getUserGoal
@GetMapping("/{id}") public org.springframework.http.ResponseEntity<GoalResponseDTO> getUserGoal(@PathVariable Long id, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) Get specific user's saving goal- Parameters:
id
- Identifies saving goaluserDetails
- current user- Returns:
- Specific user goal
-
createUserGoal
@PostMapping public org.springframework.http.ResponseEntity<GoalResponseDTO> createUserGoal(@RequestBody GoalCreateDTO goalDTO, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) throws BadInputException, ActiveGoalLimitExceededException, ObjectNotValidException Creates a saving goal- Parameters:
goalDTO
- Wrapper for saving goal infouserDetails
- current user- Returns:
- Wrapper for new saving goal info
- Throws:
BadInputException
- On bad user inputActiveGoalLimitExceededException
- If active goal limit of 10 is exceeded.ObjectNotValidException
- If goalDTO fields are invalid
-
updateUserGoal
@PutMapping("/{id}") public org.springframework.http.ResponseEntity<GoalResponseDTO> updateUserGoal(@PathVariable Long id, @RequestBody GoalUpdateDTO goalDTO, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) throws BadInputException, ObjectNotValidException Updates a user's saving goal- Parameters:
id
- Identifies saving goalgoalDTO
- Wrapper for updated saving goal infouserDetails
- Current user- Returns:
- Updated saving goal info
- Throws:
BadInputException
- Upon bad user inputObjectNotValidException
- If goalDTO has invalid fields
-
updatePriorities
@PutMapping public org.springframework.http.ResponseEntity<List<GoalResponseDTO>> updatePriorities(@RequestBody List<Long> goalIds, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) Updates goal priority order- Parameters:
goalIds
- List of goal id's ordered by priorityuserDetails
- Current user- Returns:
- New list of updated goals
-
deleteUserGoal
@DeleteMapping("/{id}") public org.springframework.http.ResponseEntity<Void> deleteUserGoal(@PathVariable Long id, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) Deletes a user's saving goal- Parameters:
id
- Identifies saving goaluserDetails
- Current user- Returns:
- NADA
-
completeUserGoal
@PutMapping("/{id}/complete") public org.springframework.http.ResponseEntity<GoalResponseDTO> completeUserGoal(@PathVariable Long id, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) Completes a user's saving goal- Parameters:
id
- Identifies saving goaluserDetails
- Current user- Returns:
- Completed user goal
-
handleFileUpload
@PostMapping("/picture") public org.springframework.http.ResponseEntity<String> handleFileUpload(@RequestParam String id, @RequestParam("file") org.springframework.web.multipart.MultipartFile file, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) throws IOException Uploads an mage of a goal- Parameters:
id
- Identifies goalfile
- File to be uploadeduserDetails
- Current user- Returns:
- Resource wrapper for image
- Throws:
IOException
- For IO-errors
-
findFile
@GetMapping("/picture") @ResponseBody public org.springframework.http.ResponseEntity<org.springframework.core.io.Resource> findFile(@RequestParam String id, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) throws IOException Gets the image of a goal- Parameters:
id
- Identifies goaluserDetails
- Current user- Returns:
- Resource wrapper for image
- Throws:
IOException
- For IO-errors
-