Skip to content

Commit 9791c13

Browse files
authored
Merge pull request #2 from FlipNoteTeam/feat/update-profile
Feat: [FN-296] 프로필 수정
2 parents d46f804 + d703857 commit 9791c13

13 files changed

Lines changed: 229 additions & 93 deletions

File tree

src/main/java/flipnote/user/auth/application/AuthService.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import flipnote.user.auth.presentation.dto.response.TokenValidateResponse;
2020
import flipnote.user.auth.presentation.dto.response.UserResponse;
2121
import flipnote.user.global.config.ClientProperties;
22-
import flipnote.user.global.exception.UserException;
22+
import flipnote.user.global.exception.BizException;
2323
import flipnote.user.user.domain.OAuthLink;
2424
import flipnote.user.user.domain.OAuthLinkRepository;
2525
import flipnote.user.user.domain.User;
@@ -54,11 +54,11 @@ public class AuthService {
5454
@Transactional
5555
public UserResponse register(SignupRequest request) {
5656
if (!emailVerificationRepository.isVerified(request.getEmail())) {
57-
throw new UserException(AuthErrorCode.UNVERIFIED_EMAIL);
57+
throw new BizException(AuthErrorCode.UNVERIFIED_EMAIL);
5858
}
5959

6060
if (userRepository.existsByEmail(request.getEmail())) {
61-
throw new UserException(AuthErrorCode.EMAIL_ALREADY_EXISTS);
61+
throw new BizException(AuthErrorCode.EMAIL_ALREADY_EXISTS);
6262
}
6363

6464
User user = User.builder()
@@ -76,10 +76,10 @@ public UserResponse register(SignupRequest request) {
7676

7777
public TokenPair login(LoginRequest request) {
7878
User user = userRepository.findByEmailAndStatus(request.getEmail(), User.Status.ACTIVE)
79-
.orElseThrow(() -> new UserException(AuthErrorCode.INVALID_CREDENTIALS));
79+
.orElseThrow(() -> new BizException(AuthErrorCode.INVALID_CREDENTIALS));
8080

8181
if (!passwordEncoder.matches(request.getPassword(), user.getPassword())) {
82-
throw new UserException(AuthErrorCode.INVALID_CREDENTIALS);
82+
throw new BizException(AuthErrorCode.INVALID_CREDENTIALS);
8383
}
8484

8585
return jwtProvider.generateTokenPair(user);
@@ -96,18 +96,18 @@ public void logout(String refreshToken) {
9696

9797
public TokenPair refreshToken(String refreshToken) {
9898
if (refreshToken == null || !jwtProvider.isTokenValid(refreshToken)) {
99-
throw new UserException(AuthErrorCode.INVALID_TOKEN);
99+
throw new BizException(AuthErrorCode.INVALID_TOKEN);
100100
}
101101

102102
if (tokenBlacklistRepository.isBlacklisted(refreshToken)) {
103-
throw new UserException(AuthErrorCode.BLACKLISTED_TOKEN);
103+
throw new BizException(AuthErrorCode.BLACKLISTED_TOKEN);
104104
}
105105

106106
TokenClaims claims = jwtProvider.extractClaims(refreshToken);
107107

108108
sessionInvalidationRepository.getInvalidatedAtMillis(claims.userId()).ifPresent(invalidatedAtMillis -> {
109109
if (jwtProvider.getIssuedAt(refreshToken).getTime() < invalidatedAtMillis) {
110-
throw new UserException(AuthErrorCode.INVALIDATED_SESSION);
110+
throw new BizException(AuthErrorCode.INVALIDATED_SESSION);
111111
}
112112
});
113113

@@ -126,7 +126,7 @@ public void changePassword(Long userId, ChangePasswordRequest request) {
126126
User user = findActiveUser(userId);
127127

128128
if (!passwordEncoder.matches(request.getCurrentPassword(), user.getPassword())) {
129-
throw new UserException(AuthErrorCode.PASSWORD_MISMATCH);
129+
throw new BizException(AuthErrorCode.PASSWORD_MISMATCH);
130130
}
131131

132132
user.changePassword(passwordEncoder.encode(request.getNewPassword()));
@@ -135,18 +135,18 @@ public void changePassword(Long userId, ChangePasswordRequest request) {
135135

136136
public TokenValidateResponse validateToken(String token) {
137137
if (!jwtProvider.isTokenValid(token)) {
138-
throw new UserException(AuthErrorCode.INVALID_TOKEN);
138+
throw new BizException(AuthErrorCode.INVALID_TOKEN);
139139
}
140140

141141
if (tokenBlacklistRepository.isBlacklisted(token)) {
142-
throw new UserException(AuthErrorCode.BLACKLISTED_TOKEN);
142+
throw new BizException(AuthErrorCode.BLACKLISTED_TOKEN);
143143
}
144144

145145
TokenClaims claims = jwtProvider.extractClaims(token);
146146

147147
sessionInvalidationRepository.getInvalidatedAtMillis(claims.userId()).ifPresent(invalidatedAtMillis -> {
148148
if (jwtProvider.getIssuedAt(token).getTime() < invalidatedAtMillis) {
149-
throw new UserException(AuthErrorCode.INVALIDATED_SESSION);
149+
throw new BizException(AuthErrorCode.INVALIDATED_SESSION);
150150
}
151151
});
152152

@@ -157,7 +157,7 @@ public TokenValidateResponse validateToken(String token) {
157157

158158
public void sendEmailVerificationCode(String email) {
159159
if (emailVerificationRepository.hasCode(email)) {
160-
throw new UserException(AuthErrorCode.ALREADY_ISSUED_VERIFICATION_CODE);
160+
throw new BizException(AuthErrorCode.ALREADY_ISSUED_VERIFICATION_CODE);
161161
}
162162

163163
String code = verificationCodeGenerator.generate();
@@ -167,12 +167,12 @@ public void sendEmailVerificationCode(String email) {
167167

168168
public void verifyEmail(String email, String code) {
169169
if (!emailVerificationRepository.hasCode(email)) {
170-
throw new UserException(AuthErrorCode.NOT_ISSUED_VERIFICATION_CODE);
170+
throw new BizException(AuthErrorCode.NOT_ISSUED_VERIFICATION_CODE);
171171
}
172172

173173
String savedCode = emailVerificationRepository.getCode(email);
174174
if (!code.equals(savedCode)) {
175-
throw new UserException(AuthErrorCode.INVALID_VERIFICATION_CODE);
175+
throw new BizException(AuthErrorCode.INVALID_VERIFICATION_CODE);
176176
}
177177

178178
emailVerificationRepository.deleteCode(email);
@@ -186,7 +186,7 @@ public void requestPasswordReset(String email) {
186186
}
187187

188188
if (passwordResetRepository.hasToken(email)) {
189-
throw new UserException(AuthErrorCode.ALREADY_SENT_PASSWORD_RESET_LINK);
189+
throw new BizException(AuthErrorCode.ALREADY_SENT_PASSWORD_RESET_LINK);
190190
}
191191

192192
String token = passwordResetTokenGenerator.generate();
@@ -201,11 +201,11 @@ public void requestPasswordReset(String email) {
201201
public void resetPassword(String token, String newPassword) {
202202
String email = passwordResetRepository.findEmailByToken(token);
203203
if (email == null) {
204-
throw new UserException(AuthErrorCode.INVALID_PASSWORD_RESET_TOKEN);
204+
throw new BizException(AuthErrorCode.INVALID_PASSWORD_RESET_TOKEN);
205205
}
206206

207207
User user = userRepository.findByEmailAndStatus(email, User.Status.ACTIVE)
208-
.orElseThrow(() -> new UserException(UserErrorCode.USER_NOT_FOUND));
208+
.orElseThrow(() -> new BizException(UserErrorCode.USER_NOT_FOUND));
209209

210210
user.changePassword(passwordEncoder.encode(newPassword));
211211
sessionInvalidationRepository.invalidate(user.getId(), jwtProvider.getRefreshTokenExpiration());
@@ -220,13 +220,13 @@ public SocialLinksResponse getSocialLinks(Long userId) {
220220
@Transactional
221221
public void deleteSocialLink(Long userId, Long socialLinkId) {
222222
if (!oAuthLinkRepository.existsByIdAndUser_Id(socialLinkId, userId)) {
223-
throw new UserException(AuthErrorCode.NOT_REGISTERED_SOCIAL_ACCOUNT);
223+
throw new BizException(AuthErrorCode.NOT_REGISTERED_SOCIAL_ACCOUNT);
224224
}
225225
oAuthLinkRepository.deleteById(socialLinkId);
226226
}
227227

228228
private User findActiveUser(Long userId) {
229229
return userRepository.findByIdAndStatus(userId, User.Status.ACTIVE)
230-
.orElseThrow(() -> new UserException(UserErrorCode.USER_NOT_FOUND));
230+
.orElseThrow(() -> new BizException(UserErrorCode.USER_NOT_FOUND));
231231
}
232232
}

src/main/java/flipnote/user/auth/application/OAuthService.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import flipnote.user.auth.infrastructure.redis.SocialLinkTokenRepository;
1010
import flipnote.user.global.config.OAuthProperties;
1111
import flipnote.user.global.constants.HttpConstants;
12-
import flipnote.user.global.exception.UserException;
12+
import flipnote.user.global.exception.BizException;
1313
import flipnote.user.user.domain.OAuthLink;
1414
import flipnote.user.user.domain.OAuthLinkRepository;
1515
import flipnote.user.user.domain.User;
@@ -75,7 +75,7 @@ public TokenPair socialLogin(String providerName, String code, String codeVerifi
7575

7676
OAuthLink oAuthLink = oAuthLinkRepository
7777
.findByProviderAndProviderIdWithUser(userInfo.getProvider(), userInfo.getProviderId())
78-
.orElseThrow(() -> new UserException(AuthErrorCode.NOT_REGISTERED_SOCIAL_ACCOUNT));
78+
.orElseThrow(() -> new BizException(AuthErrorCode.NOT_REGISTERED_SOCIAL_ACCOUNT));
7979

8080
return jwtProvider.generateTokenPair(oAuthLink.getUser());
8181
}
@@ -84,19 +84,19 @@ public TokenPair socialLogin(String providerName, String code, String codeVerifi
8484
public void linkSocialAccount(String providerName, String code, String state,
8585
String codeVerifier, HttpServletRequest request) {
8686
Long userId = socialLinkTokenRepository.findUserIdByState(state)
87-
.orElseThrow(() -> new UserException(AuthErrorCode.INVALID_SOCIAL_LINK_TOKEN));
87+
.orElseThrow(() -> new BizException(AuthErrorCode.INVALID_SOCIAL_LINK_TOKEN));
8888

8989
socialLinkTokenRepository.delete(state);
9090

9191
OAuth2UserInfo userInfo = getOAuth2UserInfo(providerName, code, codeVerifier, request);
9292

9393
if (oAuthLinkRepository.existsByUser_IdAndProviderAndProviderId(
9494
userId, userInfo.getProvider(), userInfo.getProviderId())) {
95-
throw new UserException(AuthErrorCode.ALREADY_LINKED_SOCIAL_ACCOUNT);
95+
throw new BizException(AuthErrorCode.ALREADY_LINKED_SOCIAL_ACCOUNT);
9696
}
9797

9898
User user = userRepository.findByIdAndStatus(userId, User.Status.ACTIVE)
99-
.orElseThrow(() -> new UserException(UserErrorCode.USER_NOT_FOUND));
99+
.orElseThrow(() -> new BizException(UserErrorCode.USER_NOT_FOUND));
100100

101101
OAuthLink link = OAuthLink.builder()
102102
.provider(userInfo.getProvider())
@@ -117,12 +117,12 @@ private OAuth2UserInfo getOAuth2UserInfo(String providerName, String code,
117117
private OAuthProperties.Provider resolveProvider(String providerName) {
118118
Map<String, OAuthProperties.Provider> providers = oAuthProperties.getProviders();
119119
if (providers == null) {
120-
throw new UserException(AuthErrorCode.INVALID_OAUTH_PROVIDER);
120+
throw new BizException(AuthErrorCode.INVALID_OAUTH_PROVIDER);
121121
}
122122
OAuthProperties.Provider provider = providers.get(providerName.toLowerCase());
123123
if (provider == null) {
124124
log.warn("지원하지 않는 OAuth Provider: {}", providerName);
125-
throw new UserException(AuthErrorCode.INVALID_OAUTH_PROVIDER);
125+
throw new BizException(AuthErrorCode.INVALID_OAUTH_PROVIDER);
126126
}
127127
return provider;
128128
}

src/main/java/flipnote/user/auth/presentation/OAuthController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import flipnote.user.auth.application.OAuthService;
44
import flipnote.user.auth.domain.AuthErrorCode;
5-
import flipnote.user.global.exception.UserException;
5+
import flipnote.user.global.exception.BizException;
66
import flipnote.user.auth.domain.TokenPair;
77
import flipnote.user.global.config.ClientProperties;
88
import flipnote.user.global.constants.HttpConstants;
@@ -86,7 +86,7 @@ private ResponseEntity<Void> handleSocialLink(String provider, String code, Stri
8686
return ResponseEntity.status(HttpStatus.FOUND)
8787
.location(URI.create(clientProperties.getUrl() + clientProperties.getPaths().getSocialLinkSuccess()))
8888
.build();
89-
} catch (UserException e) {
89+
} catch (BizException e) {
9090
log.warn("소셜 계정 연동 처리 실패. provider: {}", provider, e);
9191
if (e.getErrorCode() == AuthErrorCode.ALREADY_LINKED_SOCIAL_ACCOUNT) {
9292
return ResponseEntity.status(HttpStatus.FOUND)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package flipnote.user.global.config;
2+
3+
import flipnote.image.grpc.v1.ImageCommandServiceGrpc;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.grpc.client.GrpcChannelFactory;
7+
8+
@Configuration
9+
public class GrpcClientConfig {
10+
11+
@Bean
12+
ImageCommandServiceGrpc.ImageCommandServiceBlockingStub imageCommandServiceBlockingStub(
13+
GrpcChannelFactory channelFactory) {
14+
return ImageCommandServiceGrpc.newBlockingStub(channelFactory.createChannel("image-service"));
15+
}
16+
}

src/main/java/flipnote/user/global/error/GlobalExceptionHandler.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package flipnote.user.global.error;
22

3-
import flipnote.user.global.exception.UserException;
3+
import flipnote.user.global.exception.BizException;
44
import lombok.extern.slf4j.Slf4j;
55
import org.springframework.http.HttpStatus;
66
import org.springframework.http.ResponseEntity;
@@ -15,9 +15,13 @@
1515
@RestControllerAdvice
1616
public class GlobalExceptionHandler {
1717

18-
@ExceptionHandler(UserException.class)
19-
public ResponseEntity<ApiResponse<Void>> handleUserException(UserException e) {
20-
log.warn("UserException: {}", e.getMessage());
18+
@ExceptionHandler(BizException.class)
19+
public ResponseEntity<ApiResponse<Void>> handleBizException(BizException e) {
20+
log.warn("BizException: code={}, status={}, message={}",
21+
e.getErrorCode().getCode(),
22+
e.getErrorCode().getStatus(),
23+
e.getErrorCode().getMessage()
24+
);
2125
return ResponseEntity.status(e.getErrorCode().getStatus()).body(ApiResponse.error(e.getErrorCode()));
2226
}
2327

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package flipnote.user.global.error;
2+
3+
import lombok.Getter;
4+
import lombok.RequiredArgsConstructor;
5+
import org.springframework.http.HttpStatus;
6+
7+
@Getter
8+
@RequiredArgsConstructor
9+
public enum ImageErrorCode implements ErrorCode {
10+
11+
IMAGE_SERVICE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "IMAGE_001", "이미지 서비스 처리 중 오류가 발생했습니다.");
12+
13+
private final HttpStatus httpStatus;
14+
private final String code;
15+
private final String message;
16+
17+
@Override
18+
public int getStatus() {
19+
return httpStatus.value();
20+
}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package flipnote.user.global.exception;
2+
3+
import flipnote.user.global.error.ErrorCode;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
7+
@Getter
8+
@AllArgsConstructor
9+
public class BizException extends RuntimeException {
10+
11+
private ErrorCode errorCode;
12+
}

src/main/java/flipnote/user/global/exception/UserException.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)