Skip to content

Commit f3dd2e6

Browse files
committed
feat: 회원 기능 수정 #16
- 로그인 아이디 중복 확인 기능 추가 - 타 유저 프로필 조회 기능 추가 - 마이페이지에서 페이징 처리를 위해 "내 감정 기록"은 다른 API로 빼버림
1 parent 12692da commit f3dd2e6

File tree

5 files changed

+61
-10
lines changed

5 files changed

+61
-10
lines changed

src/main/java/org/dfbf/soundlink/domain/user/controller/UserController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public ResponseResult checkNickName(@RequestParam String nickName){
3232
return userService.checkNickName(nickName);
3333
}
3434

35+
@GetMapping("/checkLoginId")
36+
@Operation(summary = "LoginId 중복 확인", description = "LoginId가 이미 사용중인지 확인.")
37+
public ResponseResult checkLoginiId(@RequestParam String loginiId){
38+
return userService.checkLoginiId(loginiId);
39+
}
40+
3541
@GetMapping
3642
@Operation(summary = "유저 조회", description = "유저 조회 API")
3743
public ResponseResult getUser(@AuthenticationPrincipal Long id) { return userService.getUser(id); }
@@ -50,6 +56,10 @@ public ResponseResult updateUser(@AuthenticationPrincipal Long id,@RequestBody U
5056
@Operation(summary = "마이 페이지", description = "마이 페이지 조회 API")
5157
public ResponseResult getMyPage(@AuthenticationPrincipal Long id) { return userService.getMyPage(id); }
5258

59+
@GetMapping("/profile")
60+
@Operation(summary = "타 유저 프로필 조회", description = "타 유저 프로필 조회 API")
61+
public ResponseResult getProfile(@RequestParam("tag") String tag) { return userService.getProfile(tag); }
62+
5363
@PostMapping("/login")
5464
@Operation(summary = "로그인", description = "로그인 API")
5565
public ResponseResult login(@RequestBody LoginReqDto loginReqDto, HttpServletResponse response) {

src/main/java/org/dfbf/soundlink/domain/user/dto/response/UserMyPageDto.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@
88

99
@Getter
1010
public class UserMyPageDto {
11-
private final String email;
1211
private final String loginId;
1312
private final String nickname;
1413
private final ProfileMusic profileMusic;
15-
private List<EmotionRecordDto> emotionRecords;
1614

17-
public void setEmotionRecords(List<EmotionRecordDto> emotionRecords) { this.emotionRecords = emotionRecords; }
18-
19-
public UserMyPageDto(String email, String loginId, String nickname, ProfileMusic profileMusic) {
20-
this.email = email;
15+
public UserMyPageDto(String loginId, String nickname, ProfileMusic profileMusic) {
2116
this.loginId = loginId;
2217
this.nickname = nickname;
2318
this.profileMusic = profileMusic;

src/main/java/org/dfbf/soundlink/domain/user/repository/UserRepository.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ public interface UserRepository extends JpaRepository<User, Long> {
1313

1414
boolean existsByNickname(String nickName);
1515

16+
boolean existsByLoginId(String loginId);
17+
1618
Optional<User> findById(Long id);
1719

1820
// JPQL에서는 Inner Class에 직접 값을 넣을 수 있도록 하는 기능은 지원하지 않는다.
1921
@Query(
2022
"SELECT new org.dfbf.soundlink.domain.user.dto.response.UserMyPageDto(" +
21-
"u.email, u.loginId, u.nickname," +
23+
"u.loginId, u.nickname," +
2224
"new org.dfbf.soundlink.domain.user.dto.response.ProfileMusic(" +
2325
"pm.spotifyMusic.spotifyId, pm.spotifyMusic.title, pm.spotifyMusic.artist, pm.spotifyMusic.albumImage)) " +
2426
"FROM User u " +
@@ -27,9 +29,19 @@ public interface UserRepository extends JpaRepository<User, Long> {
2729
)
2830
UserMyPageDto findMyPageDtoByUserId(@Param("user") User user);
2931

30-
//로그인관련
31-
boolean existsByLoginId(String loginId);
32+
// JPQL에서는 Inner Class에 직접 값을 넣을 수 있도록 하는 기능은 지원하지 않는다.
33+
@Query(
34+
"SELECT new org.dfbf.soundlink.domain.user.dto.response.UserMyPageDto(" +
35+
"u.loginId, u.nickname," +
36+
"new org.dfbf.soundlink.domain.user.dto.response.ProfileMusic(" +
37+
"pm.spotifyMusic.spotifyId, pm.spotifyMusic.title, pm.spotifyMusic.artist, pm.spotifyMusic.albumImage)) " +
38+
"FROM User u " +
39+
"JOIN FETCH ProfileMusic pm ON pm.user = u " +
40+
"WHERE u.loginId = :loginId"
41+
)
42+
Optional<UserMyPageDto> findMyPageDtoByLoginId(@Param("loginId") String loginId);
3243

44+
//로그인관련
3345
Optional<User> findByLoginId(String loginId);
3446

3547
@Query("Select u.password from User u where u.loginId =:loginId ")

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ public ResponseResult getMyPage(Long userId) {
140140
User user = userRepository.findById(userId).orElseThrow(() -> new NoUserDataException());
141141

142142
UserMyPageDto result = userRepository.findMyPageDtoByUserId(user);
143-
result.setEmotionRecords(emotionRecordRepository.findByUser(user));
144143

145144
return new ResponseResult(ErrorCode.SUCCESS, result);
146145
} catch (NoUserDataException e) {
@@ -246,4 +245,31 @@ public ResponseResult logout(HttpServletResponse response) {
246245
return new ResponseResult(ErrorCode. INTERNAL_SERVER_ERROR,"로그아웃 중 오류가 발생했습니다.");
247246
}
248247
}
248+
249+
// loginId 중복 확인
250+
public ResponseResult checkLoginiId(String loginId) {
251+
try {
252+
if (userRepository.existsByLoginId(loginId)) {
253+
return new ResponseResult(400, "Duplicate");
254+
} else {
255+
return new ResponseResult(ErrorCode.SUCCESS);
256+
}
257+
} catch (Exception e) {
258+
return new ResponseResult(ErrorCode.DB_ERROR);
259+
}
260+
}
261+
262+
// 타 유저 프로필
263+
public ResponseResult getProfile(String tag) {
264+
try {
265+
UserMyPageDto result = userRepository.findMyPageDtoByLoginId(tag)
266+
.orElseThrow(() -> new NoUserDataException());
267+
268+
return new ResponseResult(ErrorCode.SUCCESS, result);
269+
} catch (NoUserDataException e) {
270+
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER);
271+
} catch (Exception e) {
272+
return new ResponseResult(ErrorCode.DB_ERROR);
273+
}
274+
}
249275
}

src/main/java/org/dfbf/soundlink/global/exception/ResponseResult.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public ResponseResult(ErrorCode errorCode, Object data){
4242
this.data = data;
4343
}
4444

45+
@Builder
46+
public ResponseResult(int code, String message){
47+
this.code = code;
48+
this.message = message;
49+
this.timestamp = Instant.now().toString();
50+
this.data = null;
51+
}
52+
4553
@Builder
4654
public ResponseResult(Object data){
4755
this.code = ErrorCode.SUCCESS.getStatus().value();

0 commit comments

Comments
 (0)