From 0e082f02d15635caf153e3590a4a5203768856cb Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 21 Oct 2024 19:00:27 +0900 Subject: [PATCH 1/3] =?UTF-8?q?#76=20:=20[style]=20:=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=EC=9D=84=20=EB=B3=80=EA=B2=BD=ED=95=9C?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../side/onetime/repository/custom/EventRepositoryCustom.java | 2 +- .../side/onetime/repository/custom/EventRepositoryImpl.java | 2 +- src/main/java/side/onetime/service/EventService.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/side/onetime/repository/custom/EventRepositoryCustom.java b/src/main/java/side/onetime/repository/custom/EventRepositoryCustom.java index fac70a2..b3f2032 100644 --- a/src/main/java/side/onetime/repository/custom/EventRepositoryCustom.java +++ b/src/main/java/side/onetime/repository/custom/EventRepositoryCustom.java @@ -3,5 +3,5 @@ import side.onetime.domain.Event; public interface EventRepositoryCustom { - void deleteUserEvent(Event event); + void deleteEvent(Event event); } \ No newline at end of file diff --git a/src/main/java/side/onetime/repository/custom/EventRepositoryImpl.java b/src/main/java/side/onetime/repository/custom/EventRepositoryImpl.java index e5b0803..521d29d 100644 --- a/src/main/java/side/onetime/repository/custom/EventRepositoryImpl.java +++ b/src/main/java/side/onetime/repository/custom/EventRepositoryImpl.java @@ -16,7 +16,7 @@ public class EventRepositoryImpl implements EventRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public void deleteUserEvent(Event e) { + public void deleteEvent(Event e) { queryFactory.delete(selection) .where(selection.schedule.event.eq(e)) .execute(); diff --git a/src/main/java/side/onetime/service/EventService.java b/src/main/java/side/onetime/service/EventService.java index 2ebb2ba..fb442f8 100644 --- a/src/main/java/side/onetime/service/EventService.java +++ b/src/main/java/side/onetime/service/EventService.java @@ -294,6 +294,6 @@ public void removeUserCreatedEvent(String authorizationHeader, String eventId) { throw new EventParticipationException(EventParticipationErrorResult._IS_NOT_USERS_CREATED_EVENT_PARTICIPATION); } - eventRepository.deleteUserEvent(event); + eventRepository.deleteEvent(event); } } \ No newline at end of file From a8669ebe3fe55ac51201f49acb2e2017474f2a56 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 21 Oct 2024 19:00:51 +0900 Subject: [PATCH 2/3] =?UTF-8?q?#76=20:=20[feat]=20:=20=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=A4=84=EB=9F=AC=20=EC=84=A4=EC=A0=95=EC=9D=84=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/side/onetime/global/config/SchedulerConfig.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/side/onetime/global/config/SchedulerConfig.java diff --git a/src/main/java/side/onetime/global/config/SchedulerConfig.java b/src/main/java/side/onetime/global/config/SchedulerConfig.java new file mode 100644 index 0000000..2f18ecd --- /dev/null +++ b/src/main/java/side/onetime/global/config/SchedulerConfig.java @@ -0,0 +1,9 @@ +package side.onetime.global.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; + +@Configuration +@EnableScheduling +public class SchedulerConfig { +} \ No newline at end of file From 8a011e5f5588a280cc5fec1227f90156d72afc07 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 21 Oct 2024 19:01:37 +0900 Subject: [PATCH 3/3] =?UTF-8?q?#76=20:=20[feat]=20:=20=ED=8A=B9=EC=A0=95?= =?UTF-8?q?=20=EC=8B=9C=EA=B8=B0=EB=A7=88=EB=8B=A4=2030=EC=9D=BC=EC=9D=B4?= =?UTF-8?q?=20=EC=A7=80=EB=82=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EB=93=A4?= =?UTF-8?q?=EC=9D=84=20=EC=A0=9C=EA=B1=B0=ED=95=A0=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onetime/repository/EventRepository.java | 3 ++ .../service/EventCleanupScheduler.java | 28 +++++++++++++++++++ src/main/resources/application.yaml | 5 +++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/main/java/side/onetime/service/EventCleanupScheduler.java diff --git a/src/main/java/side/onetime/repository/EventRepository.java b/src/main/java/side/onetime/repository/EventRepository.java index f85dafa..627c915 100644 --- a/src/main/java/side/onetime/repository/EventRepository.java +++ b/src/main/java/side/onetime/repository/EventRepository.java @@ -4,10 +4,13 @@ import side.onetime.domain.Event; import side.onetime.repository.custom.EventRepositoryCustom; +import java.time.LocalDateTime; +import java.util.List; import java.util.Optional; import java.util.UUID; public interface EventRepository extends JpaRepository, EventRepositoryCustom { Optional findByEventId(UUID eventId); boolean existsByEventId(UUID eventId); + List findByCreatedDateBefore(LocalDateTime twoWeeksAgo); } \ No newline at end of file diff --git a/src/main/java/side/onetime/service/EventCleanupScheduler.java b/src/main/java/side/onetime/service/EventCleanupScheduler.java new file mode 100644 index 0000000..5dd8d27 --- /dev/null +++ b/src/main/java/side/onetime/service/EventCleanupScheduler.java @@ -0,0 +1,28 @@ +package side.onetime.service; + +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import side.onetime.domain.Event; +import side.onetime.repository.EventRepository; + +import java.time.LocalDateTime; +import java.util.List; + +@Component +@RequiredArgsConstructor +public class EventCleanupScheduler { + + private final EventRepository eventRepository; + + @Scheduled(cron = "${scheduling.cron}") + @Transactional + public void deleteOldEvents() { + LocalDateTime thirtyDaysAgo = LocalDateTime.now().minusDays(30); + + // 30일 이상 지난 이벤트를 찾은 후 삭제 + List oldEvents = eventRepository.findByCreatedDateBefore(thirtyDaysAgo); + oldEvents.forEach(eventRepository::deleteEvent); + } +} \ No newline at end of file diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 11c2ce1..676a962 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -86,4 +86,7 @@ jwt: refresh-token: expiration-time: ${REFRESH_TOKEN_EXPIRATION_TIME} register-token: - expiration-time: ${REGISTER_TOKEN_EXPIRATION_TIME} \ No newline at end of file + expiration-time: ${REGISTER_TOKEN_EXPIRATION_TIME} + +scheduling: + cron: ${CRON} \ No newline at end of file