79.2 Update Profile Image of User (#9)

This commit is contained in:
Art
2021-09-10 14:02:40 +03:00
parent b91f60ef51
commit f64d9f7246
3 changed files with 105 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.util.List;
@ -92,7 +93,7 @@ public class UserResource {
}
@DeleteMapping("{id}")
public HttpResponse deleteUser(@PathVariable long id){
public HttpResponse deleteUser(@PathVariable long id) {
userService.deleteUser(id);
return HttpResponse.builder()
.httpStatusCode(OK.value())
@ -102,6 +103,11 @@ public class UserResource {
.build();
}
@PutMapping("{username}/profileImage")
public User updateUser(@PathVariable String username, MultipartFile profileImage) {
return userService.updateProfileImage(username, profileImage);
}
private void authenticate(String username, String password) {
Authentication auth = new UsernamePasswordAuthenticationToken(username, password);
authenticationManager.authenticate(auth);