From e3231ee1d50fbb0091b4271bb7e462480f4c2ed5 Mon Sep 17 00:00:00 2001 From: leebs0521 Date: Thu, 2 Jan 2025 14:17:12 +0900 Subject: [PATCH 01/12] =?UTF-8?q?refactor(recruit-board):=20=EB=B4=89?= =?UTF-8?q?=EC=82=AC=20=EC=8B=9C=EA=B0=84=20=ED=95=84=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=20-=20volunteer=5Fhours?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruitboard/domain/RecruitBoard.java | 30 ++++-------- .../recruitboard/domain/RecruitmentInfo.java | 46 ++++++------------- .../request/RecruitBoardCreateRequestDto.java | 7 ++- .../request/RecruitBoardUpdateRequestDto.java | 9 +++- .../RecruitBoardDetailResponseDto.java | 12 ++--- .../dto/response/RecruitBoardResponseDto.java | 8 ++-- .../RecruitBoardWithCenterResponseDto.java | 12 ++--- .../RecruitBoardWithLocationResponseDto.java | 12 ++--- .../command/CreateRecruitBoardService.java | 20 ++++---- .../SettleVolunteerApplyFacadeService.java | 20 ++++---- 10 files changed, 79 insertions(+), 97 deletions(-) diff --git a/src/main/java/com/somemore/domains/recruitboard/domain/RecruitBoard.java b/src/main/java/com/somemore/domains/recruitboard/domain/RecruitBoard.java index 5f7eb312b..38f5e7047 100644 --- a/src/main/java/com/somemore/domains/recruitboard/domain/RecruitBoard.java +++ b/src/main/java/com/somemore/domains/recruitboard/domain/RecruitBoard.java @@ -1,26 +1,19 @@ package com.somemore.domains.recruitboard.domain; -import static jakarta.persistence.EnumType.STRING; -import static jakarta.persistence.GenerationType.IDENTITY; -import static lombok.AccessLevel.PROTECTED; - import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto; import com.somemore.global.common.entity.BaseEntity; -import jakarta.persistence.Column; -import jakarta.persistence.Embedded; -import jakarta.persistence.Entity; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.Lob; -import jakarta.persistence.Table; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.UUID; +import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import java.time.LocalDateTime; +import java.util.UUID; + +import static jakarta.persistence.EnumType.STRING; +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + @Getter @NoArgsConstructor(access = PROTECTED) @Entity @@ -56,7 +49,7 @@ public class RecruitBoard extends BaseEntity { @Builder public RecruitBoard(UUID centerId, Long locationId, String title, String content, - RecruitmentInfo recruitmentInfo, String imgUrl) { + RecruitmentInfo recruitmentInfo, String imgUrl) { this.centerId = centerId; this.locationId = locationId; this.title = title; @@ -65,10 +58,6 @@ public RecruitBoard(UUID centerId, Long locationId, String title, String content this.imgUrl = imgUrl; } - public LocalTime getVolunteerHours() { - return recruitmentInfo.calculateVolunteerTime(); - } - public boolean isWriter(UUID centerId) { return this.centerId.equals(centerId); } @@ -102,6 +91,7 @@ private void updateRecruitmentInfo(RecruitBoardUpdateRequestDto dto) { dto.volunteerCategory(), dto.volunteerStartDateTime(), dto.volunteerEndDateTime(), + dto.volunteerHours(), dto.admitted() ); } diff --git a/src/main/java/com/somemore/domains/recruitboard/domain/RecruitmentInfo.java b/src/main/java/com/somemore/domains/recruitboard/domain/RecruitmentInfo.java index 6da58085b..63c8fbebb 100644 --- a/src/main/java/com/somemore/domains/recruitboard/domain/RecruitmentInfo.java +++ b/src/main/java/com/somemore/domains/recruitboard/domain/RecruitmentInfo.java @@ -1,19 +1,18 @@ package com.somemore.domains.recruitboard.domain; -import static jakarta.persistence.EnumType.STRING; -import static java.time.temporal.ChronoUnit.MINUTES; -import static lombok.AccessLevel.PROTECTED; - import jakarta.persistence.Column; import jakarta.persistence.Embeddable; import jakarta.persistence.Enumerated; -import java.time.Duration; -import java.time.LocalDateTime; -import java.time.LocalTime; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import java.time.LocalDateTime; + +import static jakarta.persistence.EnumType.STRING; +import static java.time.temporal.ChronoUnit.MINUTES; +import static lombok.AccessLevel.PROTECTED; + @Getter @NoArgsConstructor(access = PROTECTED) @Embeddable @@ -31,6 +30,9 @@ public class RecruitmentInfo { @Column(name = "volunteer_end_date_time", nullable = false) private LocalDateTime volunteerEndDateTime; + @Column(name = "volunteer_hours", nullable = false) + private Integer volunteerHours; + @Enumerated(value = STRING) @Column(name = "volunteer_category", nullable = false, length = 30) private VolunteerCategory volunteerCategory; @@ -39,40 +41,27 @@ public class RecruitmentInfo { private Boolean admitted; @Builder - public RecruitmentInfo(String region, Integer recruitmentCount, - LocalDateTime volunteerStartDateTime, LocalDateTime volunteerEndDateTime, - VolunteerCategory volunteerCategory, Boolean admitted) { - - validateVolunteerDateTime(volunteerStartDateTime, volunteerEndDateTime); + public RecruitmentInfo(String region, Integer recruitmentCount, LocalDateTime volunteerStartDateTime, LocalDateTime volunteerEndDateTime, + Integer volunteerHours, VolunteerCategory volunteerCategory, Boolean admitted) { this.region = region; this.recruitmentCount = recruitmentCount; this.volunteerStartDateTime = volunteerStartDateTime.truncatedTo(MINUTES); this.volunteerEndDateTime = volunteerEndDateTime.truncatedTo(MINUTES); + this.volunteerHours = volunteerHours; this.volunteerCategory = volunteerCategory; this.admitted = admitted; } - public LocalTime calculateVolunteerTime() { - Duration duration = Duration.between(volunteerStartDateTime, volunteerEndDateTime); - - long hours = duration.toHours(); - long minutes = duration.toMinutes() % 60; - - return LocalTime.of((int) hours, (int) minutes); - } - public void updateWith(String region, Integer recruitmentCount, VolunteerCategory volunteerCategory, - LocalDateTime volunteerStartDateTime, LocalDateTime volunteerEndDateTime, - Boolean admitted) { - - validateVolunteerDateTime(volunteerStartDateTime, volunteerEndDateTime); - + LocalDateTime volunteerStartDateTime, LocalDateTime volunteerEndDateTime, + Integer volunteerHours, Boolean admitted) { this.region = region; this.recruitmentCount = recruitmentCount; this.volunteerCategory = volunteerCategory; this.volunteerStartDateTime = volunteerStartDateTime.truncatedTo(MINUTES); this.volunteerEndDateTime = volunteerEndDateTime.truncatedTo(MINUTES); + this.volunteerHours = volunteerHours; this.admitted = admitted; } @@ -80,9 +69,4 @@ public void updateWith(String region) { this.region = region; } - private void validateVolunteerDateTime(LocalDateTime startDateTime, LocalDateTime endDateTime) { - if (endDateTime.isEqual(startDateTime) || endDateTime.isBefore(startDateTime)) { - throw new IllegalArgumentException("종료 시간은 시작 시간보다 이후여야 합니다."); - } - } } diff --git a/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardCreateRequestDto.java b/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardCreateRequestDto.java index f460aec7f..366ba9909 100644 --- a/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardCreateRequestDto.java +++ b/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardCreateRequestDto.java @@ -10,9 +10,10 @@ import jakarta.validation.constraints.Future; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import lombok.Builder; + import java.time.LocalDateTime; import java.util.UUID; -import lombok.Builder; @JsonNaming(SnakeCaseStrategy.class) @Builder @@ -37,6 +38,9 @@ public record RecruitBoardCreateRequestDto( @NotNull(message = "봉사 종료 일시는 필수 값입니다.") @Future(message = "봉사 종료 일시는 내일부터 가능합니다.") LocalDateTime volunteerEndDateTime, + @Schema(description = "봉사 시간", example = "2") + @NotNull(message = "봉사 시간는 필수 값입니다.") + Integer volunteerHours, @Schema(description = "봉사 활동 유형", example = "ENVIRONMENTAL_PROTECTION") @NotNull(message = "봉사 활동 유형은 필수 값입니다.") VolunteerCategory volunteerCategory, @@ -53,6 +57,7 @@ public RecruitBoard toEntity(UUID centerId, Long locationId, String imgUrl) { .recruitmentCount(recruitmentCount) .volunteerStartDateTime(volunteerStartDateTime) .volunteerEndDateTime(volunteerEndDateTime) + .volunteerHours(volunteerHours) .volunteerCategory(volunteerCategory) .admitted(admitted) .build(); diff --git a/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardUpdateRequestDto.java b/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardUpdateRequestDto.java index dbcf00b4b..39270be2e 100644 --- a/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardUpdateRequestDto.java +++ b/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardUpdateRequestDto.java @@ -7,9 +7,10 @@ import jakarta.validation.constraints.Future; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -import java.time.LocalDateTime; import lombok.Builder; +import java.time.LocalDateTime; + @JsonNaming(SnakeCaseStrategy.class) @Builder public record RecruitBoardUpdateRequestDto( @@ -31,7 +32,11 @@ public record RecruitBoardUpdateRequestDto( LocalDateTime volunteerStartDateTime, @Schema(description = "봉사 종료 일시", example = "2024-12-20T12:00:00", type = "string") @NotNull(message = "봉사 종료 일시는 필수 값입니다.") - @Future(message = "봉사 종료 일시는 내일부터 가능합니다.")LocalDateTime volunteerEndDateTime, + @Future(message = "봉사 종료 일시는 내일부터 가능합니다.") + LocalDateTime volunteerEndDateTime, + @Schema(description = "봉사 시간", example = "2") + @NotNull(message = "봉사 시간는 필수 값입니다.") + Integer volunteerHours, @Schema(description = "봉사 활동 유형", example = "ENVIRONMENTAL_PROTECTION") @NotNull(message = "봉사 활동 유형은 필수 값입니다.") VolunteerCategory volunteerCategory, diff --git a/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardDetailResponseDto.java b/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardDetailResponseDto.java index e75ac6782..2a1c2a3a8 100644 --- a/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardDetailResponseDto.java +++ b/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardDetailResponseDto.java @@ -3,17 +3,17 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.somemore.domains.center.dto.response.CenterSimpleInfoResponseDto; -import com.somemore.domains.recruitboard.repository.mapper.RecruitBoardDetail; import com.somemore.domains.location.dto.response.LocationResponseDto; import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.domain.RecruitStatus; import com.somemore.domains.recruitboard.domain.RecruitmentInfo; import com.somemore.domains.recruitboard.domain.VolunteerCategory; +import com.somemore.domains.recruitboard.repository.mapper.RecruitBoardDetail; import io.swagger.v3.oas.annotations.media.Schema; -import java.time.LocalDateTime; -import java.time.LocalTime; import lombok.Builder; +import java.time.LocalDateTime; + @Builder @JsonNaming(SnakeCaseStrategy.class) @@ -41,8 +41,8 @@ public record RecruitBoardDetailResponseDto( LocalDateTime volunteerEndDateTime, @Schema(description = "봉사 유형", example = "LIVING_SUPPORT") VolunteerCategory volunteerCategory, - @Schema(description = "봉사 시간", example = "04:00:00") - LocalTime volunteerTime, + @Schema(description = "봉사 시간", example = "4") + Integer volunteerHours, @Schema(description = "시간 인정 여부", example = "true") Boolean admitted, @Schema(description = "이미지 URL", example = "https://image.domain.com/links") @@ -74,7 +74,7 @@ public static RecruitBoardDetailResponseDto from(RecruitBoardDetail recruitBoard .volunteerStartDateTime(info.getVolunteerStartDateTime()) .volunteerEndDateTime(info.getVolunteerEndDateTime()) .volunteerCategory(info.getVolunteerCategory()) - .volunteerTime(info.calculateVolunteerTime()) + .volunteerHours(info.getVolunteerHours()) .admitted(info.getAdmitted()) .imgUrl(board.getImgUrl()) .location(location) diff --git a/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardResponseDto.java b/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardResponseDto.java index c53bde56a..22f428762 100644 --- a/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardResponseDto.java +++ b/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardResponseDto.java @@ -7,10 +7,10 @@ import com.somemore.domains.recruitboard.domain.RecruitmentInfo; import com.somemore.domains.recruitboard.domain.VolunteerCategory; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; + import java.time.LocalDateTime; -import java.time.LocalTime; import java.util.UUID; -import lombok.Builder; @Builder @JsonNaming(SnakeCaseStrategy.class) @@ -43,7 +43,7 @@ public record RecruitBoardResponseDto( @Schema(description = "봉사 유형", example = "LIVING_SUPPORT") VolunteerCategory volunteerCategory, @Schema(description = "봉사 시간", example = "04:00:00") - LocalTime volunteerTime, + Integer volunteerHours, @Schema(description = "시간 인정 여부", example = "true") Boolean admitted, @Schema(description = "이미지 URL", example = "https://image.domain.com/links") @@ -66,7 +66,7 @@ public static RecruitBoardResponseDto from(RecruitBoard board) { .volunteerStartDateTime(info.getVolunteerStartDateTime()) .volunteerEndDateTime(info.getVolunteerEndDateTime()) .volunteerCategory(info.getVolunteerCategory()) - .volunteerTime(info.calculateVolunteerTime()) + .volunteerHours(info.getVolunteerHours()) .admitted(info.getAdmitted()) .imgUrl(board.getImgUrl()) .build(); diff --git a/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardWithCenterResponseDto.java b/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardWithCenterResponseDto.java index e1dc5ab36..d7f73e308 100644 --- a/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardWithCenterResponseDto.java +++ b/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardWithCenterResponseDto.java @@ -3,16 +3,16 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.somemore.domains.center.dto.response.CenterSimpleInfoResponseDto; -import com.somemore.domains.recruitboard.repository.mapper.RecruitBoardWithCenter; import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.domain.RecruitStatus; import com.somemore.domains.recruitboard.domain.RecruitmentInfo; import com.somemore.domains.recruitboard.domain.VolunteerCategory; +import com.somemore.domains.recruitboard.repository.mapper.RecruitBoardWithCenter; import io.swagger.v3.oas.annotations.media.Schema; -import java.time.LocalDateTime; -import java.time.LocalTime; import lombok.Builder; +import java.time.LocalDateTime; + @Builder @JsonNaming(SnakeCaseStrategy.class) @Schema(description = "봉사 모집글 기관 포함 응답 DTO") @@ -41,8 +41,8 @@ public record RecruitBoardWithCenterResponseDto( LocalDateTime volunteerEndDateTime, @Schema(description = "봉사 유형", example = "LIVING_SUPPORT") VolunteerCategory volunteerCategory, - @Schema(description = "봉사 시간", example = "04:00:00") - LocalTime volunteerTime, + @Schema(description = "봉사 시간", example = "4") + Integer volunteerHours, @Schema(description = "시간 인정 여부", example = "true") Boolean admitted, @Schema(description = "이미지 URL", example = "https://image.domain.com/links") @@ -69,7 +69,7 @@ public static RecruitBoardWithCenterResponseDto from( .volunteerStartDateTime(info.getVolunteerStartDateTime()) .volunteerEndDateTime(info.getVolunteerEndDateTime()) .volunteerCategory(info.getVolunteerCategory()) - .volunteerTime(info.calculateVolunteerTime()) + .volunteerHours(info.getVolunteerHours()) .admitted(info.getAdmitted()) .imgUrl(board.getImgUrl()) .center(CenterSimpleInfoResponseDto.of(board.getCenterId(), diff --git a/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardWithLocationResponseDto.java b/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardWithLocationResponseDto.java index fd545d1ae..170377f38 100644 --- a/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardWithLocationResponseDto.java +++ b/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardWithLocationResponseDto.java @@ -2,17 +2,17 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; -import com.somemore.domains.recruitboard.repository.mapper.RecruitBoardWithLocation; import com.somemore.domains.location.dto.response.LocationResponseDto; import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.domain.RecruitStatus; import com.somemore.domains.recruitboard.domain.RecruitmentInfo; import com.somemore.domains.recruitboard.domain.VolunteerCategory; +import com.somemore.domains.recruitboard.repository.mapper.RecruitBoardWithLocation; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; + import java.time.LocalDateTime; -import java.time.LocalTime; import java.util.UUID; -import lombok.Builder; @Builder @JsonNaming(SnakeCaseStrategy.class) @@ -42,8 +42,8 @@ public record RecruitBoardWithLocationResponseDto( LocalDateTime volunteerEndDateTime, @Schema(description = "봉사 유형", example = "LIVING_SUPPORT") VolunteerCategory volunteerCategory, - @Schema(description = "봉사 시간", example = "04:00:00") - LocalTime volunteerTime, + @Schema(description = "봉사 시간", example = "4") + Integer volunteerHours, @Schema(description = "시간 인정 여부", example = "true") Boolean admitted, @Schema(description = "이미지 URL", example = "https://image.domain.com/links") @@ -70,7 +70,7 @@ public static RecruitBoardWithLocationResponseDto from( .volunteerStartDateTime(info.getVolunteerStartDateTime()) .volunteerEndDateTime(info.getVolunteerEndDateTime()) .volunteerCategory(info.getVolunteerCategory()) - .volunteerTime(info.calculateVolunteerTime()) + .volunteerHours(info.getVolunteerHours()) .admitted(info.getAdmitted()) .imgUrl(board.getImgUrl()) .location( diff --git a/src/main/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardService.java b/src/main/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardService.java index 25df06ff0..2d900bc5b 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardService.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardService.java @@ -1,14 +1,15 @@ package com.somemore.domains.recruitboard.service.command; -import com.somemore.global.common.event.DomainEventSubType; -import com.somemore.global.common.event.ServerEventPublisher; -import com.somemore.global.common.event.ServerEventType; import com.somemore.domains.location.usecase.command.CreateLocationUseCase; import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.dto.request.RecruitBoardCreateRequestDto; import com.somemore.domains.recruitboard.event.CreateRecruitBoardEvent; import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; +import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator; import com.somemore.domains.recruitboard.usecase.command.CreateRecruitBoardUseCase; +import com.somemore.global.common.event.DomainEventSubType; +import com.somemore.global.common.event.ServerEventPublisher; +import com.somemore.global.common.event.ServerEventType; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,17 +23,16 @@ public class CreateRecruitBoardService implements CreateRecruitBoardUseCase { private final RecruitBoardRepository recruitBoardRepository; + private final RecruitBoardValidator recruitBoardValidator; private final CreateLocationUseCase createLocationUseCase; private final ServerEventPublisher serverEventPublisher; @Override - public Long createRecruitBoard( - RecruitBoardCreateRequestDto requestDto, - UUID centerId, - String imgUrl - ) { - Long locationId = createLocationUseCase.createLocation(requestDto.location()); - RecruitBoard recruitBoard = requestDto.toEntity(centerId, locationId, imgUrl); + public Long createRecruitBoard(RecruitBoardCreateRequestDto dto, UUID centerId, String imgUrl) { + recruitBoardValidator.validateRecruitBoardTime(dto.volunteerStartDateTime(), dto.volunteerEndDateTime()); + + Long locationId = createLocationUseCase.createLocation(dto.location()); + RecruitBoard recruitBoard = dto.toEntity(centerId, locationId, imgUrl); recruitBoardRepository.save(recruitBoard); diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java index c179409ef..f1b24b7f0 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java @@ -1,28 +1,26 @@ package com.somemore.domains.volunteerapply.service; -import static com.somemore.global.exception.ExceptionMessage.RECRUIT_BOARD_ID_MISMATCH; -import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; -import static com.somemore.global.exception.ExceptionMessage.VOLUNTEER_APPLY_LIST_MISMATCH; - import com.somemore.domains.notification.domain.NotificationSubType; import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; import com.somemore.domains.volunteer.usecase.UpdateVolunteerUseCase; +import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.dto.request.VolunteerApplySettleRequestDto; +import com.somemore.domains.volunteerapply.event.VolunteerReviewRequestEvent; import com.somemore.domains.volunteerapply.usecase.SettleVolunteerApplyFacadeUseCase; import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase; -import com.somemore.domains.volunteerapply.event.VolunteerReviewRequestEvent; import com.somemore.global.common.event.ServerEventPublisher; import com.somemore.global.common.event.ServerEventType; import com.somemore.global.exception.BadRequestException; -import com.somemore.domains.volunteerapply.domain.VolunteerApply; - -import java.util.List; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.UUID; + +import static com.somemore.global.exception.ExceptionMessage.*; + @RequiredArgsConstructor @Transactional @Service @@ -43,7 +41,7 @@ public void settleVolunteerApplies(VolunteerApplySettleRequestDto dto, UUID cent validateRecruitBoardConsistency(applies, recruitBoardId); validateAuth(recruitBoard, centerId); - int hours = recruitBoard.getVolunteerHours().getHour(); + int hours = recruitBoard.getRecruitmentInfo().getVolunteerHours(); applies.forEach(apply -> { apply.changeAttended(true); @@ -68,7 +66,7 @@ private void validateVolunteerApplyExistence(List ids, List applies, - Long recruitBoardId) { + Long recruitBoardId) { boolean anyMismatch = applies.stream() .anyMatch(apply -> !apply.getRecruitBoardId().equals(recruitBoardId)); From d9a37c3efc7a483187c075a78549d138d5b27bbd Mon Sep 17 00:00:00 2001 From: leebs0521 Date: Thu, 2 Jan 2025 14:17:38 +0900 Subject: [PATCH 02/12] =?UTF-8?q?test(recruit-board):=20=EB=B4=89=EC=82=AC?= =?UTF-8?q?=20=EC=8B=9C=EA=B0=84=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=20-=20volunteer=5Fhours?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RecruitBoardCommandApiControllerTest.java | 36 ++++---- .../recruitboard/domain/RecruitBoardTest.java | 21 +---- .../domain/RecruitmentInfoTest.java | 78 +++------------- .../CreateRecruitBoardServiceTest.java | 29 +++--- .../DeleteRecruitBoardServiceTest.java | 31 +++---- .../UpdateRecruitBoardServiceTest.java | 88 +++++++++---------- ...SettleVolunteerApplyFacadeServiceTest.java | 2 +- .../support/fixture/RecruitBoardFixture.java | 49 +++++++---- 8 files changed, 141 insertions(+), 193 deletions(-) diff --git a/src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiControllerTest.java b/src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiControllerTest.java index e95e44a4a..28bac8c3f 100644 --- a/src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiControllerTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiControllerTest.java @@ -1,20 +1,5 @@ package com.somemore.domains.recruitboard.controller; -import static com.somemore.domains.recruitboard.domain.RecruitStatus.CLOSED; -import static com.somemore.domains.recruitboard.domain.VolunteerCategory.OTHER; -import static com.somemore.support.fixture.LocalDateTimeFixture.createStartDateTime; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.willDoNothing; -import static org.springframework.http.MediaType.MULTIPART_FORM_DATA; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - import com.somemore.domains.location.dto.request.LocationCreateRequestDto; import com.somemore.domains.recruitboard.domain.RecruitStatus; import com.somemore.domains.recruitboard.dto.request.RecruitBoardCreateRequestDto; @@ -27,9 +12,6 @@ import com.somemore.global.imageupload.usecase.ImageUploadUseCase; import com.somemore.support.ControllerTestSupport; import com.somemore.support.annotation.WithMockCustomUser; -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.util.UUID; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; @@ -39,6 +21,22 @@ import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.RequestPostProcessor; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.UUID; + +import static com.somemore.domains.recruitboard.domain.RecruitStatus.CLOSED; +import static com.somemore.domains.recruitboard.domain.VolunteerCategory.OTHER; +import static com.somemore.support.fixture.LocalDateTimeFixture.createStartDateTime; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willDoNothing; +import static org.springframework.http.MediaType.MULTIPART_FORM_DATA; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + class RecruitBoardCommandApiControllerTest extends ControllerTestSupport { @MockBean @@ -74,6 +72,7 @@ void createRecruitBoard_success() throws Exception { .recruitmentCount(10) .volunteerStartDateTime(startDateTime) .volunteerEndDateTime(endDateTime) + .volunteerHours(2) .volunteerCategory(OTHER) .admitted(true) .location(location) @@ -128,6 +127,7 @@ void updateRecruitBoard() throws Exception { .recruitmentCount(10) .volunteerStartDateTime(startDateTime) .volunteerEndDateTime(endDateTime) + .volunteerHours(2) .volunteerCategory(OTHER) .admitted(true) .build(); diff --git a/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java b/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java index 0b3d924f1..fa37b1d82 100644 --- a/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java @@ -7,12 +7,12 @@ import org.junit.jupiter.params.provider.ValueSource; import java.time.LocalDateTime; -import java.time.LocalTime; import java.util.UUID; import static com.somemore.domains.recruitboard.domain.RecruitStatus.*; import static com.somemore.domains.recruitboard.domain.VolunteerCategory.OTHER; -import static com.somemore.support.fixture.LocalDateTimeFixture.*; +import static com.somemore.support.fixture.LocalDateTimeFixture.createCurrentDateTime; +import static com.somemore.support.fixture.LocalDateTimeFixture.createUpdateStartDateTime; import static com.somemore.support.fixture.RecruitBoardFixture.createRecruitBoard; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -34,23 +34,6 @@ void createRecruitBoardWithDefaultStatus() { assertThat(recruitStatus).isEqualTo(RECRUITING); } - @DisplayName("봉사 시간을 계산할 수 있다") - @Test - void testCalculateVolunteerTime() { - // given - int hours = 3; - LocalDateTime startDateTime = createStartDateTime(); - LocalDateTime endDateTime = startDateTime.plusHours(hours); - - RecruitBoard board = createRecruitBoard(startDateTime, endDateTime); - - // when - LocalTime volunteerTime = board.getVolunteerHours(); - - // then - assertThat(volunteerTime).isEqualTo(LocalTime.of(hours, 0)); - } - @DisplayName("봉사 모집글을 업데이트 할 수 있다") @Test void updateRecruitBoard() { diff --git a/src/test/java/com/somemore/domains/recruitboard/domain/RecruitmentInfoTest.java b/src/test/java/com/somemore/domains/recruitboard/domain/RecruitmentInfoTest.java index 079be5c4c..62c6b1e0b 100644 --- a/src/test/java/com/somemore/domains/recruitboard/domain/RecruitmentInfoTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/domain/RecruitmentInfoTest.java @@ -2,52 +2,17 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; import java.time.LocalDateTime; -import java.time.LocalTime; -import static com.somemore.domains.recruitboard.domain.VolunteerCategory.*; +import static com.somemore.domains.recruitboard.domain.VolunteerCategory.OTHER; +import static com.somemore.domains.recruitboard.domain.VolunteerCategory.SAFETY_PREVENTION; import static com.somemore.support.fixture.LocalDateTimeFixture.createStartDateTime; import static com.somemore.support.fixture.LocalDateTimeFixture.createUpdateStartDateTime; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; class RecruitmentInfoTest { - @DisplayName("봉사 종료 시간이 시작 시간과 같거나 빠르면, 봉사 모집글 생성 시 에러가 발생한다") - @ParameterizedTest - @ValueSource(longs = {0, -1}) - void createRecruitBoardWithInValidVolunteerTime(long minutesOffset) { - // given - LocalDateTime now = createStartDateTime(); - LocalDateTime endDateTime = now.plusMinutes(minutesOffset); - - // when & then - assertThatThrownBy( - () -> createRecruitmentInfo(now, endDateTime) - ).isInstanceOf(IllegalArgumentException.class); - - } - - @DisplayName("봉사 시간을 계산할 수 있다") - @Test - void testCalculateVolunteerTime() { - // given - int hours = 3; - LocalDateTime startDateTime = createStartDateTime(); - LocalDateTime endDateTime = startDateTime.plusHours(hours); - - RecruitmentInfo recruitmentInfo = createRecruitmentInfo(startDateTime, endDateTime); - - // when - LocalTime volunteerTime = recruitmentInfo.calculateVolunteerTime(); - - // then - assertThat(volunteerTime).isEqualTo(LocalTime.of(hours, 0)); - } - @DisplayName("봉사 활동 정보를 업데이트 할 수 있다") @Test void updateRecruitmentInfo() { @@ -59,17 +24,18 @@ void updateRecruitmentInfo() { VolunteerCategory volunteerCategory = SAFETY_PREVENTION; LocalDateTime startDateTime = createUpdateStartDateTime(); LocalDateTime endDateTime = startDateTime.plusHours(2); + Integer volunteerHours = 2; Boolean admitted = false; // when - recruitmentInfo.updateWith(region, count, volunteerCategory, startDateTime, - endDateTime, admitted); + recruitmentInfo.updateWith(region, count, volunteerCategory, startDateTime, endDateTime, volunteerHours, admitted); // then assertThat(recruitmentInfo.getRecruitmentCount()).isEqualTo(count); assertThat(recruitmentInfo.getVolunteerCategory()).isEqualTo(volunteerCategory); assertThat(recruitmentInfo.getVolunteerStartDateTime().compareTo(startDateTime)).isZero(); assertThat(recruitmentInfo.getVolunteerEndDateTime().compareTo(endDateTime)).isZero(); + assertThat(recruitmentInfo.getVolunteerHours()).isEqualTo(volunteerHours); assertThat(recruitmentInfo.getAdmitted()).isEqualTo(admitted); } @@ -87,34 +53,16 @@ void updateRecruitmentInfoWithRegion() { assertThat(recruitmentInfo.getRegion()).isEqualTo(updateRegion); } - @DisplayName("봉사 종료 시간이 시작 시간과 같거나 빠르면, 봉사 모집글을 업데이트시 에러가 발생한다") - @ParameterizedTest - @ValueSource(longs = {0, -1}) - void updateRecruitBoardWithInValidVolunteerTime(long minutesOffset) { - // given - LocalDateTime startDateTime = createStartDateTime(); - LocalDateTime endDateTime = startDateTime.plusMinutes(minutesOffset); - - RecruitmentInfo recruitmentInfo = createRecruitmentInfo(); - - // when & then - assertThatThrownBy( - () -> recruitmentInfo.updateWith("",3, ADMINISTRATIVE_SUPPORT, startDateTime, endDateTime, - false) - ).isInstanceOf(IllegalArgumentException.class); - - } - private static RecruitmentInfo createRecruitmentInfo(LocalDateTime startDateTime, - LocalDateTime endDateTime) { + LocalDateTime endDateTime) { return RecruitmentInfo.builder() - .region("경기") - .recruitmentCount(1) - .volunteerStartDateTime(startDateTime) - .volunteerEndDateTime(endDateTime) - .volunteerCategory(OTHER) - .admitted(true) - .build(); + .region("경기") + .recruitmentCount(1) + .volunteerStartDateTime(startDateTime) + .volunteerEndDateTime(endDateTime) + .volunteerCategory(OTHER) + .admitted(true) + .build(); } private static RecruitmentInfo createRecruitmentInfo() { diff --git a/src/test/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardServiceTest.java b/src/test/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardServiceTest.java index 3f92e73f8..9191d78b1 100644 --- a/src/test/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardServiceTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardServiceTest.java @@ -46,25 +46,26 @@ void tearDown() { void createRecruitBoardWithDto() { // given LocationCreateRequestDto locationDto = LocationCreateRequestDto.builder() - .address("도로명 주소 33") - .latitude(BigDecimal.valueOf(37.4845373748015)) - .longitude(BigDecimal.valueOf(127.010842267696)) - .build(); + .address("도로명 주소 33") + .latitude(BigDecimal.valueOf(37.4845373748015)) + .longitude(BigDecimal.valueOf(127.010842267696)) + .build(); LocalDateTime startDateTime = createStartDateTime(); LocalDateTime endDateTime = startDateTime.plusHours(2); RecruitBoardCreateRequestDto dto = RecruitBoardCreateRequestDto.builder() - .title("봉사 모집글 작성") - .content("봉사 하실분을 모집합니다.
") - .region("지역") - .recruitmentCount(10) - .volunteerStartDateTime(startDateTime) - .volunteerEndDateTime(endDateTime) - .volunteerCategory(OTHER) - .admitted(true) - .location(locationDto) - .build(); + .title("봉사 모집글 작성") + .content("봉사 하실분을 모집합니다.
") + .region("지역") + .recruitmentCount(10) + .volunteerStartDateTime(startDateTime) + .volunteerEndDateTime(endDateTime) + .volunteerHours(2) + .volunteerCategory(OTHER) + .admitted(true) + .location(locationDto) + .build(); UUID centerId = UUID.randomUUID(); String imgUrl = "https://image.domain.com/links"; diff --git a/src/test/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardServiceTest.java b/src/test/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardServiceTest.java index 20e0368d8..3c429f32d 100644 --- a/src/test/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardServiceTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardServiceTest.java @@ -71,7 +71,7 @@ void deleteRecruitBoardWithWrongCenterId() { // when // then assertThatThrownBy( - () -> deleteRecruitBoardService.deleteRecruitBoard(wrongCenterId, recruitBoardId) + () -> deleteRecruitBoardService.deleteRecruitBoard(wrongCenterId, recruitBoardId) ).isInstanceOf(BadRequestException.class); } @@ -81,21 +81,22 @@ private static RecruitBoard createRecruitBoard() { LocalDateTime endDateTime = startDateTime.plusHours(1); RecruitmentInfo recruitmentInfo = RecruitmentInfo.builder() - .region("경기") - .recruitmentCount(1) - .volunteerStartDateTime(startDateTime) - .volunteerEndDateTime(endDateTime) - .volunteerCategory(OTHER) - .admitted(true) - .build(); + .region("경기") + .recruitmentCount(1) + .volunteerStartDateTime(startDateTime) + .volunteerEndDateTime(endDateTime) + .volunteerHours(1) + .volunteerCategory(OTHER) + .admitted(true) + .build(); return RecruitBoard.builder() - .centerId(UUID.randomUUID()) - .locationId(1L) - .title("봉사모집제목") - .content("봉사모집내용") - .imgUrl("https://image.domain.com/links") - .recruitmentInfo(recruitmentInfo) - .build(); + .centerId(UUID.randomUUID()) + .locationId(1L) + .title("봉사모집제목") + .content("봉사모집내용") + .imgUrl("https://image.domain.com/links") + .recruitmentInfo(recruitmentInfo) + .build(); } } diff --git a/src/test/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardServiceTest.java b/src/test/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardServiceTest.java index eca0beacb..4e9c92798 100644 --- a/src/test/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardServiceTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardServiceTest.java @@ -73,17 +73,18 @@ void updateRecruitBoard() { .region("서울특별시") .volunteerStartDateTime(newStartDateTime) .volunteerEndDateTime(newEndDateTime) + .volunteerHours(3) .volunteerCategory(ADMINISTRATIVE_SUPPORT) .admitted(false) .build(); // when updateRecruitBoardService.updateRecruitBoard(dto, recruitBoard.getId(), centerId, - newImgUrl); + newImgUrl); // then RecruitBoard updatedRecruitBoard = recruitBoardRepository.findById(recruitBoard.getId()) - .orElseThrow(); + .orElseThrow(); assertThat(updatedRecruitBoard.getTitle()).isEqualTo(dto.title()); assertThat(updatedRecruitBoard.getContent()).isEqualTo(dto.content()); @@ -95,9 +96,9 @@ void updateRecruitBoard() { assertThat(recruitmentInfo.getAdmitted()).isEqualTo(dto.admitted()); assertThat(recruitmentInfo.getVolunteerStartDateTime()) - .isEqualToIgnoringNanos(dto.volunteerStartDateTime()); + .isEqualToIgnoringNanos(dto.volunteerStartDateTime()); assertThat(recruitmentInfo.getVolunteerEndDateTime()) - .isEqualToIgnoringNanos(dto.volunteerEndDateTime()); + .isEqualToIgnoringNanos(dto.volunteerEndDateTime()); } @DisplayName("봉사 모집글 위치를 수정할 수 있다") @@ -105,27 +106,27 @@ void updateRecruitBoard() { void updateRecruitBoardLocation() { // given RecruitBoardLocationUpdateRequestDto dto = RecruitBoardLocationUpdateRequestDto.builder() - .region("새로새로지역지역") - .address("새로새로주소주소") - .latitude(BigDecimal.valueOf(37.2222222)) - .longitude(BigDecimal.valueOf(127.2222222)) - .build(); + .region("새로새로지역지역") + .address("새로새로주소주소") + .latitude(BigDecimal.valueOf(37.2222222)) + .longitude(BigDecimal.valueOf(127.2222222)) + .build(); // when updateRecruitBoardService.updateRecruitBoardLocation(dto, recruitBoard.getId(), centerId); // then RecruitBoard updateRecruitBoard = recruitBoardRepository.findById(recruitBoard.getId()) - .orElseThrow(); + .orElseThrow(); Location updateLocation = locationRepository.findById(recruitBoard.getLocationId()) - .orElseThrow(); + .orElseThrow(); assertThat(updateRecruitBoard.getRecruitmentInfo().getRegion()).isEqualTo(dto.region()); assertThat(updateLocation.getAddress()).isEqualTo(dto.address()); assertThat(updateLocation.getLongitude()) - .isEqualByComparingTo(dto.longitude()); + .isEqualByComparingTo(dto.longitude()); assertThat(updateLocation.getLatitude()) - .isEqualByComparingTo(dto.latitude()); + .isEqualByComparingTo(dto.latitude()); } @DisplayName("봉사 모집글은 작성자만 수정할 수 있다") @@ -138,19 +139,19 @@ void updateRecruitBoardWhenCenterIdIsWrong() { LocalDateTime newEndDateTime = newStartDateTime.plusHours(3); String newImgUrl = "https://image.domain.com/updates"; RecruitBoardUpdateRequestDto dto = RecruitBoardUpdateRequestDto.builder() - .title("업데이트 제목") - .content("업데이트 내용") - .recruitmentCount(1111) - .volunteerStartDateTime(newStartDateTime) - .volunteerEndDateTime(newEndDateTime) - .volunteerCategory(ADMINISTRATIVE_SUPPORT) - .admitted(false) - .build(); + .title("업데이트 제목") + .content("업데이트 내용") + .recruitmentCount(1111) + .volunteerStartDateTime(newStartDateTime) + .volunteerEndDateTime(newEndDateTime) + .volunteerCategory(ADMINISTRATIVE_SUPPORT) + .admitted(false) + .build(); // when // then Assertions.assertThatThrownBy( - () -> updateRecruitBoardService.updateRecruitBoard(dto, id, wrongCenterId, newImgUrl) + () -> updateRecruitBoardService.updateRecruitBoard(dto, id, wrongCenterId, newImgUrl) ).isInstanceOf(BadRequestException.class); } @@ -165,7 +166,7 @@ void updateRecruitBoardStatus() { // when updateRecruitBoardService.updateRecruitBoardStatus(newStatus, recruitBoardId, centerId, - currentDateTime); + currentDateTime); // then RecruitBoard findBoard = recruitBoardRepository.findById(recruitBoardId).orElseThrow(); @@ -179,34 +180,33 @@ private static RecruitBoard createRecruitBoard(UUID centerId, Long locationId) { return createRecruitBoard(centerId, locationId, startDateTime, endDateTime); } - private static RecruitBoard createRecruitBoard(UUID centerId, Long locationId, - LocalDateTime startDateTime, - LocalDateTime endDateTime) { + private static RecruitBoard createRecruitBoard(UUID centerId, Long locationId, LocalDateTime startDateTime, LocalDateTime endDateTime) { RecruitmentInfo recruitmentInfo = RecruitmentInfo.builder() - .region("경기") - .recruitmentCount(1) - .volunteerStartDateTime(startDateTime) - .volunteerEndDateTime(endDateTime) - .volunteerCategory(OTHER) - .admitted(true) - .build(); + .region("경기") + .recruitmentCount(1) + .volunteerStartDateTime(startDateTime) + .volunteerEndDateTime(endDateTime) + .volunteerHours(1) + .volunteerCategory(OTHER) + .admitted(true) + .build(); return RecruitBoard.builder() - .centerId(centerId) - .locationId(locationId) - .title("봉사모집제목") - .content("봉사모집내용") - .imgUrl("https://image.domain.com/links") - .recruitmentInfo(recruitmentInfo) - .build(); + .centerId(centerId) + .locationId(locationId) + .title("봉사모집제목") + .content("봉사모집내용") + .imgUrl("https://image.domain.com/links") + .recruitmentInfo(recruitmentInfo) + .build(); } private static Location createLocation() { return Location.builder() - .address("주소주소") - .longitude(BigDecimal.valueOf(37.11111)) - .latitude(BigDecimal.valueOf(127.11111)) - .build(); + .address("주소주소") + .longitude(BigDecimal.valueOf(37.11111)) + .latitude(BigDecimal.valueOf(127.11111)) + .build(); } } diff --git a/src/test/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeServiceTest.java b/src/test/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeServiceTest.java index eaa3979e0..33a5f0a08 100644 --- a/src/test/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeServiceTest.java @@ -58,7 +58,7 @@ void settleVolunteerApplies() { VolunteerApply apply3 = createApply(volunteer3.getId(), board.getId()); volunteerApplyRepository.saveAll(List.of(apply1, apply2, apply3)); - int hour = board.getVolunteerHours().getHour(); + int hour = board.getRecruitmentInfo().getVolunteerHours(); VolunteerApplySettleRequestDto dto = VolunteerApplySettleRequestDto.builder() .ids(List.of(apply1.getId(), apply2.getId(), apply3.getId())) .build(); diff --git a/src/test/java/com/somemore/support/fixture/RecruitBoardFixture.java b/src/test/java/com/somemore/support/fixture/RecruitBoardFixture.java index d80c231f8..f28d81538 100644 --- a/src/test/java/com/somemore/support/fixture/RecruitBoardFixture.java +++ b/src/test/java/com/somemore/support/fixture/RecruitBoardFixture.java @@ -1,30 +1,32 @@ package com.somemore.support.fixture; -import static com.somemore.support.fixture.LocalDateTimeFixture.createStartDateTime; -import static com.somemore.domains.recruitboard.domain.RecruitStatus.CLOSED; -import static com.somemore.domains.recruitboard.domain.RecruitStatus.COMPLETED; -import static com.somemore.domains.recruitboard.domain.VolunteerCategory.OTHER; - import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.domain.RecruitStatus; import com.somemore.domains.recruitboard.domain.RecruitmentInfo; import com.somemore.domains.recruitboard.domain.VolunteerCategory; + import java.lang.reflect.Field; import java.time.LocalDateTime; import java.util.UUID; +import static com.somemore.domains.recruitboard.domain.RecruitStatus.CLOSED; +import static com.somemore.domains.recruitboard.domain.RecruitStatus.COMPLETED; +import static com.somemore.domains.recruitboard.domain.VolunteerCategory.OTHER; +import static com.somemore.support.fixture.LocalDateTimeFixture.createStartDateTime; + public class RecruitBoardFixture { - public static final String REGION = "경기"; - public static final int RECRUITMENT_COUNT = 1; - public static final LocalDateTime START_DATE_TIME = createStartDateTime(); - public static final LocalDateTime END_DATE_TIME = START_DATE_TIME.plusHours(1); - public static final boolean ADMITTED = true; - public static final long LOCATION_ID = 1L; - public static final String TITLE = "봉사모집제목"; - public static final String CONTENT = "봉사모집내용"; - public static final String IMG_URL = "https://image.domain.com/links"; - public static final VolunteerCategory VOLUNTEER_CATEGORY = OTHER; + private static final String REGION = "경기"; + private static final int RECRUITMENT_COUNT = 1; + private static final LocalDateTime START_DATE_TIME = createStartDateTime(); + private static final LocalDateTime END_DATE_TIME = START_DATE_TIME.plusHours(1); + private static final Integer VOLUNTEER_HOURS = 1; + private static final boolean ADMITTED = true; + private static final long LOCATION_ID = 1L; + private static final String TITLE = "봉사모집제목"; + private static final String CONTENT = "봉사모집내용"; + private static final String IMG_URL = "https://image.domain.com/links"; + private static final VolunteerCategory VOLUNTEER_CATEGORY = OTHER; private RecruitBoardFixture() { } @@ -36,6 +38,7 @@ public static RecruitBoard createRecruitBoard() { .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(START_DATE_TIME) .volunteerEndDateTime(END_DATE_TIME) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(VOLUNTEER_CATEGORY) .admitted(ADMITTED) .build(); @@ -57,6 +60,7 @@ public static RecruitBoard createRecruitBoard(String title) { .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(START_DATE_TIME) .volunteerEndDateTime(END_DATE_TIME) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(VOLUNTEER_CATEGORY) .admitted(ADMITTED) .build(); @@ -78,6 +82,7 @@ public static RecruitBoard createRecruitBoard(String title, UUID centerId, Long .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(START_DATE_TIME) .volunteerEndDateTime(END_DATE_TIME) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(VOLUNTEER_CATEGORY) .admitted(ADMITTED) .build(); @@ -99,6 +104,7 @@ public static RecruitBoard createRecruitBoard(String title, UUID centerId) { .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(START_DATE_TIME) .volunteerEndDateTime(END_DATE_TIME) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(VOLUNTEER_CATEGORY) .admitted(ADMITTED) .build(); @@ -120,6 +126,7 @@ public static RecruitBoard createRecruitBoard(VolunteerCategory category, UUID c .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(START_DATE_TIME) .volunteerEndDateTime(END_DATE_TIME) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(category) .admitted(ADMITTED) .build(); @@ -141,6 +148,7 @@ public static RecruitBoard createRecruitBoard(Boolean admitted, UUID centerId) { .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(START_DATE_TIME) .volunteerEndDateTime(END_DATE_TIME) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(VOLUNTEER_CATEGORY) .admitted(admitted) .build(); @@ -162,6 +170,7 @@ public static RecruitBoard createRecruitBoard(Long locationId) { .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(START_DATE_TIME) .volunteerEndDateTime(END_DATE_TIME) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(VOLUNTEER_CATEGORY) .admitted(ADMITTED) .build(); @@ -183,6 +192,7 @@ public static RecruitBoard createRecruitBoard(UUID centerId) { .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(START_DATE_TIME) .volunteerEndDateTime(END_DATE_TIME) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(VOLUNTEER_CATEGORY) .admitted(ADMITTED) .build(); @@ -204,6 +214,7 @@ public static RecruitBoard createRecruitBoard(UUID centerId, Long locationId) { .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(START_DATE_TIME) .volunteerEndDateTime(END_DATE_TIME) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(VOLUNTEER_CATEGORY) .admitted(ADMITTED) .build(); @@ -219,13 +230,14 @@ public static RecruitBoard createRecruitBoard(UUID centerId, Long locationId) { } public static RecruitBoard createRecruitBoard(String region, - VolunteerCategory volunteerCategory) { + VolunteerCategory volunteerCategory) { RecruitmentInfo recruitmentInfo = RecruitmentInfo.builder() .region(region) .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(START_DATE_TIME) .volunteerEndDateTime(END_DATE_TIME) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(volunteerCategory) .admitted(ADMITTED) .build(); @@ -247,6 +259,7 @@ public static RecruitBoard createRecruitBoard(Long locationId, String title) { .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(START_DATE_TIME) .volunteerEndDateTime(END_DATE_TIME) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(VOLUNTEER_CATEGORY) .admitted(ADMITTED) .build(); @@ -268,6 +281,7 @@ public static RecruitBoard createRecruitBoard(LocalDateTime start, LocalDateTime .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(start) .volunteerEndDateTime(end) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(VOLUNTEER_CATEGORY) .admitted(ADMITTED) .build(); @@ -283,12 +297,13 @@ public static RecruitBoard createRecruitBoard(LocalDateTime start, LocalDateTime } public static RecruitBoard createCompletedRecruitBoard(UUID centerId, - VolunteerCategory category) { + VolunteerCategory category) { RecruitmentInfo recruitmentInfo = RecruitmentInfo.builder() .region(REGION) .recruitmentCount(RECRUITMENT_COUNT) .volunteerStartDateTime(START_DATE_TIME) .volunteerEndDateTime(END_DATE_TIME) + .volunteerHours(VOLUNTEER_HOURS) .volunteerCategory(category) .admitted(ADMITTED) .build(); From 00076d5316692569c373daa2b1293b0cf5a865fd Mon Sep 17 00:00:00 2001 From: leebs0521 Date: Thu, 2 Jan 2025 15:15:03 +0900 Subject: [PATCH 03/12] =?UTF-8?q?feat(recruit-board):=20=EB=AA=A8=EC=A7=91?= =?UTF-8?q?=EA=B8=80=20Validator=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruitboard/domain/RecruitBoard.java | 2 +- .../validator/RecruitBoardValidator.java | 31 +++++++++++++++++++ .../global/exception/ExceptionMessage.java | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java diff --git a/src/main/java/com/somemore/domains/recruitboard/domain/RecruitBoard.java b/src/main/java/com/somemore/domains/recruitboard/domain/RecruitBoard.java index 38f5e7047..0927449b9 100644 --- a/src/main/java/com/somemore/domains/recruitboard/domain/RecruitBoard.java +++ b/src/main/java/com/somemore/domains/recruitboard/domain/RecruitBoard.java @@ -58,7 +58,7 @@ public RecruitBoard(UUID centerId, Long locationId, String title, String content this.imgUrl = imgUrl; } - public boolean isWriter(UUID centerId) { + public boolean isAuthor(UUID centerId) { return this.centerId.equals(centerId); } diff --git a/src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java b/src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java new file mode 100644 index 000000000..2a9e69186 --- /dev/null +++ b/src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java @@ -0,0 +1,31 @@ +package com.somemore.domains.recruitboard.service.validator; + +import com.somemore.domains.recruitboard.domain.RecruitBoard; +import com.somemore.global.exception.BadRequestException; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.util.UUID; + +import static com.somemore.global.exception.ExceptionMessage.INVALID_RECRUIT_BOARD_TIME; +import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; + +@Component +public class RecruitBoardValidator { + + public void validateRecruitBoardTime(LocalDateTime startDateTime, LocalDateTime endDateTime) { + if (endDateTime.isAfter(startDateTime)) { + return; + } + + throw new BadRequestException(INVALID_RECRUIT_BOARD_TIME); + } + + public void validateAuthor(RecruitBoard recruitBoard, UUID centerId) { + if (recruitBoard.isAuthor(centerId)) { + return; + } + + throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD.getMessage()); + } +} diff --git a/src/main/java/com/somemore/global/exception/ExceptionMessage.java b/src/main/java/com/somemore/global/exception/ExceptionMessage.java index 9cdd95b88..8136f9844 100644 --- a/src/main/java/com/somemore/global/exception/ExceptionMessage.java +++ b/src/main/java/com/somemore/global/exception/ExceptionMessage.java @@ -31,6 +31,7 @@ public enum ExceptionMessage { // RECRUIT BOARD NOT_EXISTS_RECRUIT_BOARD("존재하지 않는 봉사 모집글입니다."), UNAUTHORIZED_RECRUIT_BOARD("해당 봉사 모집글에 권한이 없습니다."), + INVALID_RECRUIT_BOARD_TIME("종료 시간은 시작 시간보다 이후여야 합니다."), // IMAGE UPLOAD_FAILED("파일 업로드에 실패했습니다."), From 0d317afadf578fcbe166c8ae91904dd17f274bb4 Mon Sep 17 00:00:00 2001 From: leebs0521 Date: Thu, 2 Jan 2025 15:15:13 +0900 Subject: [PATCH 04/12] =?UTF-8?q?test(recruit-board):=20=EB=AA=A8=EC=A7=91?= =?UTF-8?q?=EA=B8=80=20Validator=20=EC=B6=94=EA=B0=80=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruitboard/domain/RecruitBoardTest.java | 8 +-- .../validator/RecruitBoardValidatorTest.java | 54 +++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidatorTest.java diff --git a/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java b/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java index fa37b1d82..c47561da8 100644 --- a/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java @@ -80,13 +80,13 @@ void updateWithRegion() { @DisplayName("올바른 기관 식별 값이 주어지면 작성자인지 확인할 수 있다") @Test - void isWriterWithCorrectCenterId() { + void isAuthorWithCorrectCenterId() { // given UUID centerId = UUID.randomUUID(); RecruitBoard recruitBoard = createRecruitBoard(centerId); // when - boolean isWriter = recruitBoard.isWriter(centerId); + boolean isWriter = recruitBoard.isAuthor(centerId); // then assertThat(isWriter).isTrue(); @@ -94,13 +94,13 @@ void isWriterWithCorrectCenterId() { @DisplayName("잘못된 기관 식별 값이 주어지면 잘못된 작성자인 확인할 수있다.") @Test - void isNotWriterWithWrongCenterId() { + void isNotAuthorWithWrongCenterId() { UUID centerId = UUID.randomUUID(); UUID wrongId = UUID.randomUUID(); RecruitBoard recruitBoard = createRecruitBoard(centerId); // when - boolean isWriter = recruitBoard.isWriter(wrongId); + boolean isWriter = recruitBoard.isAuthor(wrongId); // then assertThat(isWriter).isFalse(); diff --git a/src/test/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidatorTest.java b/src/test/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidatorTest.java new file mode 100644 index 000000000..7f33306be --- /dev/null +++ b/src/test/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidatorTest.java @@ -0,0 +1,54 @@ +package com.somemore.domains.recruitboard.service.validator; + +import com.somemore.domains.recruitboard.domain.RecruitBoard; +import com.somemore.global.exception.BadRequestException; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import java.time.LocalDateTime; +import java.util.UUID; + +import static com.somemore.global.exception.ExceptionMessage.INVALID_RECRUIT_BOARD_TIME; +import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; +import static com.somemore.support.fixture.LocalDateTimeFixture.createStartDateTime; +import static com.somemore.support.fixture.RecruitBoardFixture.createRecruitBoard; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class RecruitBoardValidatorTest { + + private final RecruitBoardValidator validator = new RecruitBoardValidator(); + + @DisplayName("봉사 종료 시간이 시작 시간과 같거나 빠르면, 봉사 모집글 생성 시 에러가 발생한다") + @ParameterizedTest + @ValueSource(longs = {0, -1}) + void createRecruitBoardWithInValidVolunteerTime(long minutesOffset) { + // given + LocalDateTime now = createStartDateTime(); + LocalDateTime endDateTime = now.plusMinutes(minutesOffset); + + // when & then + assertThatThrownBy( + () -> validator.validateRecruitBoardTime(now, endDateTime)) + .isInstanceOf(BadRequestException.class) + .hasMessage(INVALID_RECRUIT_BOARD_TIME.getMessage()); + + } + + @DisplayName("모집글 작성자가 아닌 경우 에러가 발생한다") + @Test + void validateAuthor() { + // given + UUID wrongCenterId = UUID.randomUUID(); + RecruitBoard board = createRecruitBoard(UUID.randomUUID()); + + // when + // then + assertThatThrownBy( + () -> validator.validateAuthor(board, wrongCenterId)) + .isInstanceOf(BadRequestException.class) + .hasMessage(UNAUTHORIZED_RECRUIT_BOARD.getMessage()); + } + +} From 9cad0419f55f2cc5bfa9189ed31c6f3ee4b1e3e2 Mon Sep 17 00:00:00 2001 From: leebs0521 Date: Thu, 2 Jan 2025 15:15:37 +0900 Subject: [PATCH 05/12] =?UTF-8?q?refactor(recruit-board):=20=EB=AA=A8?= =?UTF-8?q?=EC=A7=91=EA=B8=80=20Validator=20=EC=B6=94=EA=B0=80=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/DeleteRecruitBoardService.java | 24 ++++----- .../command/UpdateRecruitBoardService.java | 51 +++++++------------ .../SettleVolunteerApplyFacadeService.java | 2 +- .../VolunteerApplyQueryFacadeService.java | 18 +++---- .../VolunteerApplyStatusChangeService.java | 12 ++--- 5 files changed, 42 insertions(+), 65 deletions(-) diff --git a/src/main/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardService.java b/src/main/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardService.java index bb454aa26..e23d71a5a 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardService.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardService.java @@ -1,41 +1,35 @@ package com.somemore.domains.recruitboard.service.command; -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD; -import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; - -import com.somemore.global.exception.BadRequestException; import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; +import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator; import com.somemore.domains.recruitboard.usecase.command.DeleteRecruitBoardUseCase; -import java.util.UUID; +import com.somemore.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.UUID; + +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD; + @RequiredArgsConstructor @Transactional @Service public class DeleteRecruitBoardService implements DeleteRecruitBoardUseCase { private final RecruitBoardRepository recruitBoardRepository; + private final RecruitBoardValidator recruitBoardValidator; @Override public void deleteRecruitBoard(UUID centerId, Long recruitBoardId) { RecruitBoard recruitBoard = recruitBoardRepository.findById(recruitBoardId).orElseThrow( - () -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage()) + () -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage()) ); - validateWriter(recruitBoard, centerId); + recruitBoardValidator.validateAuthor(recruitBoard, centerId); recruitBoard.markAsDeleted(); - recruitBoardRepository.save(recruitBoard); } - private void validateWriter(RecruitBoard recruitBoard, UUID centerId) { - if (recruitBoard.isWriter(centerId)) { - return; - } - - throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD.getMessage()); - } } diff --git a/src/main/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardService.java b/src/main/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardService.java index aaeb6af35..59048b1d4 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardService.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardService.java @@ -1,22 +1,22 @@ package com.somemore.domains.recruitboard.service.command; -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD; -import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; - -import com.somemore.global.exception.BadRequestException; import com.somemore.domains.location.usecase.command.UpdateLocationUseCase; import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.domain.RecruitStatus; import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto; import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto; import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; +import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator; import com.somemore.domains.recruitboard.usecase.command.UpdateRecruitBoardUseCase; -import java.time.LocalDateTime; -import java.util.UUID; +import com.somemore.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; +import java.util.UUID; + +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD; @RequiredArgsConstructor @Transactional @@ -24,57 +24,42 @@ public class UpdateRecruitBoardService implements UpdateRecruitBoardUseCase { private final RecruitBoardRepository recruitBoardRepository; + private final RecruitBoardValidator recruitBoardValidator; private final UpdateLocationUseCase updateLocationUseCase; @Override - public void updateRecruitBoard( - RecruitBoardUpdateRequestDto requestDto, - Long recruitBoardId, - UUID centerId, - String imgUrl) { - + public void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long recruitBoardId, UUID centerId, String imgUrl) { RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId); - validateWriter(recruitBoard, centerId); - recruitBoard.updateWith(requestDto, imgUrl); + recruitBoardValidator.validateAuthor(recruitBoard, centerId); + recruitBoardValidator.validateRecruitBoardTime(dto.volunteerStartDateTime(), dto.volunteerEndDateTime()); - recruitBoardRepository.save(recruitBoard); + recruitBoard.updateWith(dto, imgUrl); } @Override - public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, - Long recruitBoardId, UUID centerId) { - + public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, Long recruitBoardId, + UUID centerId) { RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId); - validateWriter(recruitBoard, centerId); + recruitBoardValidator.validateAuthor(recruitBoard, centerId); - updateLocationUseCase.updateLocation(requestDto.toLocationUpdateRequestDto(), - recruitBoard.getLocationId()); + updateLocationUseCase.updateLocation(requestDto.toLocationUpdateRequestDto(), recruitBoard.getLocationId()); recruitBoard.updateWith(requestDto.region()); - recruitBoardRepository.save(recruitBoard); } @Override public void updateRecruitBoardStatus(RecruitStatus status, Long recruitBoardId, UUID centerId, - LocalDateTime currentDateTime) { + LocalDateTime currentDateTime) { RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId); - validateWriter(recruitBoard, centerId); + recruitBoardValidator.validateAuthor(recruitBoard, centerId); recruitBoard.changeRecruitStatus(status, currentDateTime); - recruitBoardRepository.save(recruitBoard); } private RecruitBoard getRecruitBoard(Long recruitBoardId) { return recruitBoardRepository.findById(recruitBoardId).orElseThrow( - () -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage()) + () -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage()) ); } - private void validateWriter(RecruitBoard recruitBoard, UUID centerId) { - if (recruitBoard.isWriter(centerId)) { - return; - } - - throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD.getMessage()); - } } diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java index f1b24b7f0..787c1059b 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java @@ -52,7 +52,7 @@ public void settleVolunteerApplies(VolunteerApplySettleRequestDto dto, UUID cent } private void validateAuth(RecruitBoard recruitBoard, UUID centerId) { - if (recruitBoard.isWriter(centerId)) { + if (recruitBoard.isAuthor(centerId)) { return; } throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD); diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java index 6d62e8337..cfdee87de 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java @@ -1,27 +1,27 @@ package com.somemore.domains.volunteerapply.service; -import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; - import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; +import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; +import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.dto.condition.VolunteerApplySearchCondition; import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyRecruitInfoResponseDto; import com.somemore.domains.volunteerapply.dto.response.VolunteerApplyVolunteerInfoResponseDto; import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryFacadeUseCase; import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase; import com.somemore.global.exception.BadRequestException; -import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; -import com.somemore.domains.volunteerapply.domain.VolunteerApply; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; + +import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; @RequiredArgsConstructor @Transactional(readOnly = true) @@ -68,7 +68,7 @@ public Page getVolunteerAppliesByVolunteer private void validateAuthorization(Long recruitId, UUID centerId) { RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(recruitId); - if (recruitBoard.isWriter(centerId)) { + if (recruitBoard.isAuthor(centerId)) { return; } diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java index de238c2d3..fcfc0fc34 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java @@ -2,25 +2,23 @@ import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; +import com.somemore.domains.volunteerapply.domain.ApplyStatus; +import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.event.VolunteerApplyStatusChangeEvent; import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository; import com.somemore.domains.volunteerapply.usecase.ApproveVolunteerApplyUseCase; import com.somemore.domains.volunteerapply.usecase.RejectVolunteerApplyUseCase; import com.somemore.global.common.event.ServerEventPublisher; import com.somemore.global.exception.BadRequestException; -import com.somemore.domains.volunteerapply.domain.ApplyStatus; -import com.somemore.domains.volunteerapply.domain.VolunteerApply; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.UUID; -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER_APPLY; -import static com.somemore.global.exception.ExceptionMessage.RECRUIT_BOARD_ALREADY_COMPLETED; -import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED; import static com.somemore.domains.volunteerapply.domain.ApplyStatus.REJECTED; +import static com.somemore.global.exception.ExceptionMessage.*; @RequiredArgsConstructor @Transactional @@ -61,7 +59,7 @@ private VolunteerApply getVolunteerApply(Long id) { } private void validateWriter(RecruitBoard recruitBoard, UUID centerId) { - if (recruitBoard.isWriter(centerId)) { + if (recruitBoard.isAuthor(centerId)) { return; } throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD); @@ -81,4 +79,4 @@ private void publishVolunteerApplyStatusChangeEvent(VolunteerApply apply, } serverEventPublisher.publish(VolunteerApplyStatusChangeEvent.from(apply, recruitBoard, oldStatus)); } -} \ No newline at end of file +} From 82af9103b05a5c8d02fbd1f772111fc865cf0526 Mon Sep 17 00:00:00 2001 From: leebs0521 Date: Thu, 2 Jan 2025 15:15:50 +0900 Subject: [PATCH 06/12] =?UTF-8?q?test(recruit-board):=20=EB=AA=A8=EC=A7=91?= =?UTF-8?q?=EA=B8=80=20Validator=20=EC=B6=94=EA=B0=80=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeleteRecruitBoardServiceTest.java | 28 +----------- .../UpdateRecruitBoardServiceTest.java | 44 ++----------------- 2 files changed, 6 insertions(+), 66 deletions(-) diff --git a/src/test/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardServiceTest.java b/src/test/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardServiceTest.java index 3c429f32d..366dcaa49 100644 --- a/src/test/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardServiceTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardServiceTest.java @@ -2,15 +2,13 @@ import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.domain.RecruitmentInfo; -import com.somemore.domains.recruitboard.repository.RecruitBoardJpaRepository; import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; -import com.somemore.global.exception.BadRequestException; import com.somemore.support.IntegrationTestSupport; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; 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.time.LocalDateTime; import java.util.Optional; @@ -19,8 +17,8 @@ import static com.somemore.domains.recruitboard.domain.VolunteerCategory.OTHER; import static com.somemore.support.fixture.LocalDateTimeFixture.createStartDateTime; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +@Transactional class DeleteRecruitBoardServiceTest extends IntegrationTestSupport { @Autowired @@ -29,9 +27,6 @@ class DeleteRecruitBoardServiceTest extends IntegrationTestSupport { @Autowired private RecruitBoardRepository recruitBoardRepository; - @Autowired - private RecruitBoardJpaRepository recruitBoardJpaRepository; - private RecruitBoard recruitBoard; @BeforeEach @@ -40,11 +35,6 @@ void setUp() { recruitBoardRepository.save(recruitBoard); } - @AfterEach - void tearDown() { - recruitBoardJpaRepository.deleteAllInBatch(); - } - @DisplayName("봉사 모집글 식별값으로 모집글을 삭제할 수 있다") @Test void deleteRecruitBoard() { @@ -61,20 +51,6 @@ void deleteRecruitBoard() { assertThat(findBoard).isEmpty(); } - @DisplayName("모집글 삭제시 작성자가 아니면 에러가 발생한다") - @Test - void deleteRecruitBoardWithWrongCenterId() { - // given - UUID wrongCenterId = UUID.randomUUID(); - Long recruitBoardId = recruitBoard.getId(); - - // when - // then - assertThatThrownBy( - () -> deleteRecruitBoardService.deleteRecruitBoard(wrongCenterId, recruitBoardId) - ).isInstanceOf(BadRequestException.class); - } - private static RecruitBoard createRecruitBoard() { LocalDateTime startDateTime = createStartDateTime(); diff --git a/src/test/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardServiceTest.java b/src/test/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardServiceTest.java index 4e9c92798..f1b8d5361 100644 --- a/src/test/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardServiceTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardServiceTest.java @@ -9,14 +9,12 @@ import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto; import com.somemore.domains.recruitboard.repository.RecruitBoardJpaRepository; import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; -import com.somemore.global.exception.BadRequestException; import com.somemore.support.IntegrationTestSupport; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; 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.math.BigDecimal; import java.time.LocalDateTime; @@ -27,6 +25,7 @@ import static com.somemore.support.fixture.LocalDateTimeFixture.*; import static org.assertj.core.api.Assertions.assertThat; +@Transactional class UpdateRecruitBoardServiceTest extends IntegrationTestSupport { @Autowired @@ -53,12 +52,6 @@ void setUp() { recruitBoardJpaRepository.saveAndFlush(recruitBoard); } - @AfterEach - void tearDown() { - recruitBoardJpaRepository.deleteAllInBatch(); - locationRepository.deleteAllInBatch(); - } - @DisplayName("봉사 모집글의 데이터를 업데이트하면 저장소에 반영된다.") @Test void updateRecruitBoard() { @@ -79,8 +72,7 @@ void updateRecruitBoard() { .build(); // when - updateRecruitBoardService.updateRecruitBoard(dto, recruitBoard.getId(), centerId, - newImgUrl); + updateRecruitBoardService.updateRecruitBoard(dto, recruitBoard.getId(), centerId, newImgUrl); // then RecruitBoard updatedRecruitBoard = recruitBoardRepository.findById(recruitBoard.getId()) @@ -129,33 +121,6 @@ void updateRecruitBoardLocation() { .isEqualByComparingTo(dto.latitude()); } - @DisplayName("봉사 모집글은 작성자만 수정할 수 있다") - @Test - void updateRecruitBoardWhenCenterIdIsWrong() { - // given - Long id = recruitBoard.getId(); - UUID wrongCenterId = UUID.randomUUID(); - LocalDateTime newStartDateTime = createUpdateStartDateTime(); - LocalDateTime newEndDateTime = newStartDateTime.plusHours(3); - String newImgUrl = "https://image.domain.com/updates"; - RecruitBoardUpdateRequestDto dto = RecruitBoardUpdateRequestDto.builder() - .title("업데이트 제목") - .content("업데이트 내용") - .recruitmentCount(1111) - .volunteerStartDateTime(newStartDateTime) - .volunteerEndDateTime(newEndDateTime) - .volunteerCategory(ADMINISTRATIVE_SUPPORT) - .admitted(false) - .build(); - - // when - // then - Assertions.assertThatThrownBy( - () -> updateRecruitBoardService.updateRecruitBoard(dto, id, wrongCenterId, newImgUrl) - ).isInstanceOf(BadRequestException.class); - - } - @DisplayName("봉사 모집글 상태를 변경할 수 있다") @Test void updateRecruitBoardStatus() { @@ -165,8 +130,7 @@ void updateRecruitBoardStatus() { LocalDateTime currentDateTime = createCurrentDateTime(); // when - updateRecruitBoardService.updateRecruitBoardStatus(newStatus, recruitBoardId, centerId, - currentDateTime); + updateRecruitBoardService.updateRecruitBoardStatus(newStatus, recruitBoardId, centerId, currentDateTime); // then RecruitBoard findBoard = recruitBoardRepository.findById(recruitBoardId).orElseThrow(); From c5deb1f1d46d15bce61ab680767a9b05f2eb3652 Mon Sep 17 00:00:00 2001 From: leebs0521 Date: Thu, 2 Jan 2025 15:23:23 +0900 Subject: [PATCH 07/12] =?UTF-8?q?refactor(recruit-board):=20=EB=AA=A8?= =?UTF-8?q?=EC=A7=91=EA=B8=80=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20QueryUseCase?= =?UTF-8?q?=20=EC=9D=98=EC=A1=B4=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/DeleteRecruitBoardService.java | 10 +++---- .../command/UpdateRecruitBoardService.java | 29 ++++++------------- .../validator/RecruitBoardValidator.java | 2 +- .../command/DeleteRecruitBoardUseCase.java | 2 +- .../command/UpdateRecruitBoardUseCase.java | 23 +++------------ 5 files changed, 19 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardService.java b/src/main/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardService.java index e23d71a5a..76c5b82c1 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardService.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardService.java @@ -4,6 +4,7 @@ import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator; import com.somemore.domains.recruitboard.usecase.command.DeleteRecruitBoardUseCase; +import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; import com.somemore.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -18,15 +19,12 @@ @Service public class DeleteRecruitBoardService implements DeleteRecruitBoardUseCase { - private final RecruitBoardRepository recruitBoardRepository; + private final RecruitBoardQueryUseCase recruitBoardQueryUseCase; private final RecruitBoardValidator recruitBoardValidator; @Override - public void deleteRecruitBoard(UUID centerId, Long recruitBoardId) { - RecruitBoard recruitBoard = recruitBoardRepository.findById(recruitBoardId).orElseThrow( - () -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage()) - ); - + public void deleteRecruitBoard(UUID centerId, Long id) { + RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(id); recruitBoardValidator.validateAuthor(recruitBoard, centerId); recruitBoard.markAsDeleted(); diff --git a/src/main/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardService.java b/src/main/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardService.java index 59048b1d4..bb8b7aabf 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardService.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardService.java @@ -5,10 +5,9 @@ import com.somemore.domains.recruitboard.domain.RecruitStatus; import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto; import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto; -import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator; import com.somemore.domains.recruitboard.usecase.command.UpdateRecruitBoardUseCase; -import com.somemore.global.exception.BadRequestException; +import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,20 +15,18 @@ import java.time.LocalDateTime; import java.util.UUID; -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD; - @RequiredArgsConstructor @Transactional @Service public class UpdateRecruitBoardService implements UpdateRecruitBoardUseCase { - private final RecruitBoardRepository recruitBoardRepository; - private final RecruitBoardValidator recruitBoardValidator; + private final RecruitBoardQueryUseCase recruitBoardQueryUseCase; private final UpdateLocationUseCase updateLocationUseCase; + private final RecruitBoardValidator recruitBoardValidator; @Override - public void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long recruitBoardId, UUID centerId, String imgUrl) { - RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId); + public void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long id, UUID centerId, String imgUrl) { + RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(id); recruitBoardValidator.validateAuthor(recruitBoard, centerId); recruitBoardValidator.validateRecruitBoardTime(dto.volunteerStartDateTime(), dto.volunteerEndDateTime()); @@ -37,9 +34,8 @@ public void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long recruitBoa } @Override - public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, Long recruitBoardId, - UUID centerId) { - RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId); + public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, Long id, UUID centerId) { + RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(id); recruitBoardValidator.validateAuthor(recruitBoard, centerId); updateLocationUseCase.updateLocation(requestDto.toLocationUpdateRequestDto(), recruitBoard.getLocationId()); @@ -48,18 +44,11 @@ public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requ } @Override - public void updateRecruitBoardStatus(RecruitStatus status, Long recruitBoardId, UUID centerId, - LocalDateTime currentDateTime) { - RecruitBoard recruitBoard = getRecruitBoard(recruitBoardId); + public void updateRecruitBoardStatus(RecruitStatus status, Long id, UUID centerId, LocalDateTime currentDateTime) { + RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(id); recruitBoardValidator.validateAuthor(recruitBoard, centerId); recruitBoard.changeRecruitStatus(status, currentDateTime); } - private RecruitBoard getRecruitBoard(Long recruitBoardId) { - return recruitBoardRepository.findById(recruitBoardId).orElseThrow( - () -> new BadRequestException(NOT_EXISTS_RECRUIT_BOARD.getMessage()) - ); - } - } diff --git a/src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java b/src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java index 2a9e69186..196a75df1 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java @@ -26,6 +26,6 @@ public void validateAuthor(RecruitBoard recruitBoard, UUID centerId) { return; } - throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD.getMessage()); + throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD); } } diff --git a/src/main/java/com/somemore/domains/recruitboard/usecase/command/DeleteRecruitBoardUseCase.java b/src/main/java/com/somemore/domains/recruitboard/usecase/command/DeleteRecruitBoardUseCase.java index f73e0760c..e04f2538d 100644 --- a/src/main/java/com/somemore/domains/recruitboard/usecase/command/DeleteRecruitBoardUseCase.java +++ b/src/main/java/com/somemore/domains/recruitboard/usecase/command/DeleteRecruitBoardUseCase.java @@ -4,5 +4,5 @@ public interface DeleteRecruitBoardUseCase { - void deleteRecruitBoard(UUID centerId, Long recruitBoardId); + void deleteRecruitBoard(UUID centerId, Long id); } diff --git a/src/main/java/com/somemore/domains/recruitboard/usecase/command/UpdateRecruitBoardUseCase.java b/src/main/java/com/somemore/domains/recruitboard/usecase/command/UpdateRecruitBoardUseCase.java index 358f7a767..51986a037 100644 --- a/src/main/java/com/somemore/domains/recruitboard/usecase/command/UpdateRecruitBoardUseCase.java +++ b/src/main/java/com/somemore/domains/recruitboard/usecase/command/UpdateRecruitBoardUseCase.java @@ -3,29 +3,14 @@ import com.somemore.domains.recruitboard.domain.RecruitStatus; import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto; import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto; + import java.time.LocalDateTime; import java.util.UUID; public interface UpdateRecruitBoardUseCase { + void updateRecruitBoard(RecruitBoardUpdateRequestDto requestDto, Long id, UUID centerId, String imgUrl); - void updateRecruitBoard( - RecruitBoardUpdateRequestDto requestDto, - Long recruitBoardId, - UUID centerId, - String imgUrl - ); - - void updateRecruitBoardLocation( - RecruitBoardLocationUpdateRequestDto requestDto, - Long recruitBoardId, - UUID centerId - ); - - void updateRecruitBoardStatus( - RecruitStatus status, - Long recruitBoardId, - UUID centerId, - LocalDateTime currentDateTime - ); + void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, Long id, UUID centerId); + void updateRecruitBoardStatus(RecruitStatus status, Long id, UUID centerId, LocalDateTime currentDateTime); } From c47c5c7022762f0284aab765e902297c4f734bc9 Mon Sep 17 00:00:00 2001 From: leebs0521 Date: Thu, 2 Jan 2025 15:28:02 +0900 Subject: [PATCH 08/12] =?UTF-8?q?refactor(recruit-board):=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD(qu?= =?UTF-8?q?ery,=20command=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RecruitBoardCommandApiController.java | 31 +++++++------------ .../RecruitBoardQueryApiController.java | 21 ++++++------- .../CreateRecruitBoardService.java | 4 +-- .../DeleteRecruitBoardService.java | 10 ++---- .../RecruitBoardDocumentService.java | 0 .../{query => }/RecruitBoardQueryService.java | 20 ++++++------ .../UpdateRecruitBoardService.java | 6 ++-- .../CreateRecruitBoardUseCase.java | 3 +- .../DeleteRecruitBoardUseCase.java | 2 +- .../RecruitBoardDocumentUseCase.java | 0 .../{query => }/RecruitBoardQueryUseCase.java | 7 +++-- .../UpdateRecruitBoardUseCase.java | 2 +- .../VolunteerDetailAccessValidatorImpl.java | 2 +- .../service/ApplyVolunteerApplyService.java | 20 ++++++------ .../SettleVolunteerApplyFacadeService.java | 2 +- .../VolunteerApplyQueryFacadeService.java | 2 +- .../VolunteerApplyStatusChangeService.java | 2 +- .../RecruitBoardCommandApiControllerTest.java | 6 ++-- .../RecruitBoardQueryApiControllerTest.java | 25 +++++++-------- .../CreateRecruitBoardServiceTest.java | 2 +- .../DeleteRecruitBoardServiceTest.java | 2 +- .../RecruitBoardDocumentServiceTest.java | 0 .../RecruitBoardQueryServiceTest.java | 2 +- .../UpdateRecruitBoardServiceTest.java | 2 +- ...VolunteerApplyStatusChangeServiceTest.java | 2 +- ...VolunteerApplyStatusChangeServiceTest.java | 2 +- 26 files changed, 82 insertions(+), 95 deletions(-) rename src/main/java/com/somemore/domains/recruitboard/service/{command => }/CreateRecruitBoardService.java (93%) rename src/main/java/com/somemore/domains/recruitboard/service/{command => }/DeleteRecruitBoardService.java (65%) rename src/main/java/com/somemore/domains/recruitboard/service/{query => }/RecruitBoardDocumentService.java (100%) rename src/main/java/com/somemore/domains/recruitboard/service/{query => }/RecruitBoardQueryService.java (94%) rename src/main/java/com/somemore/domains/recruitboard/service/{command => }/UpdateRecruitBoardService.java (90%) rename src/main/java/com/somemore/domains/recruitboard/usecase/{command => }/CreateRecruitBoardUseCase.java (81%) rename src/main/java/com/somemore/domains/recruitboard/usecase/{command => }/DeleteRecruitBoardUseCase.java (68%) rename src/main/java/com/somemore/domains/recruitboard/usecase/{query => }/RecruitBoardDocumentUseCase.java (100%) rename src/main/java/com/somemore/domains/recruitboard/usecase/{query => }/RecruitBoardQueryUseCase.java (89%) rename src/main/java/com/somemore/domains/recruitboard/usecase/{command => }/UpdateRecruitBoardUseCase.java (91%) rename src/test/java/com/somemore/domains/recruitboard/service/{command => }/CreateRecruitBoardServiceTest.java (98%) rename src/test/java/com/somemore/domains/recruitboard/service/{command => }/DeleteRecruitBoardServiceTest.java (97%) rename src/test/java/com/somemore/domains/recruitboard/service/{query => }/RecruitBoardDocumentServiceTest.java (100%) rename src/test/java/com/somemore/domains/recruitboard/service/{query => }/RecruitBoardQueryServiceTest.java (99%) rename src/test/java/com/somemore/domains/recruitboard/service/{command => }/UpdateRecruitBoardServiceTest.java (99%) diff --git a/src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiController.java b/src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiController.java index b4ed2d624..7f4f401d9 100644 --- a/src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiController.java +++ b/src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiController.java @@ -1,37 +1,30 @@ package com.somemore.domains.recruitboard.controller; -import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; - +import com.somemore.domains.recruitboard.dto.request.RecruitBoardCreateRequestDto; +import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto; +import com.somemore.domains.recruitboard.dto.request.RecruitBoardStatusUpdateRequestDto; import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto; -import com.somemore.domains.recruitboard.usecase.command.CreateRecruitBoardUseCase; -import com.somemore.domains.recruitboard.usecase.command.DeleteRecruitBoardUseCase; -import com.somemore.domains.recruitboard.usecase.command.UpdateRecruitBoardUseCase; +import com.somemore.domains.recruitboard.usecase.CreateRecruitBoardUseCase; +import com.somemore.domains.recruitboard.usecase.DeleteRecruitBoardUseCase; +import com.somemore.domains.recruitboard.usecase.UpdateRecruitBoardUseCase; import com.somemore.global.auth.annotation.CurrentUser; import com.somemore.global.common.response.ApiResponse; import com.somemore.global.imageupload.dto.ImageUploadRequestDto; import com.somemore.global.imageupload.usecase.ImageUploadUseCase; -import com.somemore.domains.recruitboard.dto.request.RecruitBoardCreateRequestDto; -import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto; -import com.somemore.domains.recruitboard.dto.request.RecruitBoardStatusUpdateRequestDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; -import java.time.LocalDateTime; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.security.access.annotation.Secured; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; -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.RequestPart; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.time.LocalDateTime; +import java.util.UUID; + +import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; + @Tag(name = "Recruit Board Command API", description = "봉사 활동 모집글 생성 수정 삭제 API") @RequiredArgsConstructor @RequestMapping("/api") diff --git a/src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardQueryApiController.java b/src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardQueryApiController.java index 4f9567fbb..d39ff1d84 100644 --- a/src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardQueryApiController.java +++ b/src/main/java/com/somemore/domains/recruitboard/controller/RecruitBoardQueryApiController.java @@ -1,29 +1,26 @@ package com.somemore.domains.recruitboard.controller; -import static org.springframework.data.domain.Sort.Direction.DESC; - -import com.somemore.domains.recruitboard.dto.condition.RecruitBoardNearByCondition; -import com.somemore.domains.recruitboard.dto.condition.RecruitBoardSearchCondition; -import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; -import com.somemore.global.common.response.ApiResponse; import com.somemore.domains.recruitboard.domain.RecruitStatus; import com.somemore.domains.recruitboard.domain.VolunteerCategory; +import com.somemore.domains.recruitboard.dto.condition.RecruitBoardNearByCondition; +import com.somemore.domains.recruitboard.dto.condition.RecruitBoardSearchCondition; import com.somemore.domains.recruitboard.dto.response.RecruitBoardDetailResponseDto; import com.somemore.domains.recruitboard.dto.response.RecruitBoardResponseDto; import com.somemore.domains.recruitboard.dto.response.RecruitBoardWithCenterResponseDto; import com.somemore.domains.recruitboard.dto.response.RecruitBoardWithLocationResponseDto; +import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; +import com.somemore.global.common.response.ApiResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.UUID; + +import static org.springframework.data.domain.Sort.Direction.DESC; @Tag(name = "Recruit Board Query API", description = "봉사 활동 모집 조회 관련 API") @RequiredArgsConstructor diff --git a/src/main/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardService.java b/src/main/java/com/somemore/domains/recruitboard/service/CreateRecruitBoardService.java similarity index 93% rename from src/main/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardService.java rename to src/main/java/com/somemore/domains/recruitboard/service/CreateRecruitBoardService.java index 2d900bc5b..fcb3e3440 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardService.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/CreateRecruitBoardService.java @@ -1,4 +1,4 @@ -package com.somemore.domains.recruitboard.service.command; +package com.somemore.domains.recruitboard.service; import com.somemore.domains.location.usecase.command.CreateLocationUseCase; import com.somemore.domains.recruitboard.domain.RecruitBoard; @@ -6,7 +6,7 @@ import com.somemore.domains.recruitboard.event.CreateRecruitBoardEvent; import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator; -import com.somemore.domains.recruitboard.usecase.command.CreateRecruitBoardUseCase; +import com.somemore.domains.recruitboard.usecase.CreateRecruitBoardUseCase; import com.somemore.global.common.event.DomainEventSubType; import com.somemore.global.common.event.ServerEventPublisher; import com.somemore.global.common.event.ServerEventType; diff --git a/src/main/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardService.java b/src/main/java/com/somemore/domains/recruitboard/service/DeleteRecruitBoardService.java similarity index 65% rename from src/main/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardService.java rename to src/main/java/com/somemore/domains/recruitboard/service/DeleteRecruitBoardService.java index 76c5b82c1..485e1ef8d 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardService.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/DeleteRecruitBoardService.java @@ -1,19 +1,15 @@ -package com.somemore.domains.recruitboard.service.command; +package com.somemore.domains.recruitboard.service; import com.somemore.domains.recruitboard.domain.RecruitBoard; -import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator; -import com.somemore.domains.recruitboard.usecase.command.DeleteRecruitBoardUseCase; -import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; -import com.somemore.global.exception.BadRequestException; +import com.somemore.domains.recruitboard.usecase.DeleteRecruitBoardUseCase; +import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.UUID; -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD; - @RequiredArgsConstructor @Transactional @Service diff --git a/src/main/java/com/somemore/domains/recruitboard/service/query/RecruitBoardDocumentService.java b/src/main/java/com/somemore/domains/recruitboard/service/RecruitBoardDocumentService.java similarity index 100% rename from src/main/java/com/somemore/domains/recruitboard/service/query/RecruitBoardDocumentService.java rename to src/main/java/com/somemore/domains/recruitboard/service/RecruitBoardDocumentService.java diff --git a/src/main/java/com/somemore/domains/recruitboard/service/query/RecruitBoardQueryService.java b/src/main/java/com/somemore/domains/recruitboard/service/RecruitBoardQueryService.java similarity index 94% rename from src/main/java/com/somemore/domains/recruitboard/service/query/RecruitBoardQueryService.java rename to src/main/java/com/somemore/domains/recruitboard/service/RecruitBoardQueryService.java index 0172e58c3..151146bc4 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/query/RecruitBoardQueryService.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/RecruitBoardQueryService.java @@ -1,13 +1,9 @@ -package com.somemore.domains.recruitboard.service.query; - -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD; +package com.somemore.domains.recruitboard.service; import com.somemore.domains.center.usecase.query.CenterQueryUseCase; +import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.dto.condition.RecruitBoardNearByCondition; import com.somemore.domains.recruitboard.dto.condition.RecruitBoardSearchCondition; -import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; -import com.somemore.global.exception.BadRequestException; -import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.dto.response.RecruitBoardDetailResponseDto; import com.somemore.domains.recruitboard.dto.response.RecruitBoardResponseDto; import com.somemore.domains.recruitboard.dto.response.RecruitBoardWithCenterResponseDto; @@ -16,14 +12,18 @@ import com.somemore.domains.recruitboard.repository.mapper.RecruitBoardDetail; import com.somemore.domains.recruitboard.repository.mapper.RecruitBoardWithCenter; import com.somemore.domains.recruitboard.repository.mapper.RecruitBoardWithLocation; - -import java.util.List; -import java.util.UUID; +import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; +import com.somemore.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.UUID; + +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_RECRUIT_BOARD; + @RequiredArgsConstructor @Transactional(readOnly = true) @Service @@ -70,7 +70,7 @@ public Page getRecruitBoardsNearby( @Override public Page getRecruitBoardsByCenterId(UUID centerId, - RecruitBoardSearchCondition condition) { + RecruitBoardSearchCondition condition) { centerQueryUseCase.validateCenterExists(centerId); Page boards = recruitBoardRepository.findAllByCenterId(centerId, condition); diff --git a/src/main/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardService.java b/src/main/java/com/somemore/domains/recruitboard/service/UpdateRecruitBoardService.java similarity index 90% rename from src/main/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardService.java rename to src/main/java/com/somemore/domains/recruitboard/service/UpdateRecruitBoardService.java index bb8b7aabf..e4320d342 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardService.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/UpdateRecruitBoardService.java @@ -1,4 +1,4 @@ -package com.somemore.domains.recruitboard.service.command; +package com.somemore.domains.recruitboard.service; import com.somemore.domains.location.usecase.command.UpdateLocationUseCase; import com.somemore.domains.recruitboard.domain.RecruitBoard; @@ -6,8 +6,8 @@ import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto; import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto; import com.somemore.domains.recruitboard.service.validator.RecruitBoardValidator; -import com.somemore.domains.recruitboard.usecase.command.UpdateRecruitBoardUseCase; -import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; +import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; +import com.somemore.domains.recruitboard.usecase.UpdateRecruitBoardUseCase; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/somemore/domains/recruitboard/usecase/command/CreateRecruitBoardUseCase.java b/src/main/java/com/somemore/domains/recruitboard/usecase/CreateRecruitBoardUseCase.java similarity index 81% rename from src/main/java/com/somemore/domains/recruitboard/usecase/command/CreateRecruitBoardUseCase.java rename to src/main/java/com/somemore/domains/recruitboard/usecase/CreateRecruitBoardUseCase.java index 26ad1ced5..73e19df05 100644 --- a/src/main/java/com/somemore/domains/recruitboard/usecase/command/CreateRecruitBoardUseCase.java +++ b/src/main/java/com/somemore/domains/recruitboard/usecase/CreateRecruitBoardUseCase.java @@ -1,6 +1,7 @@ -package com.somemore.domains.recruitboard.usecase.command; +package com.somemore.domains.recruitboard.usecase; import com.somemore.domains.recruitboard.dto.request.RecruitBoardCreateRequestDto; + import java.util.UUID; public interface CreateRecruitBoardUseCase { diff --git a/src/main/java/com/somemore/domains/recruitboard/usecase/command/DeleteRecruitBoardUseCase.java b/src/main/java/com/somemore/domains/recruitboard/usecase/DeleteRecruitBoardUseCase.java similarity index 68% rename from src/main/java/com/somemore/domains/recruitboard/usecase/command/DeleteRecruitBoardUseCase.java rename to src/main/java/com/somemore/domains/recruitboard/usecase/DeleteRecruitBoardUseCase.java index e04f2538d..1175cb165 100644 --- a/src/main/java/com/somemore/domains/recruitboard/usecase/command/DeleteRecruitBoardUseCase.java +++ b/src/main/java/com/somemore/domains/recruitboard/usecase/DeleteRecruitBoardUseCase.java @@ -1,4 +1,4 @@ -package com.somemore.domains.recruitboard.usecase.command; +package com.somemore.domains.recruitboard.usecase; import java.util.UUID; diff --git a/src/main/java/com/somemore/domains/recruitboard/usecase/query/RecruitBoardDocumentUseCase.java b/src/main/java/com/somemore/domains/recruitboard/usecase/RecruitBoardDocumentUseCase.java similarity index 100% rename from src/main/java/com/somemore/domains/recruitboard/usecase/query/RecruitBoardDocumentUseCase.java rename to src/main/java/com/somemore/domains/recruitboard/usecase/RecruitBoardDocumentUseCase.java diff --git a/src/main/java/com/somemore/domains/recruitboard/usecase/query/RecruitBoardQueryUseCase.java b/src/main/java/com/somemore/domains/recruitboard/usecase/RecruitBoardQueryUseCase.java similarity index 89% rename from src/main/java/com/somemore/domains/recruitboard/usecase/query/RecruitBoardQueryUseCase.java rename to src/main/java/com/somemore/domains/recruitboard/usecase/RecruitBoardQueryUseCase.java index a0e8e49f1..88255cd06 100644 --- a/src/main/java/com/somemore/domains/recruitboard/usecase/query/RecruitBoardQueryUseCase.java +++ b/src/main/java/com/somemore/domains/recruitboard/usecase/RecruitBoardQueryUseCase.java @@ -1,4 +1,4 @@ -package com.somemore.domains.recruitboard.usecase.query; +package com.somemore.domains.recruitboard.usecase; import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.dto.condition.RecruitBoardNearByCondition; @@ -7,9 +7,10 @@ import com.somemore.domains.recruitboard.dto.response.RecruitBoardResponseDto; import com.somemore.domains.recruitboard.dto.response.RecruitBoardWithCenterResponseDto; import com.somemore.domains.recruitboard.dto.response.RecruitBoardWithLocationResponseDto; +import org.springframework.data.domain.Page; + import java.util.List; import java.util.UUID; -import org.springframework.data.domain.Page; public interface RecruitBoardQueryUseCase { @@ -25,7 +26,7 @@ Page getRecruitBoardsNearby( RecruitBoardNearByCondition condition); Page getRecruitBoardsByCenterId(UUID centerId, - RecruitBoardSearchCondition condition); + RecruitBoardSearchCondition condition); List getNotCompletedIdsByCenterIds(UUID centerId); diff --git a/src/main/java/com/somemore/domains/recruitboard/usecase/command/UpdateRecruitBoardUseCase.java b/src/main/java/com/somemore/domains/recruitboard/usecase/UpdateRecruitBoardUseCase.java similarity index 91% rename from src/main/java/com/somemore/domains/recruitboard/usecase/command/UpdateRecruitBoardUseCase.java rename to src/main/java/com/somemore/domains/recruitboard/usecase/UpdateRecruitBoardUseCase.java index 51986a037..3403d7711 100644 --- a/src/main/java/com/somemore/domains/recruitboard/usecase/command/UpdateRecruitBoardUseCase.java +++ b/src/main/java/com/somemore/domains/recruitboard/usecase/UpdateRecruitBoardUseCase.java @@ -1,4 +1,4 @@ -package com.somemore.domains.recruitboard.usecase.command; +package com.somemore.domains.recruitboard.usecase; import com.somemore.domains.recruitboard.domain.RecruitStatus; import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto; diff --git a/src/main/java/com/somemore/domains/volunteer/validator/VolunteerDetailAccessValidatorImpl.java b/src/main/java/com/somemore/domains/volunteer/validator/VolunteerDetailAccessValidatorImpl.java index 8201a8484..dc4209c2a 100644 --- a/src/main/java/com/somemore/domains/volunteer/validator/VolunteerDetailAccessValidatorImpl.java +++ b/src/main/java/com/somemore/domains/volunteer/validator/VolunteerDetailAccessValidatorImpl.java @@ -1,6 +1,6 @@ package com.somemore.domains.volunteer.validator; -import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; +import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase; import com.somemore.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/ApplyVolunteerApplyService.java b/src/main/java/com/somemore/domains/volunteerapply/service/ApplyVolunteerApplyService.java index 4d525777d..152aa79c6 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/ApplyVolunteerApplyService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/ApplyVolunteerApplyService.java @@ -1,25 +1,25 @@ package com.somemore.domains.volunteerapply.service; -import static com.somemore.global.exception.ExceptionMessage.DUPLICATE_APPLICATION; -import static com.somemore.global.exception.ExceptionMessage.RECRUITMENT_NOT_OPEN; - import com.somemore.domains.notification.domain.NotificationSubType; import com.somemore.domains.recruitboard.domain.RecruitBoard; -import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; -import com.somemore.domains.volunteerapply.usecase.ApplyVolunteerApplyUseCase; -import com.somemore.global.common.event.ServerEventPublisher; -import com.somemore.global.common.event.ServerEventType; -import com.somemore.global.exception.BadRequestException; +import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.dto.request.VolunteerApplyCreateRequestDto; import com.somemore.domains.volunteerapply.event.VolunteerApplyEvent; import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository; - -import java.util.UUID; +import com.somemore.domains.volunteerapply.usecase.ApplyVolunteerApplyUseCase; +import com.somemore.global.common.event.ServerEventPublisher; +import com.somemore.global.common.event.ServerEventType; +import com.somemore.global.exception.BadRequestException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.UUID; + +import static com.somemore.global.exception.ExceptionMessage.DUPLICATE_APPLICATION; +import static com.somemore.global.exception.ExceptionMessage.RECRUITMENT_NOT_OPEN; + @RequiredArgsConstructor @Transactional @Service diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java index 787c1059b..b32d8e18a 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java @@ -2,7 +2,7 @@ import com.somemore.domains.notification.domain.NotificationSubType; import com.somemore.domains.recruitboard.domain.RecruitBoard; -import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; +import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; import com.somemore.domains.volunteer.usecase.UpdateVolunteerUseCase; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.dto.request.VolunteerApplySettleRequestDto; diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java index cfdee87de..9a57cc0cc 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java @@ -1,7 +1,7 @@ package com.somemore.domains.volunteerapply.service; import com.somemore.domains.recruitboard.domain.RecruitBoard; -import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; +import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; import com.somemore.domains.volunteer.repository.mapper.VolunteerSimpleInfo; import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; import com.somemore.domains.volunteerapply.domain.VolunteerApply; diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java index fcfc0fc34..9197ddc23 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java @@ -1,7 +1,7 @@ package com.somemore.domains.volunteerapply.service; import com.somemore.domains.recruitboard.domain.RecruitBoard; -import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; +import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; import com.somemore.domains.volunteerapply.domain.ApplyStatus; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.event.VolunteerApplyStatusChangeEvent; diff --git a/src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiControllerTest.java b/src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiControllerTest.java index 28bac8c3f..2384efc5d 100644 --- a/src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiControllerTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiControllerTest.java @@ -6,9 +6,9 @@ import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto; import com.somemore.domains.recruitboard.dto.request.RecruitBoardStatusUpdateRequestDto; import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto; -import com.somemore.domains.recruitboard.usecase.command.CreateRecruitBoardUseCase; -import com.somemore.domains.recruitboard.usecase.command.DeleteRecruitBoardUseCase; -import com.somemore.domains.recruitboard.usecase.command.UpdateRecruitBoardUseCase; +import com.somemore.domains.recruitboard.usecase.CreateRecruitBoardUseCase; +import com.somemore.domains.recruitboard.usecase.DeleteRecruitBoardUseCase; +import com.somemore.domains.recruitboard.usecase.UpdateRecruitBoardUseCase; import com.somemore.global.imageupload.usecase.ImageUploadUseCase; import com.somemore.support.ControllerTestSupport; import com.somemore.support.annotation.WithMockCustomUser; diff --git a/src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardQueryApiControllerTest.java b/src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardQueryApiControllerTest.java index 77e73bc6d..8e250b3f9 100644 --- a/src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardQueryApiControllerTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardQueryApiControllerTest.java @@ -1,25 +1,13 @@ package com.somemore.domains.recruitboard.controller; -import static com.somemore.domains.recruitboard.domain.VolunteerCategory.ADMINISTRATIVE_SUPPORT; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - import com.somemore.domains.recruitboard.dto.condition.RecruitBoardNearByCondition; import com.somemore.domains.recruitboard.dto.condition.RecruitBoardSearchCondition; import com.somemore.domains.recruitboard.dto.response.RecruitBoardDetailResponseDto; import com.somemore.domains.recruitboard.dto.response.RecruitBoardResponseDto; import com.somemore.domains.recruitboard.dto.response.RecruitBoardWithCenterResponseDto; import com.somemore.domains.recruitboard.dto.response.RecruitBoardWithLocationResponseDto; -import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; +import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; import com.somemore.support.ControllerTestSupport; -import java.util.Collections; -import java.util.UUID; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; @@ -27,6 +15,17 @@ import org.springframework.data.domain.PageImpl; import org.springframework.http.MediaType; +import java.util.Collections; +import java.util.UUID; + +import static com.somemore.domains.recruitboard.domain.VolunteerCategory.ADMINISTRATIVE_SUPPORT; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + class RecruitBoardQueryApiControllerTest extends ControllerTestSupport { @MockBean diff --git a/src/test/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardServiceTest.java b/src/test/java/com/somemore/domains/recruitboard/service/CreateRecruitBoardServiceTest.java similarity index 98% rename from src/test/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardServiceTest.java rename to src/test/java/com/somemore/domains/recruitboard/service/CreateRecruitBoardServiceTest.java index 9191d78b1..81b98819c 100644 --- a/src/test/java/com/somemore/domains/recruitboard/service/command/CreateRecruitBoardServiceTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/service/CreateRecruitBoardServiceTest.java @@ -1,4 +1,4 @@ -package com.somemore.domains.recruitboard.service.command; +package com.somemore.domains.recruitboard.service; import com.somemore.domains.location.dto.request.LocationCreateRequestDto; import com.somemore.domains.location.repository.LocationRepository; diff --git a/src/test/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardServiceTest.java b/src/test/java/com/somemore/domains/recruitboard/service/DeleteRecruitBoardServiceTest.java similarity index 97% rename from src/test/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardServiceTest.java rename to src/test/java/com/somemore/domains/recruitboard/service/DeleteRecruitBoardServiceTest.java index 366dcaa49..b53e7c542 100644 --- a/src/test/java/com/somemore/domains/recruitboard/service/command/DeleteRecruitBoardServiceTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/service/DeleteRecruitBoardServiceTest.java @@ -1,4 +1,4 @@ -package com.somemore.domains.recruitboard.service.command; +package com.somemore.domains.recruitboard.service; import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.domain.RecruitmentInfo; diff --git a/src/test/java/com/somemore/domains/recruitboard/service/query/RecruitBoardDocumentServiceTest.java b/src/test/java/com/somemore/domains/recruitboard/service/RecruitBoardDocumentServiceTest.java similarity index 100% rename from src/test/java/com/somemore/domains/recruitboard/service/query/RecruitBoardDocumentServiceTest.java rename to src/test/java/com/somemore/domains/recruitboard/service/RecruitBoardDocumentServiceTest.java diff --git a/src/test/java/com/somemore/domains/recruitboard/service/query/RecruitBoardQueryServiceTest.java b/src/test/java/com/somemore/domains/recruitboard/service/RecruitBoardQueryServiceTest.java similarity index 99% rename from src/test/java/com/somemore/domains/recruitboard/service/query/RecruitBoardQueryServiceTest.java rename to src/test/java/com/somemore/domains/recruitboard/service/RecruitBoardQueryServiceTest.java index 922af7b26..36724e570 100644 --- a/src/test/java/com/somemore/domains/recruitboard/service/query/RecruitBoardQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/service/RecruitBoardQueryServiceTest.java @@ -1,4 +1,4 @@ -package com.somemore.domains.recruitboard.service.query; +package com.somemore.domains.recruitboard.service; import com.somemore.domains.center.domain.Center; import com.somemore.domains.center.repository.center.CenterRepository; diff --git a/src/test/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardServiceTest.java b/src/test/java/com/somemore/domains/recruitboard/service/UpdateRecruitBoardServiceTest.java similarity index 99% rename from src/test/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardServiceTest.java rename to src/test/java/com/somemore/domains/recruitboard/service/UpdateRecruitBoardServiceTest.java index f1b8d5361..9265db3ee 100644 --- a/src/test/java/com/somemore/domains/recruitboard/service/command/UpdateRecruitBoardServiceTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/service/UpdateRecruitBoardServiceTest.java @@ -1,4 +1,4 @@ -package com.somemore.domains.recruitboard.service.command; +package com.somemore.domains.recruitboard.service; import com.somemore.domains.location.domain.Location; import com.somemore.domains.location.repository.LocationRepository; diff --git a/src/test/java/com/somemore/domains/volunteerapply/service/ApproveVolunteerApplyStatusChangeServiceTest.java b/src/test/java/com/somemore/domains/volunteerapply/service/ApproveVolunteerApplyStatusChangeServiceTest.java index 5c8ef7b6c..8271c081d 100644 --- a/src/test/java/com/somemore/domains/volunteerapply/service/ApproveVolunteerApplyStatusChangeServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteerapply/service/ApproveVolunteerApplyStatusChangeServiceTest.java @@ -2,7 +2,7 @@ import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; -import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; +import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.event.VolunteerApplyStatusChangeEvent; import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository; diff --git a/src/test/java/com/somemore/domains/volunteerapply/service/RejectVolunteerApplyStatusChangeServiceTest.java b/src/test/java/com/somemore/domains/volunteerapply/service/RejectVolunteerApplyStatusChangeServiceTest.java index 95ce2a418..13b8321ef 100644 --- a/src/test/java/com/somemore/domains/volunteerapply/service/RejectVolunteerApplyStatusChangeServiceTest.java +++ b/src/test/java/com/somemore/domains/volunteerapply/service/RejectVolunteerApplyStatusChangeServiceTest.java @@ -2,7 +2,7 @@ import com.somemore.domains.recruitboard.domain.RecruitBoard; import com.somemore.domains.recruitboard.repository.RecruitBoardRepository; -import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase; +import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase; import com.somemore.domains.volunteerapply.domain.VolunteerApply; import com.somemore.domains.volunteerapply.event.VolunteerApplyStatusChangeEvent; import com.somemore.domains.volunteerapply.repository.VolunteerApplyRepository; From e35bb9759072683c18239ae352d82f72b312e6bb Mon Sep 17 00:00:00 2001 From: leebs0521 Date: Thu, 2 Jan 2025 15:44:20 +0900 Subject: [PATCH 09/12] =?UTF-8?q?chore(recruit-board):=20sonarqube=20?= =?UTF-8?q?=EC=9D=B4=EC=8A=88=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/RecruitBoardQueryServiceTest.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/test/java/com/somemore/domains/recruitboard/service/RecruitBoardQueryServiceTest.java b/src/test/java/com/somemore/domains/recruitboard/service/RecruitBoardQueryServiceTest.java index 36724e570..508a169b5 100644 --- a/src/test/java/com/somemore/domains/recruitboard/service/RecruitBoardQueryServiceTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/service/RecruitBoardQueryServiceTest.java @@ -252,18 +252,16 @@ void findNotCompletedIdsByCenterIds() { recruitBoardRepository.save(completedRecruitBoard); // when - List notCompletedBoardIds = recruitBoardQueryService.getNotCompletedIdsByCenterIds( - centerId); + List notCompletedBoardIds = recruitBoardQueryService.getNotCompletedIdsByCenterIds(centerId); // then assertThat(notCompletedBoardIds) - .hasSize(2); - - assertThat(notCompletedBoardIds) - .doesNotContain(deletedRecruitingBoard.getId()) - .doesNotContain(deletedClosedBoard.getId()) - .doesNotContain(deletedCompletedRecruitBoard.getId()) - .doesNotContain(completedRecruitBoard.getId()); + .hasSize(2) + .doesNotContain( + deletedRecruitingBoard.getId(), + deletedClosedBoard.getId(), + deletedCompletedRecruitBoard.getId(), + completedRecruitBoard.getId()); } @DisplayName("아이디리스트로 모집글 리스트를 조회할 수 있다.") From b69f1d153dbd02eaec069f280e367133337ae689 Mon Sep 17 00:00:00 2001 From: leebs0521 Date: Tue, 7 Jan 2025 14:37:19 +0900 Subject: [PATCH 10/12] =?UTF-8?q?refactor(recruit-board):=20=EB=B4=89?= =?UTF-8?q?=EC=82=AC=20=EC=8B=9C=EA=B0=84=20=ED=83=80=EC=9E=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=20-=20Integer=20->=20int?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../somemore/domains/recruitboard/domain/RecruitmentInfo.java | 4 ++-- .../domains/recruitboard/domain/RecruitBoardTest.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/somemore/domains/recruitboard/domain/RecruitmentInfo.java b/src/main/java/com/somemore/domains/recruitboard/domain/RecruitmentInfo.java index 63c8fbebb..8d9dd12a0 100644 --- a/src/main/java/com/somemore/domains/recruitboard/domain/RecruitmentInfo.java +++ b/src/main/java/com/somemore/domains/recruitboard/domain/RecruitmentInfo.java @@ -31,7 +31,7 @@ public class RecruitmentInfo { private LocalDateTime volunteerEndDateTime; @Column(name = "volunteer_hours", nullable = false) - private Integer volunteerHours; + private int volunteerHours; @Enumerated(value = STRING) @Column(name = "volunteer_category", nullable = false, length = 30) @@ -42,7 +42,7 @@ public class RecruitmentInfo { @Builder public RecruitmentInfo(String region, Integer recruitmentCount, LocalDateTime volunteerStartDateTime, LocalDateTime volunteerEndDateTime, - Integer volunteerHours, VolunteerCategory volunteerCategory, Boolean admitted) { + int volunteerHours, VolunteerCategory volunteerCategory, Boolean admitted) { this.region = region; this.recruitmentCount = recruitmentCount; diff --git a/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java b/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java index c47561da8..8abb970f7 100644 --- a/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java @@ -50,6 +50,7 @@ void updateRecruitBoard() { .recruitmentCount(10) .volunteerStartDateTime(startDateTime) .volunteerEndDateTime(endDateTime) + .volunteerHours(2) .volunteerCategory(OTHER) .admitted(true).build(); From 983ab4ab34897f68e607cbd6ed9a24dc3417067d Mon Sep 17 00:00:00 2001 From: leebs0521 Date: Tue, 7 Jan 2025 14:38:41 +0900 Subject: [PATCH 11/12] =?UTF-8?q?fix(recruit-board):=20=EC=98=A4=ED=83=80?= =?UTF-8?q?=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruitboard/dto/request/RecruitBoardCreateRequestDto.java | 2 +- .../recruitboard/dto/response/RecruitBoardResponseDto.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardCreateRequestDto.java b/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardCreateRequestDto.java index 366ba9909..b33d54dd9 100644 --- a/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardCreateRequestDto.java +++ b/src/main/java/com/somemore/domains/recruitboard/dto/request/RecruitBoardCreateRequestDto.java @@ -39,7 +39,7 @@ public record RecruitBoardCreateRequestDto( @Future(message = "봉사 종료 일시는 내일부터 가능합니다.") LocalDateTime volunteerEndDateTime, @Schema(description = "봉사 시간", example = "2") - @NotNull(message = "봉사 시간는 필수 값입니다.") + @NotNull(message = "봉사 시간은 필수 값입니다.") Integer volunteerHours, @Schema(description = "봉사 활동 유형", example = "ENVIRONMENTAL_PROTECTION") @NotNull(message = "봉사 활동 유형은 필수 값입니다.") diff --git a/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardResponseDto.java b/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardResponseDto.java index 22f428762..758b926aa 100644 --- a/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardResponseDto.java +++ b/src/main/java/com/somemore/domains/recruitboard/dto/response/RecruitBoardResponseDto.java @@ -42,7 +42,7 @@ public record RecruitBoardResponseDto( LocalDateTime volunteerEndDateTime, @Schema(description = "봉사 유형", example = "LIVING_SUPPORT") VolunteerCategory volunteerCategory, - @Schema(description = "봉사 시간", example = "04:00:00") + @Schema(description = "봉사 시간", example = "4") Integer volunteerHours, @Schema(description = "시간 인정 여부", example = "true") Boolean admitted, From 074e77c9e2793096efcb66965798abf80e93bb11 Mon Sep 17 00:00:00 2001 From: leebs0521 Date: Tue, 7 Jan 2025 14:43:14 +0900 Subject: [PATCH 12/12] =?UTF-8?q?refactor:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD=20=20-=20isAuthor=20->=20isWrite?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domains/recruitboard/domain/RecruitBoard.java | 2 +- .../recruitboard/service/DeleteRecruitBoardService.java | 2 +- .../recruitboard/service/UpdateRecruitBoardService.java | 6 +++--- .../service/validator/RecruitBoardValidator.java | 4 ++-- .../java/com/somemore/domains/review/domain/Review.java | 2 +- .../domains/review/service/DeleteReviewService.java | 2 +- .../domains/review/service/UpdateReviewService.java | 4 ++-- .../domains/review/service/validator/ReviewValidator.java | 4 ++-- .../service/SettleVolunteerApplyFacadeService.java | 2 +- .../service/VolunteerApplyQueryFacadeService.java | 2 +- .../service/VolunteerApplyStatusChangeService.java | 2 +- .../domains/recruitboard/domain/RecruitBoardTest.java | 8 ++++---- .../service/validator/RecruitBoardValidatorTest.java | 4 ++-- .../com/somemore/domains/review/domain/ReviewTest.java | 4 ++-- .../review/service/validator/ReviewValidatorTest.java | 8 ++++---- 15 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/somemore/domains/recruitboard/domain/RecruitBoard.java b/src/main/java/com/somemore/domains/recruitboard/domain/RecruitBoard.java index 0927449b9..38f5e7047 100644 --- a/src/main/java/com/somemore/domains/recruitboard/domain/RecruitBoard.java +++ b/src/main/java/com/somemore/domains/recruitboard/domain/RecruitBoard.java @@ -58,7 +58,7 @@ public RecruitBoard(UUID centerId, Long locationId, String title, String content this.imgUrl = imgUrl; } - public boolean isAuthor(UUID centerId) { + public boolean isWriter(UUID centerId) { return this.centerId.equals(centerId); } diff --git a/src/main/java/com/somemore/domains/recruitboard/service/DeleteRecruitBoardService.java b/src/main/java/com/somemore/domains/recruitboard/service/DeleteRecruitBoardService.java index 485e1ef8d..ad5d32213 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/DeleteRecruitBoardService.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/DeleteRecruitBoardService.java @@ -21,7 +21,7 @@ public class DeleteRecruitBoardService implements DeleteRecruitBoardUseCase { @Override public void deleteRecruitBoard(UUID centerId, Long id) { RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(id); - recruitBoardValidator.validateAuthor(recruitBoard, centerId); + recruitBoardValidator.validateWriter(recruitBoard, centerId); recruitBoard.markAsDeleted(); } diff --git a/src/main/java/com/somemore/domains/recruitboard/service/UpdateRecruitBoardService.java b/src/main/java/com/somemore/domains/recruitboard/service/UpdateRecruitBoardService.java index e4320d342..fe9967994 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/UpdateRecruitBoardService.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/UpdateRecruitBoardService.java @@ -27,7 +27,7 @@ public class UpdateRecruitBoardService implements UpdateRecruitBoardUseCase { @Override public void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long id, UUID centerId, String imgUrl) { RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(id); - recruitBoardValidator.validateAuthor(recruitBoard, centerId); + recruitBoardValidator.validateWriter(recruitBoard, centerId); recruitBoardValidator.validateRecruitBoardTime(dto.volunteerStartDateTime(), dto.volunteerEndDateTime()); recruitBoard.updateWith(dto, imgUrl); @@ -36,7 +36,7 @@ public void updateRecruitBoard(RecruitBoardUpdateRequestDto dto, Long id, UUID c @Override public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requestDto, Long id, UUID centerId) { RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(id); - recruitBoardValidator.validateAuthor(recruitBoard, centerId); + recruitBoardValidator.validateWriter(recruitBoard, centerId); updateLocationUseCase.updateLocation(requestDto.toLocationUpdateRequestDto(), recruitBoard.getLocationId()); @@ -46,7 +46,7 @@ public void updateRecruitBoardLocation(RecruitBoardLocationUpdateRequestDto requ @Override public void updateRecruitBoardStatus(RecruitStatus status, Long id, UUID centerId, LocalDateTime currentDateTime) { RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(id); - recruitBoardValidator.validateAuthor(recruitBoard, centerId); + recruitBoardValidator.validateWriter(recruitBoard, centerId); recruitBoard.changeRecruitStatus(status, currentDateTime); } diff --git a/src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java b/src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java index 196a75df1..f212a85bb 100644 --- a/src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java +++ b/src/main/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidator.java @@ -21,8 +21,8 @@ public void validateRecruitBoardTime(LocalDateTime startDateTime, LocalDateTime throw new BadRequestException(INVALID_RECRUIT_BOARD_TIME); } - public void validateAuthor(RecruitBoard recruitBoard, UUID centerId) { - if (recruitBoard.isAuthor(centerId)) { + public void validateWriter(RecruitBoard recruitBoard, UUID centerId) { + if (recruitBoard.isWriter(centerId)) { return; } diff --git a/src/main/java/com/somemore/domains/review/domain/Review.java b/src/main/java/com/somemore/domains/review/domain/Review.java index 82506e1f5..06f7f248e 100644 --- a/src/main/java/com/somemore/domains/review/domain/Review.java +++ b/src/main/java/com/somemore/domains/review/domain/Review.java @@ -52,7 +52,7 @@ public Review(Long volunteerApplyId, UUID volunteerId, String title, this.imgUrl = imgUrl; } - public boolean isAuthor(UUID volunteerId) { + public boolean isWriter(UUID volunteerId) { return this.volunteerId.equals(volunteerId); } diff --git a/src/main/java/com/somemore/domains/review/service/DeleteReviewService.java b/src/main/java/com/somemore/domains/review/service/DeleteReviewService.java index 708f55612..59c7d33fe 100644 --- a/src/main/java/com/somemore/domains/review/service/DeleteReviewService.java +++ b/src/main/java/com/somemore/domains/review/service/DeleteReviewService.java @@ -22,7 +22,7 @@ public class DeleteReviewService implements DeleteReviewUseCase { public void deleteReview(UUID volunteerId, Long id) { Review review = reviewQueryUseCase.getById(id); - reviewValidator.validateAuthor(review, volunteerId); + reviewValidator.validateWriter(review, volunteerId); review.markAsDeleted(); } diff --git a/src/main/java/com/somemore/domains/review/service/UpdateReviewService.java b/src/main/java/com/somemore/domains/review/service/UpdateReviewService.java index c020527b8..8640064e6 100644 --- a/src/main/java/com/somemore/domains/review/service/UpdateReviewService.java +++ b/src/main/java/com/somemore/domains/review/service/UpdateReviewService.java @@ -22,14 +22,14 @@ public class UpdateReviewService implements UpdateReviewUseCase { @Override public void updateReview(Long id, UUID volunteerId, ReviewUpdateRequestDto requestDto) { Review review = reviewQueryUseCase.getById(id); - reviewValidator.validateAuthor(review, volunteerId); + reviewValidator.validateWriter(review, volunteerId); review.updateWith(requestDto); } @Override public void updateReviewImageUrl(Long id, UUID volunteerId, String imgUrl) { Review review = reviewQueryUseCase.getById(id); - reviewValidator.validateAuthor(review, volunteerId); + reviewValidator.validateWriter(review, volunteerId); review.updateWith(imgUrl); } diff --git a/src/main/java/com/somemore/domains/review/service/validator/ReviewValidator.java b/src/main/java/com/somemore/domains/review/service/validator/ReviewValidator.java index ebd6f5d51..936a8ddd8 100644 --- a/src/main/java/com/somemore/domains/review/service/validator/ReviewValidator.java +++ b/src/main/java/com/somemore/domains/review/service/validator/ReviewValidator.java @@ -11,8 +11,8 @@ @Component public class ReviewValidator { - public void validateAuthor(Review review, UUID volunteerId) { - if (review.isAuthor(volunteerId)) { + public void validateWriter(Review review, UUID volunteerId) { + if (review.isWriter(volunteerId)) { return; } diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java index b32d8e18a..66158e59d 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/SettleVolunteerApplyFacadeService.java @@ -52,7 +52,7 @@ public void settleVolunteerApplies(VolunteerApplySettleRequestDto dto, UUID cent } private void validateAuth(RecruitBoard recruitBoard, UUID centerId) { - if (recruitBoard.isAuthor(centerId)) { + if (recruitBoard.isWriter(centerId)) { return; } throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD); diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java index 9a57cc0cc..dcde866d1 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeService.java @@ -68,7 +68,7 @@ public Page getVolunteerAppliesByVolunteer private void validateAuthorization(Long recruitId, UUID centerId) { RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(recruitId); - if (recruitBoard.isAuthor(centerId)) { + if (recruitBoard.isWriter(centerId)) { return; } diff --git a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java index 9197ddc23..6530b4c41 100644 --- a/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java +++ b/src/main/java/com/somemore/domains/volunteerapply/service/VolunteerApplyStatusChangeService.java @@ -59,7 +59,7 @@ private VolunteerApply getVolunteerApply(Long id) { } private void validateWriter(RecruitBoard recruitBoard, UUID centerId) { - if (recruitBoard.isAuthor(centerId)) { + if (recruitBoard.isWriter(centerId)) { return; } throw new BadRequestException(UNAUTHORIZED_RECRUIT_BOARD); diff --git a/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java b/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java index 8abb970f7..4c9b0a4f1 100644 --- a/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/domain/RecruitBoardTest.java @@ -81,13 +81,13 @@ void updateWithRegion() { @DisplayName("올바른 기관 식별 값이 주어지면 작성자인지 확인할 수 있다") @Test - void isAuthorWithCorrectCenterId() { + void isWriterWithCorrectCenterId() { // given UUID centerId = UUID.randomUUID(); RecruitBoard recruitBoard = createRecruitBoard(centerId); // when - boolean isWriter = recruitBoard.isAuthor(centerId); + boolean isWriter = recruitBoard.isWriter(centerId); // then assertThat(isWriter).isTrue(); @@ -95,13 +95,13 @@ void isAuthorWithCorrectCenterId() { @DisplayName("잘못된 기관 식별 값이 주어지면 잘못된 작성자인 확인할 수있다.") @Test - void isNotAuthorWithWrongCenterId() { + void isNotWriterWithWrongCenterId() { UUID centerId = UUID.randomUUID(); UUID wrongId = UUID.randomUUID(); RecruitBoard recruitBoard = createRecruitBoard(centerId); // when - boolean isWriter = recruitBoard.isAuthor(wrongId); + boolean isWriter = recruitBoard.isWriter(wrongId); // then assertThat(isWriter).isFalse(); diff --git a/src/test/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidatorTest.java b/src/test/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidatorTest.java index 7f33306be..f684b79ab 100644 --- a/src/test/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidatorTest.java +++ b/src/test/java/com/somemore/domains/recruitboard/service/validator/RecruitBoardValidatorTest.java @@ -38,7 +38,7 @@ void createRecruitBoardWithInValidVolunteerTime(long minutesOffset) { @DisplayName("모집글 작성자가 아닌 경우 에러가 발생한다") @Test - void validateAuthor() { + void validateWriter() { // given UUID wrongCenterId = UUID.randomUUID(); RecruitBoard board = createRecruitBoard(UUID.randomUUID()); @@ -46,7 +46,7 @@ void validateAuthor() { // when // then assertThatThrownBy( - () -> validator.validateAuthor(board, wrongCenterId)) + () -> validator.validateWriter(board, wrongCenterId)) .isInstanceOf(BadRequestException.class) .hasMessage(UNAUTHORIZED_RECRUIT_BOARD.getMessage()); } diff --git a/src/test/java/com/somemore/domains/review/domain/ReviewTest.java b/src/test/java/com/somemore/domains/review/domain/ReviewTest.java index 31567d693..4d01bfa45 100644 --- a/src/test/java/com/somemore/domains/review/domain/ReviewTest.java +++ b/src/test/java/com/somemore/domains/review/domain/ReviewTest.java @@ -23,11 +23,11 @@ void setUp() { @DisplayName("작성자 인지 확인할 수 있다.") @Test - void isAuthor() { + void isWriter() { // given // when - boolean result = review.isAuthor(volunteerId); + boolean result = review.isWriter(volunteerId); // then assertThat(result).isTrue(); diff --git a/src/test/java/com/somemore/domains/review/service/validator/ReviewValidatorTest.java b/src/test/java/com/somemore/domains/review/service/validator/ReviewValidatorTest.java index 9ac139e89..c95b74e51 100644 --- a/src/test/java/com/somemore/domains/review/service/validator/ReviewValidatorTest.java +++ b/src/test/java/com/somemore/domains/review/service/validator/ReviewValidatorTest.java @@ -17,7 +17,7 @@ class ReviewValidatorTest { @DisplayName("리뷰 작성자인지 검증할 수 있다") @Test - void validateAuthor() { + void validateWriter() { // given UUID volunteerId = UUID.randomUUID(); Review review = createReview(volunteerId, "리뷰 제목", "내용내용", "이미지링크"); @@ -25,13 +25,13 @@ void validateAuthor() { // when // then assertThatCode( - () -> reviewValidator.validateAuthor(review, volunteerId)) + () -> reviewValidator.validateWriter(review, volunteerId)) .doesNotThrowAnyException(); } @DisplayName("리뷰 작성자와 일치 하지 않는 경우 에러가 발생한다.") @Test - void validateAuthorWhenMissMatch() { + void validateWriterWhenMissMatch() { // given UUID wrongVolunteerId = UUID.randomUUID(); Review review = createReview(UUID.randomUUID(), "다른 제목", "다른 내용", "다른 링크"); @@ -39,7 +39,7 @@ void validateAuthorWhenMissMatch() { // when // then assertThatThrownBy( - () -> reviewValidator.validateAuthor(review, wrongVolunteerId)) + () -> reviewValidator.validateWriter(review, wrongVolunteerId)) .isInstanceOf(BadRequestException.class) .hasMessage(UNAUTHORIZED_REVIEW.getMessage()); }