Skip to content

Commit

Permalink
Merge pull request #78 from 9oormDari/develop
Browse files Browse the repository at this point in the history
fix: profile image ์—…๋กœ๋“œ ๊ธฐ๋Šฅ ๊ตฌํ˜„
  • Loading branch information
T-ferret authored Sep 28, 2024
2 parents e9a5644 + 34dfb30 commit d0cf286
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.goormdari.domain.user.domain.exception;

public class DuplicateUsernameException extends RuntimeException {

public DuplicateUsernameException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.springframework.web.multipart.MultipartFile;

@Getter
@Setter
Expand All @@ -11,7 +12,7 @@ public class UpdateUserRequest {
private String nickname;
private String username;
private String password;
private String profileUrl;
private MultipartFile file;
private String email;
private String currentPassword;
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,22 @@ public UserInfoResponse getCurrentUserInfo(@Parameter(description = "Accesstoken

return userService.getUserInfo(userId);
}

@Operation(summary = "ํ˜„์žฌ ์œ ์ € ํ”„๋กœํ•„ ์—…๋ฐ์ดํŠธ", description = "์œ ์ €์˜ nickname, username, password(์ง€๋‚œ ๋น„๋ฐ€๋ฒˆํ˜ธ ๊ฒ€์ฆ ๊ณผ์ • ์กด์žฌ) email, profileImage ์—…๋กœ๋“œ ๊ธฐ๋Šฅ(null ๊ฐ’์œผ๋กœ ์ „์†ก ์‹œ, ์—…๋ฐ์ดํŠธ X)")
@PostMapping("/profile")
public UserInfoResponse updateCurrentUserInfo(@Parameter(description = "Accesstoken์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.", required = true) @RequestHeader("Authorization") String token,
@Valid @RequestBody UpdateUserRequest updateUserRequest) {
if (token == null) {
throw new InvalidTokenException();
}

String jwt = token.startsWith("Bearer ") ? token.substring(7) : token;
if (!jwtUtil.validateToken(jwt)) {
throw new IllegalArgumentException("Invalid token");
}
Long userId = jwtUtil.extractId(jwt);

return userService.updateUserProfile(userId, updateUserRequest);
}

}
}
12 changes: 7 additions & 5 deletions src/main/java/com/goormdari/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.goormdari.domain.user.service;

import com.amazonaws.services.kms.model.NotFoundException;
import com.goormdari.domain.user.domain.exception.DuplicateUsernameException;
import com.goormdari.domain.user.domain.exception.InvalidPasswordException;
import com.goormdari.domain.user.dto.response.UserInfoResponse;
import com.goormdari.domain.user.dto.response.FindCurrentStepResponse;
Expand All @@ -10,6 +11,7 @@
import com.goormdari.domain.user.dto.request.LoginRequest;
import com.goormdari.domain.user.dto.response.JwtResponse;
import com.goormdari.domain.user.domain.repository.UserRepository;
import com.goormdari.global.config.s3.S3Service;
import com.goormdari.domain.validation.annotation.ExistUser;
import com.goormdari.global.config.security.jwt.JWTUtil;

Expand All @@ -33,6 +35,7 @@ public class UserService {
private final UserRepository userRepository;
private final PasswordEncoder passwordEncoder;
private final AuthenticationManager authenticationManager;
private final S3Service s3Service;
private final JWTUtil jwtUtil;


Expand All @@ -52,8 +55,6 @@ public Long save(AddUserRequest dto) {
throw new IllegalArgumentException("Username is already exists.");
}



// ์‚ฌ์šฉ์ž ์ €์žฅ
return userRepository.save(User.builder()
.nickname(dto.getNickname())
Expand Down Expand Up @@ -122,7 +123,7 @@ public UserInfoResponse updateUserProfile(Long userId, com.goormdari.domain.user
if (updateUserRequest.getUsername() != null && !updateUserRequest.getUsername().isEmpty()) {
if (userRepository.findByUsername(updateUserRequest.getUsername()).isPresent() &&
!user.getUsername().equals(updateUserRequest.getUsername())) {
throw new IllegalArgumentException("Username is already exists.");
throw new DuplicateUsernameException("Username is already exists.");
}
user.updateUsername(updateUserRequest.getUsername());
}
Expand All @@ -137,8 +138,9 @@ public UserInfoResponse updateUserProfile(Long userId, com.goormdari.domain.user
}

// ํ”„๋กœํ•„ URL ์—…๋ฐ์ดํŠธ
if (updateUserRequest.getProfileUrl() != null && !updateUserRequest.getProfileUrl().isEmpty()) {
user.updateProfileUrl(updateUserRequest.getProfileUrl());
if (updateUserRequest.getFile() != null && !updateUserRequest.getFile().isEmpty()) {
String profileUrl = s3Service.uploadImageToS3(updateUserRequest.getFile());
user.updateProfileUrl(profileUrl);
}

// ํ”„๋กœํ•„ ์ด๋ฉ”์ผ ์—…๋ฐ์ดํŠธ
Expand Down

0 comments on commit d0cf286

Please sign in to comment.