Skip to content

Commit cf65d48

Browse files
committed
refactor: long id를 받도록 MyPageController 수정
1 parent de13fed commit cf65d48

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

src/main/java/com/example/solidconnection/siteuser/controller/MyPageController.java

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

33

44
import com.example.solidconnection.common.resolver.AuthorizedUser;
5-
import com.example.solidconnection.siteuser.domain.SiteUser;
65
import com.example.solidconnection.siteuser.dto.MyPageResponse;
76
import com.example.solidconnection.siteuser.service.MyPageService;
87
import lombok.RequiredArgsConstructor;
@@ -23,19 +22,19 @@ class MyPageController {
2322

2423
@GetMapping
2524
public ResponseEntity<MyPageResponse> getMyPageInfo(
26-
@AuthorizedUser SiteUser siteUser
25+
@AuthorizedUser long siteUserId
2726
) {
28-
MyPageResponse myPageResponse = myPageService.getMyPageInfo(siteUser);
27+
MyPageResponse myPageResponse = myPageService.getMyPageInfo(siteUserId);
2928
return ResponseEntity.ok(myPageResponse);
3029
}
3130

3231
@PatchMapping
3332
public ResponseEntity<Void> updateMyPageInfo(
34-
@AuthorizedUser SiteUser siteUser,
33+
@AuthorizedUser long siteUserId,
3534
@RequestParam(value = "file", required = false) MultipartFile imageFile,
3635
@RequestParam(value = "nickname", required = false) String nickname
3736
) {
38-
myPageService.updateMyPageInfo(siteUser, imageFile, nickname);
37+
myPageService.updateMyPageInfo(siteUserId, imageFile, nickname);
3938
return ResponseEntity.ok().build();
4039
}
4140
}

src/main/java/com/example/solidconnection/siteuser/service/MyPageService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ public class MyPageService {
3434
* 마이페이지 정보를 조회한다.
3535
* */
3636
@Transactional(readOnly = true)
37-
public MyPageResponse getMyPageInfo(SiteUser siteUser) {
37+
public MyPageResponse getMyPageInfo(long siteUserId) {
38+
SiteUser siteUser = siteUserRepository.findById(siteUserId)
39+
.orElseThrow(() -> new CustomException(USER_NOT_FOUND));
3840
int likedUnivApplyInfoCount = likedUnivApplyInfoRepository.countBySiteUserId(siteUser.getId());
3941
return MyPageResponse.of(siteUser, likedUnivApplyInfoCount);
4042
}
@@ -43,8 +45,8 @@ public MyPageResponse getMyPageInfo(SiteUser siteUser) {
4345
* 마이페이지 정보를 수정한다.
4446
* */
4547
@Transactional
46-
public void updateMyPageInfo(SiteUser siteUser, MultipartFile imageFile, String nickname) {
47-
SiteUser user = siteUserRepository.findById(siteUser.getId())
48+
public void updateMyPageInfo(long siteUserId, MultipartFile imageFile, String nickname) {
49+
SiteUser user = siteUserRepository.findById(siteUserId)
4850
.orElseThrow(() -> new CustomException(USER_NOT_FOUND));
4951

5052
if (nickname != null) {

src/test/java/com/example/solidconnection/siteuser/service/MyPageServiceTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static com.example.solidconnection.siteuser.service.MyPageService.NICKNAME_LAST_CHANGE_DATE_FORMAT;
66
import static org.assertj.core.api.Assertions.assertThat;
77
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
8-
import static org.mockito.ArgumentMatchers.argThat;
98
import static org.mockito.BDDMockito.any;
109
import static org.mockito.BDDMockito.eq;
1110
import static org.mockito.BDDMockito.given;
@@ -75,7 +74,7 @@ void setUp() {
7574
int likedUnivApplyInfoCount = createLikedUnivApplyInfos(user);
7675

7776
// when
78-
MyPageResponse response = myPageService.getMyPageInfo(user);
77+
MyPageResponse response = myPageService.getMyPageInfo(user.getId());
7978

8079
// then
8180
Assertions.assertAll(
@@ -101,7 +100,7 @@ class 프로필_이미지_수정_테스트 {
101100
.willReturn(new UploadedFileUrlResponse(expectedUrl));
102101

103102
// when
104-
myPageService.updateMyPageInfo(user, imageFile, "newNickname");
103+
myPageService.updateMyPageInfo(user.getId(), imageFile, "newNickname");
105104

106105
// then
107106
SiteUser updatedUser = siteUserRepository.findById(user.getId()).get();
@@ -116,10 +115,10 @@ class 프로필_이미지_수정_테스트 {
116115
.willReturn(new UploadedFileUrlResponse("newProfileImageUrl"));
117116

118117
// when
119-
myPageService.updateMyPageInfo(user, imageFile, "newNickname");
118+
myPageService.updateMyPageInfo(user.getId(), imageFile, "newNickname");
120119

121120
// then
122-
then(s3Service).should(never()).deleteExProfile(any());
121+
then(s3Service).should(never()).deleteExProfile(user.getId());
123122
}
124123

125124
@Test
@@ -131,10 +130,10 @@ class 프로필_이미지_수정_테스트 {
131130
.willReturn(new UploadedFileUrlResponse("newProfileImageUrl"));
132131

133132
// when
134-
myPageService.updateMyPageInfo(커스텀_프로필_사용자, imageFile, "newNickname");
133+
myPageService.updateMyPageInfo(커스텀_프로필_사용자.getId(), imageFile, "newNickname");
135134

136135
// then
137-
then(s3Service).should().deleteExProfile(argThat(userId -> userId.equals(커스텀_프로필_사용자.getId())));
136+
then(s3Service).should().deleteExProfile(커스텀_프로필_사용자.getId());
138137
}
139138
}
140139

@@ -154,7 +153,7 @@ void setUp() {
154153
String newNickname = "newNickname";
155154

156155
// when
157-
myPageService.updateMyPageInfo(user, imageFile, newNickname);
156+
myPageService.updateMyPageInfo(user.getId(), imageFile, newNickname);
158157

159158
// then
160159
SiteUser updatedUser = siteUserRepository.findById(user.getId()).get();
@@ -171,7 +170,7 @@ void setUp() {
171170
siteUserRepository.save(user);
172171

173172
// when & then
174-
assertThatCode(() -> myPageService.updateMyPageInfo(user, imageFile, "nickname12"))
173+
assertThatCode(() -> myPageService.updateMyPageInfo(user.getId(), imageFile, "nickname12"))
175174
.isInstanceOf(CustomException.class)
176175
.hasMessage(createExpectedErrorMessage(modifiedAt));
177176
}

0 commit comments

Comments
 (0)