java.lang.Object
org.ntnu.idi.idatt2106.sparesti.sparestibackend.controller.GoalController

@RestController @CrossOrigin @RequestMapping("/goals") public class GoalController extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<GoalResponseDTO>
    completeUserGoal(Long id, org.springframework.security.core.userdetails.UserDetails userDetails)
    Completes a user's saving goal
    org.springframework.http.ResponseEntity<GoalResponseDTO>
    createUserGoal(GoalCreateDTO goalDTO, org.springframework.security.core.userdetails.UserDetails userDetails)
    Creates a saving goal
    org.springframework.http.ResponseEntity<Void>
    deleteUserGoal(Long id, org.springframework.security.core.userdetails.UserDetails userDetails)
    Deletes a user's saving goal
    org.springframework.http.ResponseEntity<org.springframework.core.io.Resource>
    findFile(String id, org.springframework.security.core.userdetails.UserDetails userDetails)
    Gets the image of a goal
    org.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 goals
    org.springframework.http.ResponseEntity<GoalResponseDTO>
    getUserGoal(Long id, org.springframework.security.core.userdetails.UserDetails userDetails)
    Get specific user's saving goal
    org.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 goals
    org.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 goal
    org.springframework.http.ResponseEntity<List<GoalResponseDTO>>
    updatePriorities(List<Long> goalIds, org.springframework.security.core.userdetails.UserDetails userDetails)
    Updates goal priority order
    org.springframework.http.ResponseEntity<GoalResponseDTO>
    updateUserGoal(Long id, GoalUpdateDTO goalDTO, org.springframework.security.core.userdetails.UserDetails userDetails)
    Updates a user's saving goal

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 object
      userDetails - 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 object
      userDetails - 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 goal
      userDetails - 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 info
      userDetails - current user
      Returns:
      Wrapper for new saving goal info
      Throws:
      BadInputException - On bad user input
      ActiveGoalLimitExceededException - 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 goal
      goalDTO - Wrapper for updated saving goal info
      userDetails - Current user
      Returns:
      Updated saving goal info
      Throws:
      BadInputException - Upon bad user input
      ObjectNotValidException - 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 priority
      userDetails - 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 goal
      userDetails - 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 goal
      userDetails - 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 goal
      file - File to be uploaded
      userDetails - 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 goal
      userDetails - Current user
      Returns:
      Resource wrapper for image
      Throws:
      IOException - For IO-errors