Class UserController
java.lang.Object
org.ntnu.idi.idatt2106.sparesti.sparestibackend.controller.UserController
Controller for managing endpoints for a user's profile
- Since:
- 23.4.24
- Version:
- 1.0
- Author:
- Yasin M.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity
<org.springframework.core.io.Resource> findFile
(org.springframework.security.core.userdetails.UserDetails userDetails) Uploads the profile picture of a userorg.springframework.http.ResponseEntity
<StreakResponse> getStreak
(org.springframework.security.core.userdetails.UserDetails userDetails) Gets the streak of a userorg.springframework.http.ResponseEntity
<UserResponse> getUser
(org.springframework.security.core.userdetails.UserDetails userDetails) Gets a users profileorg.springframework.http.ResponseEntity
<String> handleFileUpload
(org.springframework.security.core.userdetails.UserDetails userDetails, org.springframework.web.multipart.MultipartFile file) Gets the profile picture of a userorg.springframework.http.ResponseEntity
<UserResponse> updateUser
(org.springframework.security.core.userdetails.UserDetails userDetails, UserUpdateDTO userUpdateDTO) Updates a user profile
-
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 useruserUpdateDTO
- 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 userfile
- 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
-