Skip to content

Commit 295a13d

Browse files
committed
fix: 유저 수정 기능 수정
- 프로필 뮤직이 변경이 없을때 처리
1 parent 6957847 commit 295a13d

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

src/main/java/org/dfbf/soundlink/domain/user/dto/request/UserUpdateDto.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,17 @@ public record UserUpdateDto(
1313
Optional<String> albumImage,
1414
Optional<String> videoId
1515
) {
16+
public String toString(){
17+
return "UserUpdateDto{" +
18+
"email=" + email +
19+
", loginId=" + loginId +
20+
", nickName=" + nickName +
21+
", password=" + password +
22+
", spotifyId=" + spotifyId +
23+
", title=" + title +
24+
", artist=" + artist +
25+
", albumImage=" + albumImage +
26+
", videoId=" + videoId +
27+
"}";
28+
}
1629
}

src/main/java/org/dfbf/soundlink/domain/user/entity/User.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@Entity
1616
@Getter
1717
@NoArgsConstructor(access = AccessLevel.PROTECTED)
18+
@ToString
1819
public class User {
1920
@Id
2021
@GeneratedValue(strategy = GenerationType.IDENTITY)

src/main/java/org/dfbf/soundlink/domain/user/service/UserService.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public ResponseResult signUp(UserSignUpDto userSignUpDto) {
8080
userRepository.save(userSignUpDto.toEntity(passwordEncoder));
8181
return new ResponseResult(ErrorCode.SUCCESS);
8282
} catch (Exception e) {
83-
return new ResponseResult(ErrorCode.DB_ERROR);
83+
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
8484
}
8585
}
8686

@@ -95,7 +95,7 @@ public ResponseResult getUser(Long userId) {
9595

9696
return new ResponseResult(ErrorCode.SUCCESS, result);
9797
} catch (NoUserDataException e) {
98-
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER);
98+
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER, e.getMessage());
9999
}
100100
}
101101

@@ -111,6 +111,7 @@ public ResponseResult updateUser(Long userId, UserUpdateDto userUpdateDto) {
111111
* orElse -> 일단 함수는 실행, 그러나 값이 null이면 orElse의 값으로 대체 (함수O, 람다x)
112112
* orElseGet -> null일때만 실행 (함수O, 람다O)
113113
*/
114+
//log.info("userUpdateDto: " + userUpdateDto.toString());
114115

115116
try {
116117
User user = userRepository.findByUserIdWithCache(userId)
@@ -129,12 +130,13 @@ public ResponseResult updateUser(Long userId, UserUpdateDto userUpdateDto) {
129130
}
130131

131132
user.update(userUpdateDto, passwordEncoder, spotifyMusicList.get(0));
133+
profileMusicRepository.save(user.getProfileMusic());
132134
} else {
133135
if("-1".equals(spotifyId)) { user.getProfileMusic().deleteSpotifyId(); }
134136
user.update(userUpdateDto, passwordEncoder);
137+
log.info(user.toString());
135138
}
136139

137-
profileMusicRepository.save(user.getProfileMusic());
138140
userRepository.saveWithCache(user);
139141

140142
return new ResponseResult(ErrorCode.SUCCESS);
@@ -167,9 +169,9 @@ public ResponseResult deleteUser(Long userId) {
167169

168170
return new ResponseResult(ErrorCode.SUCCESS);
169171
} catch (NoUserDataException e) {
170-
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER);
172+
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER, e.getMessage());
171173
} catch (Exception e) {
172-
return new ResponseResult(ErrorCode.DB_ERROR);
174+
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
173175
}
174176
}
175177

@@ -185,9 +187,9 @@ public ResponseResult passwordCheck(Long userId, CheckPasswordDto dto) {
185187
return new ResponseResult(ErrorCode.NOT_EQUALS_PASSWORD);
186188
}
187189
} catch (NoUserDataException e) {
188-
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER);
190+
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER, e.getMessage());
189191
} catch (Exception e) {
190-
return new ResponseResult(ErrorCode.DB_ERROR);
192+
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
191193
}
192194
}
193195

@@ -202,9 +204,9 @@ public ResponseResult getMyPage(Long userId) {
202204

203205
return new ResponseResult(ErrorCode.SUCCESS, result);
204206
} catch (NoUserDataException e) {
205-
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER);
207+
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER, e.getMessage());
206208
} catch (Exception e) {
207-
return new ResponseResult(ErrorCode.DB_ERROR);
209+
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
208210
}
209211
}
210212

@@ -216,7 +218,7 @@ public ResponseResult sendAuthCode(String email) {
216218
redisService.setCode(email, authCode);
217219
return new ResponseResult(ErrorCode.SUCCESS, email);
218220
} catch (MessagingException e) {
219-
return new ResponseResult(ErrorCode.EMAIL_SEND_ERROR, "이메일 전송에 실패했습니다.");
221+
return new ResponseResult(ErrorCode.EMAIL_SEND_ERROR, e.getMessage());
220222
}
221223
}
222224

@@ -231,7 +233,7 @@ public ResponseResult validateAuthCode(String email, String authCode){
231233
return new ResponseResult(ErrorCode.BAD_REQUEST, "이메일 전송 실패: 잘못된 요청입니다.");
232234
}
233235
} catch (AuthenticationException e) {
234-
return new ResponseResult(ErrorCode.EMAIL_SEND_ERROR);
236+
return new ResponseResult(ErrorCode.EMAIL_SEND_ERROR, e.getMessage());
235237
}
236238
}
237239

@@ -361,7 +363,7 @@ public ResponseResult checkLoginiId(String loginId) {
361363
return new ResponseResult(ErrorCode.NOT_DUPLICATE_LOGINID);
362364
}
363365
} catch (Exception e) {
364-
return new ResponseResult(ErrorCode.DB_ERROR);
366+
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
365367
}
366368
}
367369

@@ -376,7 +378,7 @@ public ResponseResult getProfile(String tag) {
376378

377379
return new ResponseResult(ErrorCode.SUCCESS, result);
378380
} catch (NoUserDataException e) {
379-
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER);
381+
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER, e.getMessage());
380382
} catch (Exception e) {
381383
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
382384
}

0 commit comments

Comments
 (0)