Skip to content

Commit 5bf0207

Browse files
Merge pull request #215 from DevKor-github/main
[Merge] main to deploy
2 parents 70acbdf + 80f536d commit 5bf0207

15 files changed

Lines changed: 311 additions & 29 deletions

File tree

.idea/dataSources.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules/devkor.ontime-back.main.iml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules/ontime-back.main.iml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sqlDataSources.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package devkor.ontime_back.config;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.scheduling.TaskScheduler;
6+
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
7+
8+
@Configuration
9+
public class SchedulerConfig {
10+
11+
@Bean
12+
public TaskScheduler taskScheduler() {
13+
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
14+
scheduler.setPoolSize(20); // 필요시 더 늘릴 수 있음
15+
scheduler.setThreadNamePrefix("scheduler-");
16+
scheduler.initialize();
17+
return scheduler;
18+
}
19+
}

ontime-back/src/main/java/devkor/ontime_back/config/SwaggerConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
@Configuration
1616
@OpenAPIDefinition(
1717
servers = {
18-
@Server(url = "https://ontime.devkor.club", description = "Production Server")
18+
@Server(url = "https://ontime.devkor.club", description = "Production Server"),
19+
@Server(url = "http://localhost:8080", description = "Local Serever")
1920
}
2021
)
2122
public class SwaggerConfig {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package devkor.ontime_back.entity;
2+
3+
import jakarta.persistence.*;
4+
import lombok.AccessLevel;
5+
import lombok.Builder;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
9+
import java.time.LocalDateTime;
10+
11+
@Getter
12+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
13+
@Entity
14+
public class NotificationSchedule {
15+
16+
@Id
17+
@GeneratedValue(strategy = GenerationType.IDENTITY)
18+
private Long id;
19+
20+
private LocalDateTime notificationTime;
21+
22+
private Boolean isSent;
23+
24+
@OneToOne(fetch = FetchType.LAZY)
25+
@JoinColumn(name = "schedule_id")
26+
private Schedule schedule;
27+
28+
@Builder
29+
public NotificationSchedule(LocalDateTime notificationTime, Boolean isSent, Schedule schedule) {
30+
this.notificationTime = notificationTime;
31+
this.isSent = isSent;
32+
this.schedule = schedule;
33+
}
34+
35+
public void changeStatusToSent() {
36+
if(Boolean.FALSE.equals(this.isSent)) {
37+
this.isSent = true;
38+
}
39+
}
40+
41+
public void updateNotificationTime(LocalDateTime localDateTime) {
42+
this.notificationTime = localDateTime;
43+
}
44+
45+
public void markAsUnsent() {
46+
this.isSent = false;
47+
}
48+
49+
public void disconnectSchedule() {
50+
this.schedule = null;
51+
}
52+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package devkor.ontime_back.repository;
2+
3+
import devkor.ontime_back.entity.NotificationSchedule;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.data.jpa.repository.Query;
6+
import org.springframework.stereotype.Repository;
7+
8+
import java.time.LocalDateTime;
9+
import java.util.List;
10+
import java.util.Optional;
11+
import java.util.UUID;
12+
13+
@Repository
14+
public interface NotificationScheduleRepository extends JpaRepository<NotificationSchedule, Long> {
15+
@Query("SELECT n FROM NotificationSchedule n " +
16+
"JOIN FETCH n.schedule s " +
17+
"JOIN FETCH s.user " +
18+
"WHERE n.notificationTime > :now AND n.isSent = false")
19+
List<NotificationSchedule> findAllWithScheduleAndUser(LocalDateTime now);
20+
21+
Optional<NotificationSchedule> findByScheduleScheduleId(UUID scheduleId);
22+
}

ontime-back/src/main/java/devkor/ontime_back/response/ErrorCode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public enum ErrorCode {
2828
SCHEDULE_NOT_FOUND("1010", "해당 약속이 존재하지 않습니다.", HttpStatus.BAD_REQUEST),
2929
FIREBASE("1011", "FIREBASE로 메세지를 발송하였으나 오류가 발생했습니다.(유효하지 않은 토큰 등)", HttpStatus.BAD_REQUEST),
3030
FIRST_PREPARATION_NOT_FOUND("1012", "해당 ID의 사용자의 준비과정을 찾을 수 없습니다.", HttpStatus.BAD_REQUEST),
31-
31+
NOTIFICATION_NOT_FOUND("1013", "알림을 찾을 수 없습니다.", HttpStatus.BAD_REQUEST ),
3232

3333
// 공통 오류 메시지
34-
UNEXPECTED_ERROR("1000", "Unexpected Error: An unexpected error occurred.", HttpStatus.INTERNAL_SERVER_ERROR);
34+
UNEXPECTED_ERROR("1000", "Unexpected Error: An unexpected error occurred.", HttpStatus.INTERNAL_SERVER_ERROR),;
3535

3636
private final String code;
3737
private final String message;

ontime-back/src/main/java/devkor/ontime_back/scheduler/NotificationScheduler.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,5 @@ public void sendMorningReminder() {
4848
List<Schedule> schedulesForToday = scheduleRepository.findSchedulesBetween(startOfToday, endOfToday);
4949
notificationService.sendReminder(schedulesForToday, "오늘 예정된 약속이 있습니다.");
5050
}
51-
52-
@Scheduled(cron = "0 * * * * *") // 매 분의 0초에 실행
53-
public void sendFiveMinutesBeforeReminder() {
54-
LocalDateTime baseTime = LocalDateTime.now().plusMinutes(5); // 현재 시간
55-
LocalDateTime startTime = baseTime.withSecond(0).withNano(0); // 초와 나노초 제거 (분 단위로 설정)
56-
LocalDateTime endTime = startTime.plusMinutes(1).minusNanos(1); // 다음 분의 직전까지
57-
58-
System.out.println("5분 후 시간: " + baseTime);
59-
60-
// 5분 후의 scheduleTime과 일치하는 약속 조회
61-
List<Schedule> schedulesStartingSoon = scheduleRepository.findSchedulesBetween(startTime, endTime);
62-
63-
for(Schedule schedule : schedulesStartingSoon) {
64-
System.out.println("5분 뒤의 약속: " + schedule.getScheduleName());
65-
}
66-
67-
// 알림 전송
68-
notificationService.sendReminder(schedulesStartingSoon, "약속 5분 전입니다. 준비하세요.");
69-
}
7051
}
7152

0 commit comments

Comments
 (0)