From 8bb7f0ce11f43e0241681b87c8bd2445a6f92285 Mon Sep 17 00:00:00 2001 From: JaeHoonSong <128021502+SongJaeHoonn@users.noreply.github.com> Date: Tue, 25 Jun 2024 00:27:24 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20=EB=AA=A8=EC=A7=91=EA=B3=B5?= =?UTF-8?q?=EA=B3=A0=20=EC=83=81=ED=83=9C=20=EB=82=98=ED=83=80=EB=82=B4?= =?UTF-8?q?=EB=8A=94=20enum=20=EB=8F=84=EC=9E=85=20#353?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruitment/domain/RecruitmentStatus.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/page/clab/api/domain/recruitment/domain/RecruitmentStatus.java diff --git a/src/main/java/page/clab/api/domain/recruitment/domain/RecruitmentStatus.java b/src/main/java/page/clab/api/domain/recruitment/domain/RecruitmentStatus.java new file mode 100644 index 000000000..bd77d7f86 --- /dev/null +++ b/src/main/java/page/clab/api/domain/recruitment/domain/RecruitmentStatus.java @@ -0,0 +1,17 @@ +package page.clab.api.domain.recruitment.domain; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum RecruitmentStatus { + + UPCOMING("UPCOMING", "모집 예정"), + OPEN("OPEN", "모집중"), + CLOSED("CLOSED", "모집 종료"); + + private String key; + private String description; + +} From 6a8bb58e213e7d2044defb89d616c067c97eac63 Mon Sep 17 00:00:00 2001 From: JaeHoonSong <128021502+SongJaeHoonn@users.noreply.github.com> Date: Tue, 25 Jun 2024 00:29:42 +0900 Subject: [PATCH 2/8] =?UTF-8?q?feat:=20=EB=AA=A8=EC=A7=91=20=EA=B8=B0?= =?UTF-8?q?=EA=B0=84=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EC=9E=90=EB=8F=99?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=AA=A8=EC=A7=91=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20#353?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/RecruitmentService.java | 31 +++++++++++++++++++ .../recruitment/domain/Recruitment.java | 7 +++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/main/java/page/clab/api/domain/recruitment/application/RecruitmentService.java b/src/main/java/page/clab/api/domain/recruitment/application/RecruitmentService.java index a6275550c..76a48b651 100644 --- a/src/main/java/page/clab/api/domain/recruitment/application/RecruitmentService.java +++ b/src/main/java/page/clab/api/domain/recruitment/application/RecruitmentService.java @@ -1,13 +1,19 @@ package page.clab.api.domain.recruitment.application; +import jakarta.persistence.EntityManager; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.TransactionDefinition; +import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.annotation.Transactional; import page.clab.api.domain.notification.application.NotificationService; import page.clab.api.domain.recruitment.dao.RecruitmentRepository; import page.clab.api.domain.recruitment.domain.Recruitment; +import page.clab.api.domain.recruitment.domain.RecruitmentStatus; import page.clab.api.domain.recruitment.dto.request.RecruitmentRequestDto; import page.clab.api.domain.recruitment.dto.request.RecruitmentUpdateRequestDto; import page.clab.api.domain.recruitment.dto.response.RecruitmentResponseDto; @@ -15,6 +21,7 @@ import page.clab.api.global.exception.NotFoundException; import page.clab.api.global.validation.ValidationService; +import java.time.LocalDateTime; import java.util.List; @Service @@ -27,9 +34,16 @@ public class RecruitmentService { private final RecruitmentRepository recruitmentRepository; + private final PlatformTransactionManager transactionManager; + + private final EntityManager entityManager; + + private final TransactionDefinition transactionDefinition; + @Transactional public Long createRecruitment(RecruitmentRequestDto requestDto) { Recruitment recruitment = RecruitmentRequestDto.toEntity(requestDto); + updateRecruitmentStatusByRecruitment(recruitment); validationService.checkValid(recruitment); notificationService.sendNotificationToAllMembers("새로운 모집 공고가 등록되었습니다."); return recruitmentRepository.save(recruitment).getId(); @@ -69,4 +83,21 @@ public Recruitment getRecruitmentByIdOrThrow(Long recruitmentId) { .orElseThrow(() -> new NotFoundException("해당 모집 공고가 존재하지 않습니다.")); } + @Scheduled(cron = "0 * * * * *") + public void updateRecruitmentStatus(){ + List recruitments = recruitmentRepository.findAll(); + recruitments.forEach(this::updateRecruitmentStatusByRecruitment); + } + + public void updateRecruitmentStatusByRecruitment(Recruitment recruitment){ + TransactionStatus transactionStatus = transactionManager.getTransaction(transactionDefinition); + LocalDateTime now = LocalDateTime.now(); + RecruitmentStatus newStatus = now.isBefore(recruitment.getStartDate()) + ? RecruitmentStatus.UPCOMING : now.isAfter(recruitment.getEndDate()) + ? RecruitmentStatus.CLOSED : RecruitmentStatus.OPEN; + recruitment.updateStatus(newStatus); + entityManager.merge(recruitment); + transactionManager.commit(transactionStatus); + } + } diff --git a/src/main/java/page/clab/api/domain/recruitment/domain/Recruitment.java b/src/main/java/page/clab/api/domain/recruitment/domain/Recruitment.java index 7f689027c..a114029e6 100644 --- a/src/main/java/page/clab/api/domain/recruitment/domain/Recruitment.java +++ b/src/main/java/page/clab/api/domain/recruitment/domain/Recruitment.java @@ -52,15 +52,16 @@ public class Recruitment extends BaseEntity { private String target; @Column(nullable = false) - @Size(min = 1, message = "{size.recruitment.status}") - private String status; + @Enumerated(EnumType.STRING) + private RecruitmentStatus status; public void update(RecruitmentUpdateRequestDto recruitmentUpdateRequestDto) { Optional.ofNullable(recruitmentUpdateRequestDto.getStartDate()).ifPresent(this::setStartDate); Optional.ofNullable(recruitmentUpdateRequestDto.getEndDate()).ifPresent(this::setEndDate); Optional.ofNullable(recruitmentUpdateRequestDto.getApplicationType()).ifPresent(this::setApplicationType); Optional.ofNullable(recruitmentUpdateRequestDto.getTarget()).ifPresent(this::setTarget); - Optional.ofNullable(recruitmentUpdateRequestDto.getStatus()).ifPresent(this::setStatus); } + public void updateStatus(RecruitmentStatus status) { this.status = status; } + } From e7c35c8c410dc5ddcf9ad86d2e841cbbadc03ec2 Mon Sep 17 00:00:00 2001 From: JaeHoonSong <128021502+SongJaeHoonn@users.noreply.github.com> Date: Tue, 25 Jun 2024 00:32:32 +0900 Subject: [PATCH 3/8] =?UTF-8?q?refactor:=20=EB=AA=A8=EC=A7=91=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EA=B5=AC=ED=98=84=20=EB=A1=9C=EC=A7=81=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20DTO=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20#353?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruitment/dto/request/RecruitmentRequestDto.java | 5 ----- .../recruitment/dto/request/RecruitmentUpdateRequestDto.java | 3 --- .../recruitment/dto/response/RecruitmentResponseDto.java | 3 ++- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/java/page/clab/api/domain/recruitment/dto/request/RecruitmentRequestDto.java b/src/main/java/page/clab/api/domain/recruitment/dto/request/RecruitmentRequestDto.java index 7cbf3eff6..3dbe53273 100644 --- a/src/main/java/page/clab/api/domain/recruitment/dto/request/RecruitmentRequestDto.java +++ b/src/main/java/page/clab/api/domain/recruitment/dto/request/RecruitmentRequestDto.java @@ -29,17 +29,12 @@ public class RecruitmentRequestDto { @Schema(description = "대상", example = "2~3학년", required = true) private String target; - @NotNull(message = "{notNull.recruitment.status}") - @Schema(description = "상태", example = "종료", required = true) - private String status; - public static Recruitment toEntity(RecruitmentRequestDto requestDto) { return Recruitment.builder() .startDate(requestDto.getStartDate()) .endDate(requestDto.getEndDate()) .applicationType(requestDto.getApplicationType()) .target(requestDto.getTarget()) - .status(requestDto.getStatus()) .build(); } diff --git a/src/main/java/page/clab/api/domain/recruitment/dto/request/RecruitmentUpdateRequestDto.java b/src/main/java/page/clab/api/domain/recruitment/dto/request/RecruitmentUpdateRequestDto.java index 0a41652e8..a7579a794 100644 --- a/src/main/java/page/clab/api/domain/recruitment/dto/request/RecruitmentUpdateRequestDto.java +++ b/src/main/java/page/clab/api/domain/recruitment/dto/request/RecruitmentUpdateRequestDto.java @@ -23,7 +23,4 @@ public class RecruitmentUpdateRequestDto { @Schema(description = "대상", example = "2~3학년") private String target; - @Schema(description = "상태", example = "종료") - private String status; - } diff --git a/src/main/java/page/clab/api/domain/recruitment/dto/response/RecruitmentResponseDto.java b/src/main/java/page/clab/api/domain/recruitment/dto/response/RecruitmentResponseDto.java index f619b6b93..18f42adc6 100644 --- a/src/main/java/page/clab/api/domain/recruitment/dto/response/RecruitmentResponseDto.java +++ b/src/main/java/page/clab/api/domain/recruitment/dto/response/RecruitmentResponseDto.java @@ -4,6 +4,7 @@ import lombok.Getter; import page.clab.api.domain.application.domain.ApplicationType; import page.clab.api.domain.recruitment.domain.Recruitment; +import page.clab.api.domain.recruitment.domain.RecruitmentStatus; import java.time.LocalDateTime; @@ -21,7 +22,7 @@ public class RecruitmentResponseDto { private String target; - private String status; + private RecruitmentStatus status; private LocalDateTime updatedAt; From 1c4ef983892e3db288a414c48a3b06cf38813490 Mon Sep 17 00:00:00 2001 From: JaeHoonSong <128021502+SongJaeHoonn@users.noreply.github.com> Date: Tue, 25 Jun 2024 00:35:39 +0900 Subject: [PATCH 4/8] =?UTF-8?q?feat:=20=ED=8A=B8=EB=9E=9C=EC=9E=AD?= =?UTF-8?q?=EC=85=98=EC=9D=84=20=EC=B6=94=EC=83=81=ED=99=94=ED=95=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EB=B9=88?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=93=B1=EB=A1=9D=20#353?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/global/config/TransactionConfig.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/page/clab/api/global/config/TransactionConfig.java diff --git a/src/main/java/page/clab/api/global/config/TransactionConfig.java b/src/main/java/page/clab/api/global/config/TransactionConfig.java new file mode 100644 index 000000000..ab0949b0b --- /dev/null +++ b/src/main/java/page/clab/api/global/config/TransactionConfig.java @@ -0,0 +1,16 @@ +package page.clab.api.global.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.TransactionDefinition; +import org.springframework.transaction.support.DefaultTransactionDefinition; + +@Configuration +public class TransactionConfig { + + @Bean + public TransactionDefinition transactionDefinition(){ + return new DefaultTransactionDefinition(); + } + +} From a12fb03e1a4633ea7691378c9fa1d40b0b1d3156 Mon Sep 17 00:00:00 2001 From: JaeHoonSong <128021502+SongJaeHoonn@users.noreply.github.com> Date: Tue, 25 Jun 2024 21:31:43 +0900 Subject: [PATCH 5/8] =?UTF-8?q?refactor:=20=EB=AA=A8=EC=A7=91=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EB=AC=B8=EC=9E=90=EC=97=B4=20=EC=82=AC=EC=9D=B4?= =?UTF-8?q?=EC=A6=88=20=EA=B4=80=EB=A0=A8=20message=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20#353?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/messages.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 6970588fd..5d1a5a4ad 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -44,7 +44,6 @@ size.product.name=서비스명은 최소 {min}글자 이상이어야 합니다. size.product.description=설명은 최소 {min}글자에서 {max}글자 사이어야 합니다. size.recruitment.applicationType=신청 유형은 최소 {min}자 이상이어야 합니다. size.recruitment.target=대상은 최소 {min}자 이상이어야 합니다. -size.recruitment.status=상태는 최소 {min}자 이상이어야 합니다. size.review.content=내용은 {min}자 이상 {max}자 이하여야 합니다. size.sharedAccount.username=유저명은 {min}자 이상이어야 합니다. size.sharedAccount.password=비밀번호는 {min}자 이상이어야 합니다. From 721951fb8ada888b6f35ef2745f700f614e5be52 Mon Sep 17 00:00:00 2001 From: JaeHoonSong <128021502+SongJaeHoonn@users.noreply.github.com> Date: Tue, 25 Jun 2024 21:33:08 +0900 Subject: [PATCH 6/8] =?UTF-8?q?refactor:=20=EB=AA=A8=EC=A7=91=20=EA=B3=B5?= =?UTF-8?q?=EA=B3=A0=20=EC=88=98=EC=A0=95=20=EC=8B=9C=EC=97=90=EB=8F=84=20?= =?UTF-8?q?=EC=A6=89=EA=B0=81=EC=A0=81=EC=9C=BC=EB=A1=9C=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EB=B0=98=EC=98=81=EB=90=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20#353?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruitment/application/RecruitmentService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/page/clab/api/domain/recruitment/application/RecruitmentService.java b/src/main/java/page/clab/api/domain/recruitment/application/RecruitmentService.java index 76a48b651..4ff344aa0 100644 --- a/src/main/java/page/clab/api/domain/recruitment/application/RecruitmentService.java +++ b/src/main/java/page/clab/api/domain/recruitment/application/RecruitmentService.java @@ -69,6 +69,7 @@ public Long updateRecruitment(Long recruitmentId, RecruitmentUpdateRequestDto re Recruitment recruitment = getRecruitmentByIdOrThrow(recruitmentId); recruitment.update(requestDto); validationService.checkValid(recruitment); + updateRecruitmentStatusByRecruitment(recruitment); return recruitmentRepository.save(recruitment).getId(); } @@ -92,9 +93,12 @@ public void updateRecruitmentStatus(){ public void updateRecruitmentStatusByRecruitment(Recruitment recruitment){ TransactionStatus transactionStatus = transactionManager.getTransaction(transactionDefinition); LocalDateTime now = LocalDateTime.now(); - RecruitmentStatus newStatus = now.isBefore(recruitment.getStartDate()) - ? RecruitmentStatus.UPCOMING : now.isAfter(recruitment.getEndDate()) - ? RecruitmentStatus.CLOSED : RecruitmentStatus.OPEN; + RecruitmentStatus newStatus = RecruitmentStatus.OPEN; + if(now.isBefore(recruitment.getStartDate())){ + newStatus = RecruitmentStatus.UPCOMING; + }else if(now.isAfter(recruitment.getEndDate())){ + newStatus = RecruitmentStatus.CLOSED; + } recruitment.updateStatus(newStatus); entityManager.merge(recruitment); transactionManager.commit(transactionStatus); From ac400771991800465a9b1e4b218dc5376d661879 Mon Sep 17 00:00:00 2001 From: JaeHoonSong <128021502+SongJaeHoonn@users.noreply.github.com> Date: Tue, 25 Jun 2024 21:33:57 +0900 Subject: [PATCH 7/8] =?UTF-8?q?refactor:=20=EB=9D=84=EC=96=B4=EC=93=B0?= =?UTF-8?q?=EA=B8=B0=20=EC=88=98=EC=A0=95=20#353?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/page/clab/api/global/config/TransactionConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/page/clab/api/global/config/TransactionConfig.java b/src/main/java/page/clab/api/global/config/TransactionConfig.java index ab0949b0b..74753ce61 100644 --- a/src/main/java/page/clab/api/global/config/TransactionConfig.java +++ b/src/main/java/page/clab/api/global/config/TransactionConfig.java @@ -9,7 +9,7 @@ public class TransactionConfig { @Bean - public TransactionDefinition transactionDefinition(){ + public TransactionDefinition transactionDefinition() { return new DefaultTransactionDefinition(); } From f551d89a334c7fa42681017fb875bb9c0666f929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=9C=EA=B4=80=ED=9D=AC?= Date: Tue, 25 Jun 2024 23:42:13 +0900 Subject: [PATCH 8/8] =?UTF-8?q?refactor(Recruitment):=20=EB=9D=84=EC=96=B4?= =?UTF-8?q?=EC=93=B0=EA=B8=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/recruitment/application/RecruitmentService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/page/clab/api/domain/recruitment/application/RecruitmentService.java b/src/main/java/page/clab/api/domain/recruitment/application/RecruitmentService.java index 4ff344aa0..c4c01507d 100644 --- a/src/main/java/page/clab/api/domain/recruitment/application/RecruitmentService.java +++ b/src/main/java/page/clab/api/domain/recruitment/application/RecruitmentService.java @@ -94,9 +94,9 @@ public void updateRecruitmentStatusByRecruitment(Recruitment recruitment){ TransactionStatus transactionStatus = transactionManager.getTransaction(transactionDefinition); LocalDateTime now = LocalDateTime.now(); RecruitmentStatus newStatus = RecruitmentStatus.OPEN; - if(now.isBefore(recruitment.getStartDate())){ + if (now.isBefore(recruitment.getStartDate())) { newStatus = RecruitmentStatus.UPCOMING; - }else if(now.isAfter(recruitment.getEndDate())){ + } else if(now.isAfter(recruitment.getEndDate())) { newStatus = RecruitmentStatus.CLOSED; } recruitment.updateStatus(newStatus);