-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] 유저 프로필(기본정보) 수정 #340
Merged
+333
−6
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
660d775
feat(basicInfo): 사용자 기본 정보 요청 DTO 추가
m-a-king 5f980bc
feat(domain): 공통 속성 및 엔티티별 업데이트 메서드 추가
m-a-king 1d765fc
test(user): 기본 정보 업데이트 로직 테스트 추가
m-a-king 4224f40
refactor(controller): 메서드명 올바르게 수정, 괄호 위치 수정
m-a-king 469884f
feat(user): 사용자 기본 정보 업데이트 기능 추가
m-a-king 3053a66
refactor(basicInfo): 역할 ID 인자를 제거하여 메소드 시그니처 개선
m-a-king eccd9ed
feat(basicInfo): 유저 기본 정보 업데이트 API 추가
m-a-king 7696cb9
refactor(controller): 기존 PostMapping을 PutMapping으로 변경
m-a-king ce40522
test(user): 사용자 기본 정보 업데이트 서비스 테스트 추가
m-a-king 45e5d24
refactor(user): 불필요한 주석 삭제
m-a-king 8efcbb3
refactor: 불필요한 어노테이션, 오타 수정
m-a-king File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/com/somemore/user/controller/UserCommandController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.somemore.user.controller; | ||
|
||
import com.somemore.global.auth.annotation.UserId; | ||
import com.somemore.global.common.response.ApiResponse; | ||
import com.somemore.user.dto.basicinfo.CenterBasicInfoRequestDto; | ||
import com.somemore.user.dto.basicinfo.VolunteerBasicInfoRequestDto; | ||
import com.somemore.user.usecase.UpdateBasicInfoUseCase; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.access.annotation.Secured; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.UUID; | ||
|
||
@Tag(name = "User Command API", description = "유저 생성 수정 삭제 관련 API") | ||
@RestController | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/user") | ||
public class UserCommandController { | ||
|
||
private final UpdateBasicInfoUseCase updateBasicInfoUseCase; | ||
|
||
@Secured("ROLE_VOLUNTEER") | ||
@PutMapping("/basic-info/volunteer") | ||
@Operation(summary = "봉사자 기본 정보 업데이트", description = "봉사자의 기본 정보를 업데이트합니다.") | ||
public ApiResponse<String> registerBasicInfo( | ||
@UserId UUID userId, | ||
@RequestBody VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto | ||
) { | ||
updateBasicInfoUseCase.update(userId, volunteerBasicInfoRequestDto); | ||
return ApiResponse.ok("봉사자 기본 정보 업데이트 완료"); | ||
} | ||
|
||
@Secured("ROLE_CENTER") | ||
@PutMapping("/basic-info/center") | ||
@Operation(summary = "센터 기본 정보 업데이트", description = "센터의 기본 정보를 업데이트합니다.") | ||
public ApiResponse<String> registerBasicInfo( | ||
@UserId UUID userId, | ||
@RequestBody CenterBasicInfoRequestDto centerBasicInfoRequestDto | ||
) { | ||
updateBasicInfoUseCase.update(userId, centerBasicInfoRequestDto); | ||
return ApiResponse.ok("센터 기본 정보 업데이틍 완료"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 업데이'틍' 이라고 되어있습니다... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니다 ㅋㅋㅋㅋ |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/somemore/user/dto/basicinfo/CenterBasicInfoRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.somemore.user.dto.basicinfo; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public record CenterBasicInfoRequestDto( | ||
@Schema(description = "공통 기본 정보") | ||
@NotBlank(message = "공통 기본 정보는 필수 값입니다.") | ||
CommonBasicInfoRequestDto commonBasicInfo, | ||
|
||
@Schema(description = "홈페이지 링크") | ||
@NotBlank(message = "홈페이지 링크는 필수 값입니다.") | ||
String homepageUrl | ||
) { | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/somemore/user/dto/basicinfo/CommonBasicInfoRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.somemore.user.dto.basicinfo; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public record CommonBasicInfoRequestDto( | ||
@Schema(description = "이름", example = "홍길동, 롯데리아") | ||
@NotBlank(message = "이름은 필수 값입니다.") | ||
String name, | ||
|
||
@Schema(description = "연락처", example = "010-1234-5678, 02-123-4567") | ||
@NotBlank(message = "연락처는 필수 값입니다.") | ||
String contactNumber, | ||
|
||
@Schema(description = "이미지 링크", example = "https://image.image") | ||
@NotBlank(message = "이미지 링크는 필수 값입니다.") | ||
String imgUrl, | ||
|
||
@Schema(description = "소개 글", example = "햄부기햄북햄북어햄북스딱스함부르크햄부가우가햄비기햄부거햄부가티햄부기온앤온을 차려오거라") | ||
@NotBlank(message = "소개 글은 필수 값입니다.") | ||
String introduce | ||
) { | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/somemore/user/dto/basicinfo/VolunteerBasicInfoRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.somemore.user.dto.basicinfo; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
public record VolunteerBasicInfoRequestDto( | ||
@Schema(description = "공통 기본 정보") | ||
@NotBlank(message = "공통 기본 정보는 필수 값입니다.") | ||
CommonBasicInfoRequestDto commonBasicInfo, | ||
|
||
@Schema(description = "닉네임", example = "칠가이") | ||
@NotBlank(message = "닉네임은 필수 값입니다.") | ||
String nickname, | ||
|
||
@Schema(description = "성별", example = "MALE", allowableValues = {"MALE", "FEMALE"}) | ||
@NotBlank(message = "성별은 필수 값입니다.") | ||
String gender | ||
) { | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/somemore/user/service/UpdateBasicInfoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.somemore.user.service; | ||
|
||
import com.somemore.center.domain.NEWCenter; | ||
import com.somemore.center.usecase.NEWCenterQueryUseCase; | ||
import com.somemore.domains.volunteer.domain.Gender; | ||
import com.somemore.user.domain.UserCommonAttribute; | ||
import com.somemore.user.dto.basicinfo.CenterBasicInfoRequestDto; | ||
import com.somemore.user.dto.basicinfo.CommonBasicInfoRequestDto; | ||
import com.somemore.user.dto.basicinfo.VolunteerBasicInfoRequestDto; | ||
import com.somemore.user.usecase.UpdateBasicInfoUseCase; | ||
import com.somemore.user.usecase.UserQueryUseCase; | ||
import com.somemore.volunteer.domain.NEWVolunteer; | ||
import com.somemore.volunteer.usecase.NEWVolunteerQueryUseCase; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
@Transactional | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class UpdateBasicInfoService implements UpdateBasicInfoUseCase { | ||
|
||
private final UserQueryUseCase userQueryUseCase; | ||
private final NEWVolunteerQueryUseCase volunteerQueryUseCase; | ||
private final NEWCenterQueryUseCase centerQueryUseCase; | ||
|
||
@Override | ||
public void update(UUID userId, VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto) { | ||
updateCommonAttribute(userId, volunteerBasicInfoRequestDto.commonBasicInfo()); | ||
updateVolunteerAttribute(userId, volunteerBasicInfoRequestDto); | ||
} | ||
|
||
@Override | ||
public void update(UUID userId, CenterBasicInfoRequestDto centerBasicInfoRequestDto) { | ||
updateCommonAttribute(userId, centerBasicInfoRequestDto.commonBasicInfo()); | ||
updateCenterAttribute(userId, centerBasicInfoRequestDto); | ||
} | ||
|
||
private void updateCommonAttribute(UUID userId, CommonBasicInfoRequestDto commonBasicInfoRequestDto) { | ||
UserCommonAttribute commonAttribute = userQueryUseCase.getCommonAttributeByUserId(userId); | ||
commonAttribute.update(commonBasicInfoRequestDto); | ||
} | ||
|
||
private void updateVolunteerAttribute(UUID userId, VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto) { | ||
NEWVolunteer volunteer = volunteerQueryUseCase.getByUserId(userId); | ||
volunteer.update(volunteerBasicInfoRequestDto.nickname()); | ||
volunteer.update(Gender.from(volunteerBasicInfoRequestDto.gender())); | ||
} | ||
|
||
private void updateCenterAttribute(UUID userId, CenterBasicInfoRequestDto centerBasicInfoRequestDto) { | ||
NEWCenter center = centerQueryUseCase.getByUserId(userId); | ||
center.update(centerBasicInfoRequestDto.homepageUrl()); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/somemore/user/usecase/UpdateBasicInfoUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.somemore.user.usecase; | ||
|
||
import com.somemore.user.dto.basicinfo.CenterBasicInfoRequestDto; | ||
import com.somemore.user.dto.basicinfo.VolunteerBasicInfoRequestDto; | ||
|
||
import java.util.UUID; | ||
|
||
public interface UpdateBasicInfoUseCase { | ||
|
||
void update(UUID userId, VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto); | ||
|
||
void update(UUID userId, CenterBasicInfoRequestDto centerBasicInfoRequestDto); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/test/java/com/somemore/user/service/UpdateBasicInfoServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.somemore.user.service; | ||
|
||
import com.somemore.center.domain.NEWCenter; | ||
import com.somemore.center.repository.NEWCenterRepository; | ||
import com.somemore.support.IntegrationTestSupport; | ||
import com.somemore.user.domain.User; | ||
import com.somemore.user.domain.UserCommonAttribute; | ||
import com.somemore.user.domain.UserRole; | ||
import com.somemore.user.dto.UserAuthInfo; | ||
import com.somemore.user.dto.basicinfo.CenterBasicInfoRequestDto; | ||
import com.somemore.user.dto.basicinfo.CommonBasicInfoRequestDto; | ||
import com.somemore.user.dto.basicinfo.VolunteerBasicInfoRequestDto; | ||
import com.somemore.user.repository.user.UserRepository; | ||
import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; | ||
import com.somemore.volunteer.domain.NEWVolunteer; | ||
import com.somemore.volunteer.repository.NEWVolunteerRepository; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@Transactional | ||
class UpdateBasicInfoServiceTest extends IntegrationTestSupport { | ||
|
||
@Autowired | ||
private UpdateBasicInfoService updateBasicInfoService; | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
@Autowired | ||
private UserCommonAttributeRepository userCommonAttributeRepository; | ||
@Autowired | ||
private NEWVolunteerRepository volunteerRepository; | ||
@Autowired | ||
private NEWCenterRepository centerRepository; | ||
|
||
@Test | ||
@DisplayName("봉사자 기본 정보를 업데이트 할 수 있다.") | ||
void updateVolunteerBasicInfo() { | ||
// given | ||
UUID userId = UUID.randomUUID(); | ||
UserAuthInfo authInfo = UserAuthInfo.of("test", "test"); | ||
User user = User.of(authInfo, UserRole.VOLUNTEER); | ||
UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId, UserRole.VOLUNTEER); | ||
|
||
NEWVolunteer volunteer = NEWVolunteer.createDefault(userId); | ||
|
||
userRepository.save(user); | ||
userCommonAttributeRepository.save(userCommonAttribute); | ||
volunteerRepository.save(volunteer); | ||
|
||
CommonBasicInfoRequestDto commonBasicInfoRequestDto = createCommonBasicInfoRequestDto(); | ||
|
||
VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto = | ||
new VolunteerBasicInfoRequestDto( | ||
commonBasicInfoRequestDto, | ||
"test", | ||
"test"); | ||
|
||
boolean customizedBeforeUpdate = userCommonAttributeRepository.findIsCustomizedByUserId(userId) | ||
.orElseThrow(); | ||
|
||
// when | ||
updateBasicInfoService.update(userId, volunteerBasicInfoRequestDto); | ||
|
||
// then | ||
boolean customizedAfterUpdate = userCommonAttributeRepository.findIsCustomizedByUserId(userId) | ||
.orElseThrow(); | ||
|
||
assertThat(customizedBeforeUpdate).isFalse(); | ||
assertThat(customizedAfterUpdate).isTrue(); | ||
} | ||
|
||
@Test | ||
@DisplayName("센터 기본 정보를 업데이트 할 수 있다.") | ||
void updateCenterBasicInfo() { | ||
// given | ||
UUID userId = UUID.randomUUID(); | ||
UserAuthInfo authInfo = UserAuthInfo.of("centerTest", "centerTest"); | ||
User user = User.of(authInfo, UserRole.CENTER); | ||
UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId, UserRole.CENTER); | ||
|
||
NEWCenter center = NEWCenter.createDefault(userId); | ||
|
||
userRepository.save(user); | ||
userCommonAttributeRepository.save(userCommonAttribute); | ||
centerRepository.save(center); | ||
|
||
CommonBasicInfoRequestDto commonBasicInfoRequestDto = createCommonBasicInfoRequestDto(); | ||
|
||
CenterBasicInfoRequestDto centerBasicInfoRequestDto = | ||
new CenterBasicInfoRequestDto( | ||
commonBasicInfoRequestDto, | ||
"Main Center" | ||
); | ||
|
||
boolean customizedBeforeUpdate = userCommonAttributeRepository.findIsCustomizedByUserId(userId) | ||
.orElseThrow(); | ||
|
||
// when | ||
updateBasicInfoService.update(userId, centerBasicInfoRequestDto); | ||
|
||
// then | ||
boolean customizedAfterUpdate = userCommonAttributeRepository.findIsCustomizedByUserId(userId) | ||
.orElseThrow(); | ||
|
||
assertThat(customizedBeforeUpdate).isFalse(); | ||
assertThat(customizedAfterUpdate).isTrue(); | ||
} | ||
|
||
private static CommonBasicInfoRequestDto createCommonBasicInfoRequestDto() { | ||
return new CommonBasicInfoRequestDto( | ||
"test", | ||
"test", | ||
"test", | ||
"test" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어노테이션 제거하셔도 될 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵! 감사합니다