Skip to content

Commit 64de72a

Browse files
authored
Merge branch 'main' into feature/#73-edit-profile-image
2 parents 5a34020 + c454d52 commit 64de72a

File tree

6 files changed

+116
-3
lines changed

6 files changed

+116
-3
lines changed

src/main/java/com/ajou/hertz/domain/user/controller/UserController.java

+18
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.ajou.hertz.common.validator.PhoneNumber;
2222
import com.ajou.hertz.domain.user.dto.UserDto;
2323
import com.ajou.hertz.domain.user.dto.request.SignUpRequest;
24+
import com.ajou.hertz.domain.user.dto.request.UpdateContactLinkRequest;
2425
import com.ajou.hertz.domain.user.dto.response.UserEmailResponse;
2526
import com.ajou.hertz.domain.user.dto.response.UserExistenceResponse;
2627
import com.ajou.hertz.domain.user.dto.response.UserResponse;
@@ -136,3 +137,20 @@ public UserResponse updateProfileImageUrlV1(
136137
return UserResponse.from(userUpdated);
137138
}
138139
}
140+
141+
@Operation(
142+
summary = "연락 수단 변경",
143+
description = "연락 수단을 변경합니다.",
144+
security = @SecurityRequirement(name = "access-token")
145+
)
146+
@PutMapping(value = "/me/contact-link", headers = API_VERSION_HEADER_NAME + "=" + 1)
147+
public UserResponse updateContactLinkV1(
148+
@RequestBody @Valid UpdateContactLinkRequest updateContactLinkRequest,
149+
@AuthenticationPrincipal UserPrincipal userPrincipal
150+
) {
151+
UserDto userUpdated = userCommandService.updateContactLink(userPrincipal.getUserId(),
152+
updateContactLinkRequest.getContactLink());
153+
return UserResponse.from(userUpdated);
154+
}
155+
}
156+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.ajou.hertz.domain.user.dto.request;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
import jakarta.validation.constraints.NotBlank;
5+
import lombok.AccessLevel;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Getter;
8+
import lombok.NoArgsConstructor;
9+
10+
@AllArgsConstructor(access = AccessLevel.PRIVATE)
11+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
12+
@Getter
13+
public class UpdateContactLinkRequest {
14+
15+
@Schema(description = "연락 수단", example = "https://new-contack-link")
16+
@NotBlank
17+
private String contactLink;
18+
19+
}

src/main/java/com/ajou/hertz/domain/user/entity/User.java

+4
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,16 @@ public static User create(
101101
);
102102
}
103103

104+
104105
public void changeProfileImageUrl(String profileImageUrl) {
105106
this.profileImageUrl = profileImageUrl;
106107
}
107108

108109
public UserProfileImage getProfileImage() {
109110
return UserProfileImage.of(profileImageUrl);
111+
112+
public void changeContactLink(String contactLink) {
113+
this.contactLink = contactLink;
110114
}
111115

112116
}

src/main/java/com/ajou/hertz/domain/user/service/UserCommandService.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ private String generateRandom16CharString() {
137137
/**
138138
* 유저의 프로필 이미지를 업데이트한다.
139139
*
140-
* @param userId 유저 id
140+
* @param userId 유저 id
141141
* @param newProfileImage 새로운 프로필 이미지
142+
*
142143
* @return 업데이트된 유저 정보
143144
*/
144145
public UserDto updateProfileImageUrl(Long userId, MultipartFile newProfileImage) {
@@ -155,6 +156,20 @@ public UserDto updateProfileImageUrl(Long userId, MultipartFile newProfileImage)
155156
fileService.deleteFile(fullPathToDelete);
156157

157158
user.changeProfileImageUrl(newProfileImageUrl);
159+
return UserDto.from(user);
160+
}
161+
162+
/**
163+
*연락 수단을 변경합니다.
164+
*
165+
* @param userId 유저의 ID
166+
* @param contactLink 변경할 연락 수단
167+
*
168+
*@return 변경된 유저 정보
169+
*/
170+
public UserDto updateContactLink(Long userId, String contactLink) {
171+
User user = userQueryService.getById(userId);
172+
user.changeContactLink(contactLink);
158173
return UserDto.from(user);
159174
}
160175

src/test/java/com/ajou/hertz/unit/domain/user/controller/UserControllerTest.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,29 @@ public void securitySetUp() throws Exception {
241241
.andExpect(status().isOk())
242242
.andExpect(jsonPath("$.profileImageUrl").value(expectedResult.getProfileImageUrl()));
243243
then(userCommandService).should().updateProfileImageUrl(userId, profileImage);
244+
verifyEveryMocksShouldHaveNoMoreInteractions();
245+
}
246+
247+
248+
void 주어진_연락수단을_새로운_연락수단으로_변경한다() throws Exception {
249+
// given
250+
long userId = 1L;
251+
String newContactLink = "https://new-contact-link.com";
252+
UserDto expectedResult = createUserDto(userId);
253+
UserDetails testUser = createTestUser(userId);
254+
given(userCommandService.updateContactLink(userId, newContactLink)).willReturn(expectedResult);
255+
256+
// when & then
257+
mvc.perform(
258+
put("/api/users/me/contact-link")
259+
.header(API_VERSION_HEADER_NAME, 1)
260+
.contentType(MediaType.APPLICATION_JSON)
261+
.content(objectMapper.writeValueAsString(newContactLink))
262+
.with(user(testUser))
263+
)
264+
.andExpect(status().isOk())
265+
.andExpect(jsonPath("$.contactLink").value(expectedResult.getContactLink()));
266+
then(userCommandService).should().updateContactLink(userId, newContactLink);
244267
verifyEveryMocksShouldHaveNoMoreInteractions();
245268
}
246269

@@ -278,7 +301,7 @@ private UserDto createUserDto(long id) throws Exception {
278301
LocalDate.of(2024, 1, 1),
279302
Gender.ETC,
280303
"01012345678",
281-
"https://contack-link",
304+
"https://contact-link",
282305
LocalDateTime.of(2024, 1, 1, 0, 0)
283306
);
284307
}
@@ -290,4 +313,5 @@ private UserDto createUserDto() throws Exception {
290313
private UserDetails createTestUser(Long userId) throws Exception {
291314
return new UserPrincipal(createUserDto(userId));
292315
}
316+
293317
}

src/test/java/com/ajou/hertz/unit/domain/user/service/UserCommandServiceTest.java

+34-1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,39 @@ static Stream<Arguments> testDataForCreateNewUserWithKakao() throws Exception {
218218

219219
// when
220220
Throwable t = catchThrowable(() -> sut.updateProfileImageUrl(userId, newProfileImage));
221+
222+
// then
223+
then(userQueryService).should().getById(userId);
224+
verifyEveryMocksShouldHaveNoMoreInteractions();
225+
assertThat(t).isInstanceOf(UserNotFoundByIdException.class);
226+
}
227+
228+
229+
void 주어진_유저_ID와_연락_수단으로_연락_수단을_변경한다() throws Exception {
230+
// given
231+
Long userId = 1L;
232+
String contactLink = "https://new-contactLink";
233+
User user = createUser(userId, "$2a$abc123", "12345");
234+
given(userQueryService.getById(userId)).willReturn(user);
235+
236+
// when
237+
UserDto updatedUserDto = sut.updateContactLink(userId, contactLink);
238+
239+
// then
240+
then(userQueryService).should().getById(userId);
241+
verifyEveryMocksShouldHaveNoMoreInteractions();
242+
assertThat(updatedUserDto.getContactLink()).isEqualTo(contactLink);
243+
}
244+
245+
@Test
246+
void 주어진_유저_ID와_연락_수단으로_연락_수단을_변경한다_존재하지_않는_유저라면_예외가_발생한다() throws Exception {
247+
// given
248+
Long userId = 1L;
249+
String contactLink = "https://new-contactLink";
250+
given(userQueryService.getById(userId)).willThrow(UserNotFoundByIdException.class);
251+
252+
// when
253+
Throwable t = catchThrowable(() -> sut.updateContactLink(userId, contactLink));
221254

222255
// then
223256
then(userQueryService).should().getById(userId);
@@ -243,7 +276,7 @@ private static User createUser(Long id, String password, String kakaoUid, Gender
243276
LocalDate.of(2024, 1, 1),
244277
gender,
245278
"010-1234-5678",
246-
null
279+
"https://contactLink"
247280
);
248281
}
249282

0 commit comments

Comments
 (0)