From 660d775f0d67ca5287b133b9c8bd03ef45fa2c64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sat, 25 Jan 2025 20:44:37 +0900 Subject: [PATCH 01/11] =?UTF-8?q?feat(basicInfo):=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EA=B8=B0=EB=B3=B8=20=EC=A0=95=EB=B3=B4=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20DTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - VolunteerBasicInfoRequestDto 추가 - 공통 기본 정보(CommonBasicInfoRequestDto), 닉네임, 성별 필드 포함 - CenterBasicInfoRequestDto 추가 - 공통 기본 정보(CommonBasicInfoRequestDto), 홈페이지 링크 필드 포함 - CommonBasicInfoRequestDto 추가 - 이름, 연락처, 이미지 링크, 소개 글 필드 포함 --- .../basicinfo/CenterBasicInfoRequestDto.java | 19 ++++++++++++++ .../basicinfo/CommonBasicInfoRequestDto.java | 26 +++++++++++++++++++ .../VolunteerBasicInfoRequestDto.java | 22 ++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 src/main/java/com/somemore/user/dto/basicinfo/CenterBasicInfoRequestDto.java create mode 100644 src/main/java/com/somemore/user/dto/basicinfo/CommonBasicInfoRequestDto.java create mode 100644 src/main/java/com/somemore/user/dto/basicinfo/VolunteerBasicInfoRequestDto.java diff --git a/src/main/java/com/somemore/user/dto/basicinfo/CenterBasicInfoRequestDto.java b/src/main/java/com/somemore/user/dto/basicinfo/CenterBasicInfoRequestDto.java new file mode 100644 index 00000000..b003d18c --- /dev/null +++ b/src/main/java/com/somemore/user/dto/basicinfo/CenterBasicInfoRequestDto.java @@ -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 +) { + +} diff --git a/src/main/java/com/somemore/user/dto/basicinfo/CommonBasicInfoRequestDto.java b/src/main/java/com/somemore/user/dto/basicinfo/CommonBasicInfoRequestDto.java new file mode 100644 index 00000000..bf2b9869 --- /dev/null +++ b/src/main/java/com/somemore/user/dto/basicinfo/CommonBasicInfoRequestDto.java @@ -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 +) { +} diff --git a/src/main/java/com/somemore/user/dto/basicinfo/VolunteerBasicInfoRequestDto.java b/src/main/java/com/somemore/user/dto/basicinfo/VolunteerBasicInfoRequestDto.java new file mode 100644 index 00000000..a45e2e13 --- /dev/null +++ b/src/main/java/com/somemore/user/dto/basicinfo/VolunteerBasicInfoRequestDto.java @@ -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 +) { +} From 5f980bcb9726d0a161923dc045bb13152c9c86a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sat, 25 Jan 2025 20:44:56 +0900 Subject: [PATCH 02/11] =?UTF-8?q?feat(domain):=20=EA=B3=B5=ED=86=B5=20?= =?UTF-8?q?=EC=86=8D=EC=84=B1=20=EB=B0=8F=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=EB=B3=84=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - UserCommonAttribute: CommonBasicInfoRequestDto 기반 업데이트 메서드 추가 - NEWVolunteer: nickname, gender, volunteerStats 업데이트 메서드 추가 - NEWCenter: homepageUrl 업데이트 메서드 추가 --- src/main/java/com/somemore/center/domain/NEWCenter.java | 4 ++++ .../com/somemore/user/domain/UserCommonAttribute.java | 7 ++++++- .../java/com/somemore/volunteer/domain/NEWVolunteer.java | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/center/domain/NEWCenter.java b/src/main/java/com/somemore/center/domain/NEWCenter.java index 22351fa2..3720d6a2 100644 --- a/src/main/java/com/somemore/center/domain/NEWCenter.java +++ b/src/main/java/com/somemore/center/domain/NEWCenter.java @@ -43,4 +43,8 @@ public static NEWCenter createDefault(UUID userId) { .homepageUrl("") .build(); } + + public void update(String homepageUrl) { + this.homepageUrl = homepageUrl; + } } diff --git a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java index 101f8e87..f2a11ea5 100644 --- a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java +++ b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java @@ -2,6 +2,7 @@ import com.somemore.global.common.entity.BaseEntity; import com.somemore.global.imageupload.service.ImageUploadService; +import com.somemore.user.dto.basicinfo.CommonBasicInfoRequestDto; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -44,8 +45,12 @@ public class UserCommonAttribute extends BaseEntity { @Column(name = "is_customized", nullable = false) private boolean isCustomized; - public void customize() { + public void update(CommonBasicInfoRequestDto commonBasicInfoRequestDto) { // TODO param의 정보를 필드에 업데이트 + this.name = commonBasicInfoRequestDto.name(); + this.contactNumber = commonBasicInfoRequestDto.contactNumber(); + this.imgUrl = commonBasicInfoRequestDto.imgUrl(); + this.introduce = commonBasicInfoRequestDto.introduce(); this.isCustomized = true; } diff --git a/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java b/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java index 4a1445f2..7b619272 100644 --- a/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java +++ b/src/main/java/com/somemore/volunteer/domain/NEWVolunteer.java @@ -77,6 +77,14 @@ public static NEWVolunteer createDefault(UUID userId) { .build(); } + public void update(String nickname) { + this.nickname = nickname; + } + + public void update(Gender gender) { + this.gender = gender; + } + public void updateVolunteerStats(int hours, int count) { this.totalVolunteerHours += hours; this.totalVolunteerCount += count; From 1d765fcd48872b43b920f073b8f1c1ff251f04d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sat, 25 Jan 2025 20:45:16 +0900 Subject: [PATCH 03/11] =?UTF-8?q?test(user):=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CommonBasicInfoRequestDto 객체 생성 및 활용 추가 - UserCommonAttribute의 customize() 메서드를 update() 메서드로 수정 --- .../somemore/user/service/ValidateBasicInfoServiceTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java b/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java index ccae9e66..0780cf49 100644 --- a/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java +++ b/src/test/java/com/somemore/user/service/ValidateBasicInfoServiceTest.java @@ -5,6 +5,7 @@ import com.somemore.user.domain.UserCommonAttribute; import com.somemore.user.domain.UserRole; import com.somemore.user.dto.UserAuthInfo; +import com.somemore.user.dto.basicinfo.CommonBasicInfoRequestDto; import com.somemore.user.repository.user.UserRepository; import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; import org.junit.jupiter.api.BeforeEach; @@ -39,8 +40,10 @@ void setup() { @Test void isBasicInfoComplete_ReturnsTrue() { // given + CommonBasicInfoRequestDto commonBasicInfoRequestDto = + new CommonBasicInfoRequestDto("test", "test", "test", "test"); UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(user.getId(), UserRole.VOLUNTEER); - userCommonAttribute.customize(); + userCommonAttribute.update(commonBasicInfoRequestDto); userCommonAttributeRepository.save(userCommonAttribute); // when From 4224f406f0dfc5f11835e4235120368a1f70b3df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sat, 25 Jan 2025 20:46:13 +0900 Subject: [PATCH 04/11] =?UTF-8?q?refactor(controller):=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=AA=85=20=EC=98=AC=EB=B0=94=EB=A5=B4?= =?UTF-8?q?=EA=B2=8C=20=EC=88=98=EC=A0=95,=20=EA=B4=84=ED=98=B8=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/somemore/user/controller/UserQueryController.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/somemore/user/controller/UserQueryController.java b/src/main/java/com/somemore/user/controller/UserQueryController.java index fe5b2709..8d1f2998 100644 --- a/src/main/java/com/somemore/user/controller/UserQueryController.java +++ b/src/main/java/com/somemore/user/controller/UserQueryController.java @@ -35,9 +35,8 @@ public ApiResponse checkUserExists( } @GetMapping("/check/basic-info") - @Operation(summary = "유저 기본 정보 입력 상태 확인", description = "현재 유저의 필수 입력 정보가 모두 완료되었는지 확인합니다." - ) - public ApiResponse checkUserExists( + @Operation(summary = "유저 기본 정보 입력 상태 확인", description = "현재 유저의 필수 입력 정보가 모두 완료되었는지 확인합니다.") + public ApiResponse checkBasicInfo( @UserId UUID userId ) { boolean isBasicInfoComplete = validateBasicInfoUseCase.isBasicInfoComplete(userId); From 469884f8c3dae612917c99a8b033db369eb9f4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sat, 25 Jan 2025 20:46:38 +0900 Subject: [PATCH 05/11] =?UTF-8?q?feat(user):=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=20=EA=B8=B0=EB=B3=B8=20=EC=A0=95=EB=B3=B4=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - UpdateBasicInfoUseCase 인터페이스 정의 - UpdateBasicInfoService 구현 - 사용자 공통 속성 업데이트 로직 추가 - 봉사자 및 센터 속성별 업데이트 로직 포함 --- .../user/service/UpdateBasicInfoService.java | 58 +++++++++++++++++++ .../user/usecase/UpdateBasicInfoUseCase.java | 13 +++++ 2 files changed, 71 insertions(+) create mode 100644 src/main/java/com/somemore/user/service/UpdateBasicInfoService.java create mode 100644 src/main/java/com/somemore/user/usecase/UpdateBasicInfoUseCase.java diff --git a/src/main/java/com/somemore/user/service/UpdateBasicInfoService.java b/src/main/java/com/somemore/user/service/UpdateBasicInfoService.java new file mode 100644 index 00000000..b9dcdc61 --- /dev/null +++ b/src/main/java/com/somemore/user/service/UpdateBasicInfoService.java @@ -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, UUID roleId, VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto) { + updateCommonAttribute(userId, volunteerBasicInfoRequestDto.commonBasicInfo()); + updateVolunteerAttribute(userId, volunteerBasicInfoRequestDto); + } + + @Override + public void update(UUID userId, UUID roleId, 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()); + } +} diff --git a/src/main/java/com/somemore/user/usecase/UpdateBasicInfoUseCase.java b/src/main/java/com/somemore/user/usecase/UpdateBasicInfoUseCase.java new file mode 100644 index 00000000..9809787f --- /dev/null +++ b/src/main/java/com/somemore/user/usecase/UpdateBasicInfoUseCase.java @@ -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, UUID roleId, VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto); + + void update(UUID userId, UUID roleId, CenterBasicInfoRequestDto centerBasicInfoRequestDto); +} From 3053a669b6ba28e9ddb6bb3a3411dc11e705d460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sat, 25 Jan 2025 21:01:13 +0900 Subject: [PATCH 06/11] =?UTF-8?q?refactor(basicInfo):=20=EC=97=AD=ED=95=A0?= =?UTF-8?q?=20ID=20=EC=9D=B8=EC=9E=90=EB=A5=BC=20=EC=A0=9C=EA=B1=B0?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=8B=9C?= =?UTF-8?q?=EA=B7=B8=EB=8B=88=EC=B2=98=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - VolunteerBasicInfoRequestDto와 CenterBasicInfoRequestDto를 업데이트하는 메소드에서 roleId 파라미터 삭제 --- .../com/somemore/user/service/UpdateBasicInfoService.java | 4 ++-- .../com/somemore/user/usecase/UpdateBasicInfoUseCase.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/somemore/user/service/UpdateBasicInfoService.java b/src/main/java/com/somemore/user/service/UpdateBasicInfoService.java index b9dcdc61..3c991213 100644 --- a/src/main/java/com/somemore/user/service/UpdateBasicInfoService.java +++ b/src/main/java/com/somemore/user/service/UpdateBasicInfoService.java @@ -29,13 +29,13 @@ public class UpdateBasicInfoService implements UpdateBasicInfoUseCase { private final NEWCenterQueryUseCase centerQueryUseCase; @Override - public void update(UUID userId, UUID roleId, VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto) { + public void update(UUID userId, VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto) { updateCommonAttribute(userId, volunteerBasicInfoRequestDto.commonBasicInfo()); updateVolunteerAttribute(userId, volunteerBasicInfoRequestDto); } @Override - public void update(UUID userId, UUID roleId, CenterBasicInfoRequestDto centerBasicInfoRequestDto) { + public void update(UUID userId, CenterBasicInfoRequestDto centerBasicInfoRequestDto) { updateCommonAttribute(userId, centerBasicInfoRequestDto.commonBasicInfo()); updateCenterAttribute(userId, centerBasicInfoRequestDto); } diff --git a/src/main/java/com/somemore/user/usecase/UpdateBasicInfoUseCase.java b/src/main/java/com/somemore/user/usecase/UpdateBasicInfoUseCase.java index 9809787f..513f23a5 100644 --- a/src/main/java/com/somemore/user/usecase/UpdateBasicInfoUseCase.java +++ b/src/main/java/com/somemore/user/usecase/UpdateBasicInfoUseCase.java @@ -7,7 +7,7 @@ public interface UpdateBasicInfoUseCase { - void update(UUID userId, UUID roleId, VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto); + void update(UUID userId, VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto); - void update(UUID userId, UUID roleId, CenterBasicInfoRequestDto centerBasicInfoRequestDto); + void update(UUID userId, CenterBasicInfoRequestDto centerBasicInfoRequestDto); } From eccd9eda6909087fec2f721178b0e9fea1cbeffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sat, 25 Jan 2025 21:01:34 +0900 Subject: [PATCH 07/11] =?UTF-8?q?feat(basicInfo):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B8=B0=EB=B3=B8=20=EC=A0=95=EB=B3=B4=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - UserCommandController 클래스 생성 - 봉사자 기본 정보 업데이트 API 추가 - 센터 기본 정보 업데이트 API 추가 --- .../controller/UserCommandController.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/main/java/com/somemore/user/controller/UserCommandController.java diff --git a/src/main/java/com/somemore/user/controller/UserCommandController.java b/src/main/java/com/somemore/user/controller/UserCommandController.java new file mode 100644 index 00000000..8915cc25 --- /dev/null +++ b/src/main/java/com/somemore/user/controller/UserCommandController.java @@ -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.PostMapping; +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") + @PostMapping("/basic-info/volunteer") + @Operation(summary = "봉사자 기본 정보 업데이트", description = "봉사자의 기본 정보를 업데이트합니다.") + public ApiResponse registerBasicInfo( + @UserId UUID userId, + @RequestBody VolunteerBasicInfoRequestDto volunteerBasicInfoRequestDto + ) { + updateBasicInfoUseCase.update(userId, volunteerBasicInfoRequestDto); + return ApiResponse.ok("봉사자 기본 정보 업데이트 완료"); + } + + @Secured("ROLE_CENTER") + @PostMapping("/basic-info/center") + @Operation(summary = "센터 기본 정보 업데이트", description = "센터의 기본 정보를 업데이트합니다.") + public ApiResponse registerBasicInfo( + @UserId UUID userId, + @RequestBody CenterBasicInfoRequestDto centerBasicInfoRequestDto + ) { + updateBasicInfoUseCase.update(userId, centerBasicInfoRequestDto); + return ApiResponse.ok("센터 기본 정보 업데이틍 완료"); + } +} From 7696cb981663d7cf9f7fdfdb8437efaabbbe17d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sat, 25 Jan 2025 21:45:45 +0900 Subject: [PATCH 08/11] =?UTF-8?q?refactor(controller):=20=EA=B8=B0?= =?UTF-8?q?=EC=A1=B4=20PostMapping=EC=9D=84=20PutMapping=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 봉사자 및 센터 기본 정보 업데이트 엔드포인트를 PUT 메서드로 변경 - RESTful API 규칙에 따라 정보 업데이트에 PUT 메서드 활용 --- .../com/somemore/user/controller/UserCommandController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/somemore/user/controller/UserCommandController.java b/src/main/java/com/somemore/user/controller/UserCommandController.java index 8915cc25..8cb58151 100644 --- a/src/main/java/com/somemore/user/controller/UserCommandController.java +++ b/src/main/java/com/somemore/user/controller/UserCommandController.java @@ -10,7 +10,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.annotation.Secured; -import org.springframework.web.bind.annotation.PostMapping; +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; @@ -27,7 +27,7 @@ public class UserCommandController { private final UpdateBasicInfoUseCase updateBasicInfoUseCase; @Secured("ROLE_VOLUNTEER") - @PostMapping("/basic-info/volunteer") + @PutMapping("/basic-info/volunteer") @Operation(summary = "봉사자 기본 정보 업데이트", description = "봉사자의 기본 정보를 업데이트합니다.") public ApiResponse registerBasicInfo( @UserId UUID userId, @@ -38,7 +38,7 @@ public ApiResponse registerBasicInfo( } @Secured("ROLE_CENTER") - @PostMapping("/basic-info/center") + @PutMapping("/basic-info/center") @Operation(summary = "센터 기본 정보 업데이트", description = "센터의 기본 정보를 업데이트합니다.") public ApiResponse registerBasicInfo( @UserId UUID userId, From ce40522840235d81f323a2e395ec322e8dc52db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sat, 25 Jan 2025 21:46:02 +0900 Subject: [PATCH 09/11] =?UTF-8?q?test(user):=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=20=EA=B8=B0=EB=B3=B8=20=EC=A0=95=EB=B3=B4=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 봉사자의 기본 정보를 업데이트하는 테스트 케이스 추가 - 센터의 기본 정보를 업데이트하는 테스트 케이스 추가 --- .../service/UpdateBasicInfoServiceTest.java | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/test/java/com/somemore/user/service/UpdateBasicInfoServiceTest.java diff --git a/src/test/java/com/somemore/user/service/UpdateBasicInfoServiceTest.java b/src/test/java/com/somemore/user/service/UpdateBasicInfoServiceTest.java new file mode 100644 index 00000000..f8ef3fb3 --- /dev/null +++ b/src/test/java/com/somemore/user/service/UpdateBasicInfoServiceTest.java @@ -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" + ); + } +} From 45e5d24a04bd3a4b391c882f2b136ed5e4a07e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sat, 25 Jan 2025 21:53:45 +0900 Subject: [PATCH 10/11] =?UTF-8?q?refactor(user):=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EC=A3=BC=EC=84=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/somemore/user/domain/UserCommonAttribute.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java index f2a11ea5..9e2c8dfc 100644 --- a/src/main/java/com/somemore/user/domain/UserCommonAttribute.java +++ b/src/main/java/com/somemore/user/domain/UserCommonAttribute.java @@ -46,7 +46,6 @@ public class UserCommonAttribute extends BaseEntity { private boolean isCustomized; public void update(CommonBasicInfoRequestDto commonBasicInfoRequestDto) { - // TODO param의 정보를 필드에 업데이트 this.name = commonBasicInfoRequestDto.name(); this.contactNumber = commonBasicInfoRequestDto.contactNumber(); this.imgUrl = commonBasicInfoRequestDto.imgUrl(); From 8efcbb3f42288d8a9cc5dcd694a530a8bbcc9a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Tue, 28 Jan 2025 19:17:03 +0900 Subject: [PATCH 11/11] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98,=20?= =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/somemore/user/controller/UserCommandController.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/somemore/user/controller/UserCommandController.java b/src/main/java/com/somemore/user/controller/UserCommandController.java index 8cb58151..7c574a8a 100644 --- a/src/main/java/com/somemore/user/controller/UserCommandController.java +++ b/src/main/java/com/somemore/user/controller/UserCommandController.java @@ -8,7 +8,6 @@ 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; @@ -19,7 +18,6 @@ @Tag(name = "User Command API", description = "유저 생성 수정 삭제 관련 API") @RestController -@Slf4j @RequiredArgsConstructor @RequestMapping("/api/user") public class UserCommandController { @@ -45,6 +43,6 @@ public ApiResponse registerBasicInfo( @RequestBody CenterBasicInfoRequestDto centerBasicInfoRequestDto ) { updateBasicInfoUseCase.update(userId, centerBasicInfoRequestDto); - return ApiResponse.ok("센터 기본 정보 업데이틍 완료"); + return ApiResponse.ok("센터 기본 정보 업데이 완료"); } }