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

@RestController @CrossOrigin @RequestMapping("/profile") public class UserController extends Object
Controller for managing endpoints for a user's profile
Since:
23.4.24
Version:
1.0
Author:
Yasin M.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<org.springframework.core.io.Resource>
    findFile(org.springframework.security.core.userdetails.UserDetails userDetails)
    Uploads the profile picture of a user
    org.springframework.http.ResponseEntity<StreakResponse>
    getStreak(org.springframework.security.core.userdetails.UserDetails userDetails)
    Gets the streak of a user
    org.springframework.http.ResponseEntity<UserResponse>
    getUser(org.springframework.security.core.userdetails.UserDetails userDetails)
    Gets a users profile
    org.springframework.http.ResponseEntity<String>
    handleFileUpload(org.springframework.security.core.userdetails.UserDetails userDetails, org.springframework.web.multipart.MultipartFile file)
    Gets the profile picture of a user
    org.springframework.http.ResponseEntity<UserResponse>
    updateUser(org.springframework.security.core.userdetails.UserDetails userDetails, UserUpdateDTO userUpdateDTO)
    Updates a user profile

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UserController

      public UserController()
  • Method Details

    • getUser

      @GetMapping public org.springframework.http.ResponseEntity<UserResponse> getUser(@AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails)
      Gets a users profile
      Parameters:
      userDetails - Current user
      Returns:
      User profile
    • updateUser

      @PutMapping public org.springframework.http.ResponseEntity<UserResponse> updateUser(@AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails, @RequestBody UserUpdateDTO userUpdateDTO)
      Updates a user profile
      Parameters:
      userDetails - Current user
      userUpdateDTO - Wrapper for user's new info
      Returns:
      Updated user profile
    • getStreak

      @GetMapping("/streak") public org.springframework.http.ResponseEntity<StreakResponse> getStreak(@AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) throws UserNotFoundException
      Gets the streak of a user
      Parameters:
      userDetails - Current user
      Returns:
      Wrapper for user's streak info
      Throws:
      UserNotFoundException - If user could not be found
    • handleFileUpload

      @PostMapping("/picture") public org.springframework.http.ResponseEntity<String> handleFileUpload(@AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails, @RequestParam("file") org.springframework.web.multipart.MultipartFile file) throws IOException
      Gets the profile picture of a user
      Parameters:
      userDetails - Current user
      file - Profile picture
      Returns:
      Resource wrapper for image
      Throws:
      IOException - Upon IO-errors
    • findFile

      @GetMapping("/picture") @ResponseBody public org.springframework.http.ResponseEntity<org.springframework.core.io.Resource> findFile(@AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) throws IOException
      Uploads the profile picture of a user
      Parameters:
      userDetails - Current user
      Returns:
      Resource wrapper for image
      Throws:
      IOException - Upon IO-errors