Skip to content

Commit

Permalink
Merge pull request #140 from Modagbul/feat/alarm_minsu
Browse files Browse the repository at this point in the history
매일 자정에 7일 전 알림 삭제하는 스케줄러 추가
  • Loading branch information
minsu20 authored Dec 12, 2023
2 parents 5ff8105 + 3728fb3 commit 6cd1d44
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.moing.backend.domain.history.application.service;

import com.moing.backend.domain.history.domain.service.AlarmHistoryDeleteService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.concurrent.CompletableFuture;

@Service
@RequiredArgsConstructor
public class CleanupUseCase {

private final AlarmHistoryDeleteService alarmHistoryDeleteService;

@Scheduled(cron = "0 0 0 * * ?")
public void cleanupOldAlarmHistories() {
CompletableFuture.runAsync(() -> {
LocalDateTime oneWeekAgo = LocalDateTime.now().minusWeeks(1);
alarmHistoryDeleteService.deleteByCreatedDateBefore(oneWeekAgo);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.moing.backend.domain.history.domain.entity.AlarmHistory;
import org.springframework.data.jpa.repository.JpaRepository;

import java.time.LocalDateTime;
import java.util.Optional;

public interface AlarmHistoryRepository extends JpaRepository<AlarmHistory, Long>, AlarmHistoryCustomRepository {

Optional<AlarmHistory> findAlarmHistoryByIdAndReceiverId(Long id, Long receiverId);
void deleteByCreatedDateBefore(LocalDateTime dateTime);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.moing.backend.domain.history.domain.service;

import com.moing.backend.domain.history.domain.repository.AlarmHistoryRepository;
import com.moing.backend.global.annotation.DomainService;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@DomainService
@Transactional
@RequiredArgsConstructor
public class AlarmHistoryDeleteService {

private final AlarmHistoryRepository alarmHistoryRepository;

public void deleteByCreatedDateBefore(LocalDateTime oneWeekAgo) {
alarmHistoryRepository.deleteByCreatedDateBefore(oneWeekAgo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Table(indexes = @Index(name = "idx_social_id", columnList = "socialId"))
public class Member extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AuthControllerTest extends CommonControllerTest {
private SignInUseCase authService;

@MockBean
private SignUpUseCase signUpUserCase;
private SignUpUseCase signUpUseCase;

@MockBean
private ReissueTokenUseCase reissueTokenUseCase;
Expand Down Expand Up @@ -333,7 +333,7 @@ public void sign_up() throws Exception {
.build();


given(signUpUserCase.signUp(any(), any())).willReturn(output);
given(signUpUseCase.signUp(any(), any())).willReturn(output);

//when
ResultActions actions = mockMvc.perform(
Expand Down

0 comments on commit 6cd1d44

Please sign in to comment.