Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/mysql/initdb.d/create_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ CREATE TABLE notification
name VARCHAR(255),
content VARCHAR(255),
notification_type ENUM ('RESERVATION_REQUESTED','RESERVATION_CANCEL_REQUEST','RESERVATION_CHANGE_REQUEST',
'SESSION_COMPLETED','CONNECT', 'CONNECT_RESPONSE','DISCONNECT','RESERVATION_CHANGE_REQUEST_APPROVED','RESERVATION_CHANGE_REQUEST_REFUSED',
'SESSION_COMPLETED','SESSION_FINISHED', 'CONNECT', 'CONNECT_RESPONSE','DISCONNECT','RESERVATION_CHANGE_REQUEST_APPROVED','RESERVATION_CHANGE_REQUEST_REFUSED',
'RESERVATION_APPROVE','RESERVATION_CANCEL', 'RESERVATION_REFUSE', 'SESSION_DEDUCTED','SESSION_REMINDER',
'RESERVATION_CANCEL_REQUEST_APPROVED','RESERVATION_CANCEL_REQUEST_REFUSED','SESSION_REMAIN_5','SESSION_EDITED',
'DISCONNECT_TRAINER'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static spring.fitlinkbe.domain.common.enums.UserRole.MEMBER;
import static spring.fitlinkbe.domain.common.enums.UserRole.TRAINER;
import static spring.fitlinkbe.domain.notification.Notification.Reason.RESERVATION_CANCEL;
import static spring.fitlinkbe.domain.reservation.Reservation.Status.RESERVATION_APPROVED;

@Component
@RequiredArgsConstructor
Expand Down Expand Up @@ -423,4 +424,22 @@ public List<Reservation> releaseFixedReservation(Long reservationId) {
return reservationService.releaseFixedReservation(reservationId);
}

@Transactional
public void sendSessionCompleteReminder() {
List<Reservation> inProgressReservations = reservationService.getInProgressReservations();

inProgressReservations.forEach(r -> {
Session session = reservationService.getSession(RESERVATION_APPROVED, r.getReservationId());
PersonalDetail trainerDetail = trainerService.getTrainerDetail(r.getTrainer().getTrainerId());
Token token = authService.getTokenByPersonalDetailId(trainerDetail.getPersonalDetailId());

notificationService.sendNotification(NotificationCommand.SessionCompleteReminder.of(
trainerDetail,
session.getSessionId(),
r.getMember().getMemberId(),
r.getName(),
token.getPushToken()));
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,24 @@ public static Notification requestReservation(PersonalDetail trainerDetail, Long
.build();
}

public static Notification completeReminderSession(PersonalDetail trainerDetail, Long sessionId,
Long memberId, String name) {

String content = " %s 회원님의 PT가 곧 종료됩니다. 세션 참석 여부를 확인해주세요.".formatted(name);

return Notification.builder()
.refId(sessionId)
.refType(ReferenceType.SESSION)
.target(UserRole.TRAINER)
.notificationType(NotificationType.SESSION_FINISHED)
.personalDetail(trainerDetail)
.partnerId(memberId)
.name(NotificationType.SESSION_FINISHED.name)
.content(content)
.sendDate(LocalDateTime.now())
.build();
}

public static Notification completeSession(PersonalDetail memberDetail, Long sessionId,
Long memberId, String name) {

Expand Down Expand Up @@ -342,6 +360,7 @@ public enum NotificationType {
CONNECT("트레이너 연동 요청", "트레이너와 연동 요청이 왔습니다."),
CONNECT_RESPONSE("트레이너 연동 처리", "트레이너와 연동 요청 결과가 생성되었습니다."),
DISCONNECT("트레이너 연동 해제", "회원과 연동이 해제되었습니다."),
SESSION_FINISHED("세션 곧 종료", "곧 세션이 종료됩니다. 세션 완료 여부를 처리해주세요."),

//회원
RESERVATION_CHANGE_REQUEST_APPROVED("예약 변경 요청 승인", "예약 변경 요청이 승인 되었습니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void init() {
strategyMap.put(Notification.NotificationType.RESERVATION_REQUESTED, this::handleRequestReservation);
strategyMap.put(Notification.NotificationType.SESSION_COMPLETED, this::handleCompleteSession);
strategyMap.put(Notification.NotificationType.SESSION_DEDUCTED, this::handleDeductSession);
strategyMap.put(Notification.NotificationType.SESSION_FINISHED, this::handleCompleteReminderSession);
strategyMap.put(Notification.NotificationType.RESERVATION_CHANGE_REQUEST, this::handleChangeRequestReservation);
strategyMap.put(Notification.NotificationType.RESERVATION_CANCEL_REQUEST_APPROVED, this::handleCancelApproveReservation);
strategyMap.put(Notification.NotificationType.RESERVATION_CANCEL_REQUEST_REFUSED, this::handleCancelApproveReservation);
Expand Down Expand Up @@ -102,6 +103,11 @@ private Notification handleCompleteSession(NotificationRequest request) {
return Notification.completeSession(dto.trainerDetail(), dto.sessionId(), dto.memberId(), dto.name());
}

private Notification handleCompleteReminderSession(NotificationRequest request) {
NotificationCommand.SessionCompleteReminder dto = (NotificationCommand.SessionCompleteReminder) request;
return Notification.completeReminderSession(dto.trainerDetail(), dto.sessionId(), dto.memberId(), dto.name());
}

private Notification handleDeductSession(NotificationRequest request) {
NotificationCommand.DeductSession dto = (NotificationCommand.DeductSession) request;
return Notification.deductSession(dto.memberDetail(), dto.sessionId(), dto.trainerId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,33 @@ public static SessionChargeReminder of(PersonalDetail memberDetail, Long session
}

}

@Builder
public record SessionCompleteReminder(PersonalDetail trainerDetail, Long sessionId, Long memberId,
String name,
String pushToken)
implements NotificationRequest {
@Override
public Notification.NotificationType getType() {
return Notification.NotificationType.SESSION_FINISHED;
}

@Override
public String getPushToken() {
return this.pushToken;
}

public static SessionCompleteReminder of(PersonalDetail trainerDetail, Long sessionId, Long memberId,
String name,
String pushToken) {
return SessionCompleteReminder.builder()
.trainerDetail(trainerDetail)
.sessionId(sessionId)
.memberId(memberId)
.name(name)
.pushToken(pushToken)
.build();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import static spring.fitlinkbe.domain.common.exception.ErrorCode.RESERVATION_WAITING_MEMBERS_EMPTY;
import static spring.fitlinkbe.domain.common.exception.ErrorCode.SESSION_CREATE_FAILED;
import static spring.fitlinkbe.domain.reservation.Reservation.Status;
import static spring.fitlinkbe.domain.reservation.Reservation.Status.DISABLED_TIME_RESERVATION;
import static spring.fitlinkbe.domain.reservation.Reservation.Status.RESERVATION_WAITING;
import static spring.fitlinkbe.domain.reservation.Reservation.Status.*;
import static spring.fitlinkbe.domain.reservation.Reservation.getEndDate;
import static spring.fitlinkbe.domain.reservation.Session.Status.SESSION_WAITING;

Expand Down Expand Up @@ -355,6 +354,15 @@ public void cancelLastFixedReservation(Long memberId, String message) {
}
}

public List<Reservation> getInProgressReservations() {
List<Reservation> reservations = reservationRepository.getReservations();

return reservations.stream()
.filter(r -> r.getStatus() == RESERVATION_APPROVED)
.filter(r -> r.getConfirmDate().getHour() == LocalDateTime.now().getHour())
.toList();
}

/**
* Related Session
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ApiResultResponse<List<ReservationResponseDto.Summary>> getReservations(@
@RoleCheck(allowedRoles = {UserRole.MEMBER})
@GetMapping("/trainers")
public ApiResultResponse<List<ReservationResponseDto.Summary>> getTrainerReservations(@RequestParam LocalDate date,
@Login SecurityUser user) {
@Login SecurityUser user) {

List<Reservation> result = reservationFacade.getTrainerReservations(date, user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ public void sessionReminder() {
reservationFacade.checkTodaySessionReminder();
}

/**
* 매일 매 50분마다, 세션 완료 처리를 해야한다는 알림을 보낸다.
*/
@Scheduled(cron = "0 50 * * * *") // 매일 00:50:00에 실행
public void confirmSessionReminder() {
reservationFacade.sendSessionCompleteReminder();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.time.LocalTime;
import java.util.List;
import java.util.Objects;

import java.util.stream.Stream;

public class MemberIntegrationTest extends BaseIntegrationTest {
Expand Down
Loading