diff --git a/src/main/java/com/fledge/fledgeserver/file/FileController.java b/src/main/java/com/fledge/fledgeserver/file/FileController.java index b1272e2..447ecf5 100644 --- a/src/main/java/com/fledge/fledgeserver/file/FileController.java +++ b/src/main/java/com/fledge/fledgeserver/file/FileController.java @@ -29,5 +29,4 @@ public ResponseEntity> getPresignedUrl( @Parameter(description = "파일 이름", required = true, example = "example.txt") @RequestParam(name = "fileName") String fileName) { return ApiResponse.success(SuccessStatus.FILE_RETRIEVAL_SUCCESS, fileService.getPresignedUrl(prefix, fileName)); } - } diff --git a/src/main/java/com/fledge/fledgeserver/scheduler/SupportExpirationScheduler.java b/src/main/java/com/fledge/fledgeserver/scheduler/SupportExpirationScheduler.java new file mode 100644 index 0000000..1676eef --- /dev/null +++ b/src/main/java/com/fledge/fledgeserver/scheduler/SupportExpirationScheduler.java @@ -0,0 +1,19 @@ +package com.fledge.fledgeserver.scheduler; + +import com.fledge.fledgeserver.challenge.service.ChallengeParticipationService; +import com.fledge.fledgeserver.support.service.SupportService; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class SupportExpirationScheduler { + private final SupportService supportService; + + @Scheduled(cron = "0 0 0 * * ?") // 매일 자정에 만료된 게시글 처리 + public void checkSupportPostExpiration() { + System.out.println("===START SupportPostExpirationScheduler==="); + supportService.checkAndExpireSupportPosts(); + } +} \ No newline at end of file diff --git a/src/main/java/com/fledge/fledgeserver/support/controller/SupportController.java b/src/main/java/com/fledge/fledgeserver/support/controller/SupportController.java index a92fdf2..9de9750 100644 --- a/src/main/java/com/fledge/fledgeserver/support/controller/SupportController.java +++ b/src/main/java/com/fledge/fledgeserver/support/controller/SupportController.java @@ -28,7 +28,7 @@ public class SupportController { @Operation(summary = "후원하기 게시글 등록", description = "후원하기 게시글을 등록합니다.(자립 준비 청소년만)\n" + - "\n" + // 추가적인 줄바꿈 + "\n" + "### promise\n" + "[ONCE, WEEKLY, MONTHLY]" + "\n" + diff --git a/src/main/java/com/fledge/fledgeserver/support/entity/SupportPost.java b/src/main/java/com/fledge/fledgeserver/support/entity/SupportPost.java index bfecf12..72f33f3 100644 --- a/src/main/java/com/fledge/fledgeserver/support/entity/SupportPost.java +++ b/src/main/java/com/fledge/fledgeserver/support/entity/SupportPost.java @@ -150,10 +150,15 @@ public void updateNotPending(PostUpdateRequest postUpdateRequest) { this.zip = postUpdateRequest.getZip(); } - - + // 첫 후원하기 시에 후원 진행 중 처리 "IN_PROGRESS" public void support() { this.supportPostStatus = SupportPostStatus.IN_PROGRESS; } + + // 현재 시점이 만료 시점을 지남 후원 종료 처리 "TERMINATED" + public void setExpiration() { this.supportPostStatus = SupportPostStatus.TERMINATED; } + + // 후원 물품 금액 달성 시 후원 완료 처리 "COMPLETED" + public void setCompleted() { this.supportPostStatus = SupportPostStatus.COMPLETED; } } diff --git a/src/main/java/com/fledge/fledgeserver/support/entity/SupportPostStatus.java b/src/main/java/com/fledge/fledgeserver/support/entity/SupportPostStatus.java index 84d1686..23a4405 100644 --- a/src/main/java/com/fledge/fledgeserver/support/entity/SupportPostStatus.java +++ b/src/main/java/com/fledge/fledgeserver/support/entity/SupportPostStatus.java @@ -10,7 +10,6 @@ public enum SupportPostStatus { COMPLETED("COMPLETED"), // 후원 금액 달성으로 종료 TERMINATED("TERMINATED"); // 후원 기간 말료로 종료 - private final String key; public String getKey() { return key; diff --git a/src/main/java/com/fledge/fledgeserver/support/repository/SupportPostRepository.java b/src/main/java/com/fledge/fledgeserver/support/repository/SupportPostRepository.java index edd1f49..dadfba4 100644 --- a/src/main/java/com/fledge/fledgeserver/support/repository/SupportPostRepository.java +++ b/src/main/java/com/fledge/fledgeserver/support/repository/SupportPostRepository.java @@ -4,6 +4,7 @@ import com.fledge.fledgeserver.exception.ErrorCode; import com.fledge.fledgeserver.support.entity.SupportCategory; import com.fledge.fledgeserver.support.entity.SupportPost; +import com.fledge.fledgeserver.support.entity.SupportPostStatus; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; @@ -44,13 +45,14 @@ Page findByCategoryAndSearchAndSupportPostStatusWithImages(@Param(" @Param("q") String q, @Param("status") String status, Pageable pageable); - - - - - - @Query("SELECT sp FROM SupportPost sp WHERE FUNCTION('DATEDIFF', sp.expirationDate, CURRENT_DATE) <= 7") Page findByExpirationDateWithinSevenDays(Pageable pageable); + // IN 절보다 AND +// List findAllBySupportPostStatusIn(List statuses); + // JPQL을 사용하여 PENDING 또는 IN_PROGRESS 상태의 SupportPost를 찾는 메서드 + @Query("SELECT sp FROM SupportPost sp WHERE sp.supportPostStatus = com.fledge.fledgeserver.support.entity.SupportPostStatus.PENDING " + + "OR sp.supportPostStatus = com.fledge.fledgeserver.support.entity.SupportPostStatus.IN_PROGRESS") + List findAllBySupportPostStatusOr(); + } diff --git a/src/main/java/com/fledge/fledgeserver/support/service/SupportService.java b/src/main/java/com/fledge/fledgeserver/support/service/SupportService.java index 8b5008a..2a56365 100644 --- a/src/main/java/com/fledge/fledgeserver/support/service/SupportService.java +++ b/src/main/java/com/fledge/fledgeserver/support/service/SupportService.java @@ -21,6 +21,8 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -294,4 +296,17 @@ public PostTotalPagingResponse deadlineApproachingPosts(int page) { return new PostTotalPagingResponse((int) totalElements, totalPages, supportPosts); } + @Transactional + public void checkAndExpireSupportPosts() { + LocalDate currentDate = LocalDate.now(); // 현재 날짜와 시간 가져오기 + List supportPosts = supportPostRepository.findAllBySupportPostStatusOr(); + System.out.println("supportPosts.size() = " + supportPosts.size()); + + supportPosts.stream() + .filter(supportPost -> supportPost.getExpirationDate().isBefore(currentDate)) // expirationDate가 현재 날짜보다 이전인 경우 + .forEach(supportPost -> { + supportPost.setExpiration(); // 만료 처리 메서드 호출 + supportPostRepository.save(supportPost); // 변경 사항 저장 + }); + } }