Skip to content

Commit 5710915

Browse files
authored
feat: 비밀번호 수정, 프로필 수정 api 분리 (#99)
* feat: 비밀번호 변경 기능 구현 * refactor: 프로필 이미지 수정, 자기소개 수정 api 분리 * refactor: 프로필 이미지 수정, 자기소개 수정 api 분리2 * refactor: 불필요 import제거 * refactor: checkStyle
1 parent 787ef30 commit 5710915

File tree

14 files changed

+389
-282
lines changed

14 files changed

+389
-282
lines changed

src/main/java/com/threestar/trainus/domain/profile/controller/ProfileController.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import org.springframework.web.bind.annotation.RequestMapping;
1010
import org.springframework.web.bind.annotation.RestController;
1111

12+
import com.threestar.trainus.domain.profile.dto.ImageUpdateRequestDto;
13+
import com.threestar.trainus.domain.profile.dto.ImageUpdateResponseDto;
14+
import com.threestar.trainus.domain.profile.dto.IntroUpdateRequestDto;
15+
import com.threestar.trainus.domain.profile.dto.IntroUpdateResponseDto;
1216
import com.threestar.trainus.domain.profile.dto.ProfileDetailResponseDto;
13-
import com.threestar.trainus.domain.profile.dto.ProfileResponseDto;
14-
import com.threestar.trainus.domain.profile.dto.ProfileUpdateRequestDto;
1517
import com.threestar.trainus.domain.profile.service.ProfileFacadeService;
1618
import com.threestar.trainus.global.annotation.LoginUser;
1719
import com.threestar.trainus.global.unit.BaseResponse;
@@ -38,13 +40,23 @@ public ResponseEntity<BaseResponse<ProfileDetailResponseDto>> getProfileDetail(
3840
return BaseResponse.ok("프로필 상세 조회가 완료되었습니다.", response, HttpStatus.OK);
3941
}
4042

41-
@PatchMapping
42-
@Operation(summary = "유저 프로필 수정 api")
43-
public ResponseEntity<BaseResponse<ProfileResponseDto>> updateProfile(
44-
@Valid @RequestBody ProfileUpdateRequestDto requestDto,
45-
@LoginUser Long userId
43+
@PatchMapping("/image")
44+
@Operation(summary = "유저 프로필 이미지 수정 api")
45+
public ResponseEntity<BaseResponse<ImageUpdateResponseDto>> updateProfileImage(
46+
@Valid @RequestBody ImageUpdateRequestDto requestDto,
47+
@LoginUser Long loginUserId
4648
) {
47-
ProfileResponseDto response = facadeService.updateProfile(userId, requestDto);
48-
return BaseResponse.ok("프로필 수정이 완료되었습니다.", response, HttpStatus.OK);
49+
ImageUpdateResponseDto response = facadeService.updateProfileImage(loginUserId, requestDto);
50+
return BaseResponse.ok("프로필 이미지 수정이 완료되었습니다.", response, HttpStatus.OK);
51+
}
52+
53+
@PatchMapping("/intro")
54+
@Operation(summary = "유저 프로필 자기소개 수정 api")
55+
public ResponseEntity<BaseResponse<IntroUpdateResponseDto>> updateProfileIntro(
56+
@Valid @RequestBody IntroUpdateRequestDto requestDto,
57+
@LoginUser Long loginUserId
58+
) {
59+
IntroUpdateResponseDto response = facadeService.updateProfileIntro(loginUserId, requestDto);
60+
return BaseResponse.ok("프로필 자기소개 수정이 완료되었습니다.", response, HttpStatus.OK);
4961
}
5062
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
package com.threestar.trainus.domain.profile.dto;
22

3-
import org.hibernate.validator.constraints.URL;
4-
53
import jakarta.validation.constraints.Pattern;
64
import jakarta.validation.constraints.Size;
75

8-
public record ProfileUpdateRequestDto(
6+
public record ImageUpdateRequestDto(
97

108
@Size(max = 2048, message = "프로필 이미지 URL은 2048자 이하여야 합니다.")
119
@Pattern(
1210
regexp = "^$|^https?://[\\w\\-._~:/?#\\[\\]@!$&'()*+,;=%]+$",
1311
message = "올바른 URL 형식이어야 합니다."
1412
)
15-
String profileImage,
16-
17-
@Size(max = 255, message = "자기소개는 255자 이하여야 합니다.")
18-
String intro
13+
String profileImage
1914
) {
2015
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.threestar.trainus.domain.profile.dto;
2+
3+
public record ImageUpdateResponseDto(
4+
Long userId,
5+
String nickname,
6+
String profileImage
7+
) {
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.threestar.trainus.domain.profile.dto;
2+
3+
import jakarta.validation.constraints.Size;
4+
5+
public record IntroUpdateRequestDto(
6+
7+
@Size(max = 255, message = "자기소개는 255자 이하여야 합니다.")
8+
String intro
9+
) {
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.threestar.trainus.domain.profile.dto;
2+
3+
public record IntroUpdateResponseDto(
4+
Long userId,
5+
String nickname,
6+
String intro
7+
) {
8+
}

src/main/java/com/threestar/trainus/domain/profile/entity/Profile.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ public class Profile {
3939
@Column(length = 255)
4040
private String intro;
4141

42-
public void updateProfile(String profileImage, String intro) {
42+
public void updateProfileImage(String profileImage) {
4343
this.profileImage = profileImage;
44+
}
45+
46+
public void updateProfileIntro(String intro) {
4447
this.intro = intro;
4548
}
4649
}

src/main/java/com/threestar/trainus/domain/profile/mapper/ProfileMapper.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.threestar.trainus.domain.profile.mapper;
22

3+
import com.threestar.trainus.domain.profile.dto.ImageUpdateResponseDto;
4+
import com.threestar.trainus.domain.profile.dto.IntroUpdateResponseDto;
35
import com.threestar.trainus.domain.profile.dto.ProfileResponseDto;
46
import com.threestar.trainus.domain.profile.entity.Profile;
57
import com.threestar.trainus.domain.user.entity.User;
@@ -19,6 +21,22 @@ public static ProfileResponseDto toResponseDto(Profile profile, User user) {
1921
);
2022
}
2123

24+
public static ImageUpdateResponseDto toImageResponseDto(Profile profile, User user) {
25+
return new ImageUpdateResponseDto(
26+
user.getId(),
27+
user.getNickname(),
28+
profile.getProfileImage()
29+
);
30+
}
31+
32+
public static IntroUpdateResponseDto toIntroResponseDto(Profile profile, User user) {
33+
return new IntroUpdateResponseDto(
34+
user.getId(),
35+
user.getNickname(),
36+
profile.getIntro()
37+
);
38+
}
39+
2240
public static Profile toDefaultEntity(User user) {
2341
return Profile.builder()
2442
.user(user)

src/main/java/com/threestar/trainus/domain/profile/service/ProfileFacadeService.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
import com.threestar.trainus.domain.metadata.dto.ProfileMetadataResponseDto;
77
import com.threestar.trainus.domain.metadata.service.ProfileMetadataService;
8+
import com.threestar.trainus.domain.profile.dto.IntroUpdateRequestDto;
89
import com.threestar.trainus.domain.profile.dto.ProfileDetailResponseDto;
10+
import com.threestar.trainus.domain.profile.dto.ImageUpdateResponseDto;
11+
import com.threestar.trainus.domain.profile.dto.ImageUpdateRequestDto;
12+
import com.threestar.trainus.domain.profile.dto.IntroUpdateResponseDto;
913
import com.threestar.trainus.domain.profile.dto.ProfileResponseDto;
10-
import com.threestar.trainus.domain.profile.dto.ProfileUpdateRequestDto;
1114
import com.threestar.trainus.domain.profile.mapper.ProfileDetailMapper;
1215
import com.threestar.trainus.domain.user.entity.User;
1316

@@ -31,8 +34,13 @@ public ProfileDetailResponseDto getProfileDetail(Long userId) {
3134

3235
//프로필 수정
3336
@Transactional
34-
public ProfileResponseDto updateProfile(Long userId, ProfileUpdateRequestDto requestDto) {
35-
return profileService.updateProfile(userId, requestDto);
37+
public ImageUpdateResponseDto updateProfileImage(Long userId, ImageUpdateRequestDto requestDto) {
38+
return profileService.updateProfileImage(userId, requestDto);
39+
}
40+
41+
@Transactional
42+
public IntroUpdateResponseDto updateProfileIntro(Long userId, IntroUpdateRequestDto requestDto) {
43+
return profileService.updateProfileIntro(userId, requestDto);
3644
}
3745

3846
//회원가입 시 프로필,메타데이터 디폴트로 생성.

src/main/java/com/threestar/trainus/domain/profile/service/ProfileService.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import org.springframework.stereotype.Service;
44
import org.springframework.transaction.annotation.Transactional;
55

6+
import com.threestar.trainus.domain.profile.dto.IntroUpdateRequestDto;
7+
import com.threestar.trainus.domain.profile.dto.ImageUpdateResponseDto;
8+
import com.threestar.trainus.domain.profile.dto.ImageUpdateRequestDto;
9+
import com.threestar.trainus.domain.profile.dto.IntroUpdateResponseDto;
610
import com.threestar.trainus.domain.profile.dto.ProfileResponseDto;
7-
import com.threestar.trainus.domain.profile.dto.ProfileUpdateRequestDto;
811
import com.threestar.trainus.domain.profile.entity.Profile;
912
import com.threestar.trainus.domain.profile.mapper.ProfileMapper;
1013
import com.threestar.trainus.domain.profile.repository.ProfileRepository;
@@ -39,15 +42,28 @@ public ProfileResponseDto getProfile(Long userId) {
3942
}
4043

4144
@Transactional
42-
public ProfileResponseDto updateProfile(Long userId, ProfileUpdateRequestDto requestDto) {
45+
public ImageUpdateResponseDto updateProfileImage(Long userId, ImageUpdateRequestDto requestDto) {
4346
User user = userRepository.findById(userId)
4447
.orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND));
4548

4649
Profile profile = findByUserId(userId);
4750

48-
profile.updateProfile(requestDto.profileImage(), requestDto.intro());
51+
profile.updateProfileImage(requestDto.profileImage());
4952

50-
return ProfileMapper.toResponseDto(profile, user);
53+
return ProfileMapper.toImageResponseDto(profile, user);
54+
}
55+
56+
@Transactional
57+
public IntroUpdateResponseDto updateProfileIntro(Long userId, IntroUpdateRequestDto requestDto) {
58+
User user = userRepository.findById(userId)
59+
.orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND));
60+
61+
Profile profile = profileRepository.findByUserId(userId)
62+
.orElseThrow(() -> new BusinessException(ErrorCode.PROFILE_NOT_FOUND));
63+
64+
profile.updateProfileIntro(requestDto.intro());
65+
66+
return ProfileMapper.toIntroResponseDto(profile, user);
5167
}
5268

5369
public Profile findByUserId(Long userId) {

src/main/java/com/threestar/trainus/domain/user/controller/UserController.java

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

33
import org.springframework.http.HttpStatus;
44
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.PatchMapping;
56
import org.springframework.web.bind.annotation.PostMapping;
67
import org.springframework.web.bind.annotation.RequestBody;
78
import org.springframework.web.bind.annotation.RequestMapping;
@@ -13,10 +14,12 @@
1314
import com.threestar.trainus.domain.user.dto.LoginRequestDto;
1415
import com.threestar.trainus.domain.user.dto.LoginResponseDto;
1516
import com.threestar.trainus.domain.user.dto.NicknameCheckRequestDto;
17+
import com.threestar.trainus.domain.user.dto.PasswordUpdateDto;
1618
import com.threestar.trainus.domain.user.dto.SignupRequestDto;
1719
import com.threestar.trainus.domain.user.dto.SignupResponseDto;
1820
import com.threestar.trainus.domain.user.service.EmailVerificationService;
1921
import com.threestar.trainus.domain.user.service.UserService;
22+
import com.threestar.trainus.global.annotation.LoginUser;
2023
import com.threestar.trainus.global.unit.BaseResponse;
2124

2225
import io.swagger.v3.oas.annotations.Operation;
@@ -87,4 +90,14 @@ public ResponseEntity<BaseResponse<Void>> confirmVerificationCode(
8790
emailVerificationService.verifyCode(request.email(), request.verificationCode());
8891
return BaseResponse.ok("이메일 인증이 완료되었습니다.", null, HttpStatus.OK);
8992
}
93+
94+
@PatchMapping("/password")
95+
@Operation(summary = "비밀번호 변경 api")
96+
public ResponseEntity<BaseResponse<Void>> updatePassword(
97+
@Valid @RequestBody PasswordUpdateDto request,
98+
@LoginUser Long loginUserId
99+
) {
100+
userService.updatePassword(request, loginUserId);
101+
return BaseResponse.ok("비밀번호 변경이 완료되었습니다.", null, HttpStatus.OK);
102+
}
90103
}

0 commit comments

Comments
 (0)