Skip to content

Commit 78b728f

Browse files
Merge pull request #501 from Podo-Store/develop
refactor: 회원정보 수정
2 parents b8840c1 + a94e66e commit 78b728f

File tree

6 files changed

+143
-18
lines changed

6 files changed

+143
-18
lines changed

src/main/java/PodoeMarket/podoemarket/profile/controller/MypageController.java

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ public ResponseEntity<?> getNickname(@AuthenticationPrincipal UserEntity userInf
3838
}
3939
}
4040

41+
@GetMapping("/account")
42+
public ResponseEntity<?> account(@AuthenticationPrincipal UserEntity userInfo){
43+
try {
44+
final ProfileInfoResponseDTO profile = mypageService.getProfileInfo(userInfo.getId());
45+
46+
return ResponseEntity.ok().body(profile);
47+
}catch(Exception e) {
48+
ResponseDTO resDTO = ResponseDTO.builder().error(e.getMessage()).build();
49+
return ResponseEntity.badRequest().body(resDTO);
50+
}
51+
}
52+
4153
@PostMapping("/confirm")
4254
public ResponseEntity<?> confirmPassword(@AuthenticationPrincipal UserEntity userInfo, @RequestBody EnterCheckRequestDTO dto){
4355
try{
@@ -56,18 +68,6 @@ public ResponseEntity<?> confirmPassword(@AuthenticationPrincipal UserEntity use
5668
}
5769
}
5870

59-
@GetMapping("/account")
60-
public ResponseEntity<?> account(@AuthenticationPrincipal UserEntity userInfo){
61-
try {
62-
final ProfileInfoResponseDTO profile = mypageService.getProfileInfo(userInfo.getId());
63-
64-
return ResponseEntity.ok().body(profile);
65-
}catch(Exception e) {
66-
ResponseDTO resDTO = ResponseDTO.builder().error(e.getMessage()).build();
67-
return ResponseEntity.badRequest().body(resDTO);
68-
}
69-
}
70-
7171
@PostMapping("/equalPw")
7272
public ResponseEntity<?> equalPassword(@RequestBody PwCheckRequestDTO dto) {
7373
if(!dto.getPassword().equals(dto.getConfirmPassword())){
@@ -100,6 +100,7 @@ public ResponseEntity<?> checkNickname(@AuthenticationPrincipal UserEntity userI
100100
@PostMapping("/update")
101101
public ResponseEntity<?> updateAccount(@AuthenticationPrincipal UserEntity userInfo, @RequestBody ProfileUpdateRequestDTO dto) {
102102
try{
103+
// 삭제 예정
103104
UserInfoResponseDTO resUserDTO = mypageService.updateUserAccount(userInfo, dto);
104105

105106
return ResponseEntity.ok().body(resUserDTO);
@@ -109,6 +110,30 @@ public ResponseEntity<?> updateAccount(@AuthenticationPrincipal UserEntity userI
109110
}
110111
}
111112

113+
@PatchMapping("/updatePassword")
114+
public ResponseEntity<?> updatePassword(@AuthenticationPrincipal UserEntity userInfo, @RequestBody PasswordUpdateRequestDTO dto) {
115+
try{
116+
mypageService.updatePassword(userInfo, dto);
117+
118+
return ResponseEntity.ok().body(true);
119+
} catch(Exception e) {
120+
ResponseDTO resDTO = ResponseDTO.builder().error(e.getMessage()).build();
121+
return ResponseEntity.badRequest().body(resDTO);
122+
}
123+
}
124+
125+
@PatchMapping("/updateNickname")
126+
public ResponseEntity<?> updateNickname(@AuthenticationPrincipal UserEntity userInfo, @RequestBody NicknameUpdateRequestDTO dto) {
127+
try{
128+
NicknameUpdateResponseDTO resDTO = mypageService.updateNickname(userInfo, dto);
129+
130+
return ResponseEntity.ok().body(resDTO);
131+
} catch(Exception e) {
132+
ResponseDTO resDTO = ResponseDTO.builder().error(e.getMessage()).build();
133+
return ResponseEntity.badRequest().body(resDTO);
134+
}
135+
}
136+
112137
@DeleteMapping("/deleteScript/{id}")
113138
public ResponseEntity<?> deleteScript(@AuthenticationPrincipal UserEntity userInfo, @PathVariable UUID id) {
114139
try {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package PodoeMarket.podoemarket.profile.dto.request;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@Builder
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class NicknameUpdateRequestDTO {
13+
private String nickname;
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package PodoeMarket.podoemarket.profile.dto.request;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@Builder
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class PasswordUpdateRequestDTO {
13+
private String password;
14+
private String confirmPassword;
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package PodoeMarket.podoemarket.profile.dto.response;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@Builder
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class NicknameUpdateResponseDTO {
13+
private String nickname;
14+
private String accessToken;
15+
private String refreshToken;
16+
}

src/main/java/PodoeMarket/podoemarket/profile/dto/response/ProfileInfoResponseDTO.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package PodoeMarket.podoemarket.profile.dto.response;
22

3+
import PodoeMarket.podoemarket.common.entity.type.SocialLoginType;
34
import lombok.AllArgsConstructor;
45
import lombok.Builder;
56
import lombok.Data;
@@ -14,6 +15,7 @@
1415
public class ProfileInfoResponseDTO {
1516
private UUID id;
1617
private String userId;
17-
private String nickname;
1818
private String email;
19+
private SocialLoginType socialLoginType;
20+
private String nickname;
1921
}

src/main/java/PodoeMarket/podoemarket/profile/service/MypageService.java

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import PodoeMarket.podoemarket.common.repository.*;
66
import PodoeMarket.podoemarket.common.security.TokenProvider;
77
import PodoeMarket.podoemarket.common.entity.type.ProductStatus;
8-
import PodoeMarket.podoemarket.profile.dto.request.ApplyRequestDTO;
9-
import PodoeMarket.podoemarket.profile.dto.request.RefundRequestDTO;
8+
import PodoeMarket.podoemarket.profile.dto.request.*;
109
import PodoeMarket.podoemarket.profile.dto.response.RequestedPerformanceResponseDTO;
11-
import PodoeMarket.podoemarket.profile.dto.request.ProfileUpdateRequestDTO;
1210
import PodoeMarket.podoemarket.profile.dto.response.*;
1311
import PodoeMarket.podoemarket.service.ViewCountService;
1412
import com.amazonaws.services.s3.AmazonS3;
@@ -85,7 +83,7 @@ public class MypageService {
8583

8684
private final Sort sort = Sort.by(Sort.Direction.DESC, "createdAt");
8785

88-
// 사용자 계정 정보 업데이트
86+
// 사용자 계정 정보 업데이트 - 삭제 예정
8987
@Transactional
9088
public UserInfoResponseDTO updateUserAccount(UserEntity userInfo, ProfileUpdateRequestDTO dto) {
9189
try {
@@ -132,6 +130,60 @@ public UserInfoResponseDTO updateUserAccount(UserEntity userInfo, ProfileUpdateR
132130
}
133131
}
134132

133+
@Transactional
134+
public void updatePassword(UserEntity userInfo, PasswordUpdateRequestDTO dto) {
135+
try {
136+
if (dto.getPassword() == null || dto.getConfirmPassword() == null)
137+
throw new RuntimeException("비밀번호를 입력하세요.");
138+
139+
if(!dto.getPassword().isBlank() && !dto.getPassword().equals(dto.getConfirmPassword()))
140+
throw new RuntimeException("비밀번호가 일치하지 않음");
141+
142+
UserEntity user = userRepo.findById(userInfo.getId());
143+
144+
if(user == null)
145+
throw new RuntimeException("로그인이 필요한 서비스입니다.");
146+
147+
isValidPw(dto.getPassword());
148+
149+
user.setPassword(pwdEncoder.encode(dto.getPassword()));
150+
151+
userRepo.save(user);
152+
} catch (Exception e) {
153+
throw e;
154+
}
155+
}
156+
157+
@Transactional
158+
public NicknameUpdateResponseDTO updateNickname(UserEntity userInfo, NicknameUpdateRequestDTO dto) {
159+
try {
160+
UserEntity user = userRepo.findById(userInfo.getId());
161+
162+
if(user == null)
163+
throw new RuntimeException("로그인이 필요한 서비스입니다.");
164+
165+
if (!Objects.equals(user.getNickname(), dto.getNickname()) && userRepo.existsByNickname(dto.getNickname()))
166+
throw new RuntimeException("이미 사용 중인 닉네임");
167+
168+
isValidNickname(dto.getNickname());
169+
170+
user.setNickname(dto.getNickname());
171+
172+
// 모든 작품의 작가명 변경
173+
for(ProductEntity product : productRepo.findAllByUserId(userInfo.getId()))
174+
product.setWriter(user.getNickname());
175+
176+
// save() 없이 자동 저장 - Transactional 선언
177+
return NicknameUpdateResponseDTO.builder()
178+
.nickname(user.getNickname())
179+
.accessToken(tokenProvider.createAccessToken(user))
180+
.refreshToken(tokenProvider.createRefreshToken(user))
181+
.build();
182+
} catch (Exception e) {
183+
throw e;
184+
}
185+
}
186+
135187
public Boolean checkUser(final UUID id, final String password) {
136188
try{
137189
final UserEntity originalUser = userRepo.findById(id);
@@ -155,8 +207,9 @@ public ProfileInfoResponseDTO getProfileInfo(final UUID id) {
155207
return ProfileInfoResponseDTO.builder()
156208
.id(user.getId())
157209
.userId(user.getUserId())
158-
.nickname(user.getNickname())
159210
.email(user.getEmail())
211+
.socialLoginType(user.getSocialLoginType())
212+
.nickname(user.getNickname())
160213
.build();
161214
} catch (Exception e) {
162215
throw e;

0 commit comments

Comments
 (0)