diff --git a/src/main/java/com/backendsystemdesignlab/notification/notification/domain/DeliveryStatus.java b/src/main/java/com/backendsystemdesignlab/notification/notification/domain/DeliveryStatus.java new file mode 100644 index 0000000..4035644 --- /dev/null +++ b/src/main/java/com/backendsystemdesignlab/notification/notification/domain/DeliveryStatus.java @@ -0,0 +1,7 @@ +package com.backendsystemdesignlab.notification.notification.domain; + +public enum DeliveryStatus { + PENDING, + SENT, + FAILED +} diff --git a/src/main/java/com/backendsystemdesignlab/notification/notification/domain/Notification.java b/src/main/java/com/backendsystemdesignlab/notification/notification/domain/Notification.java new file mode 100644 index 0000000..4ae5637 --- /dev/null +++ b/src/main/java/com/backendsystemdesignlab/notification/notification/domain/Notification.java @@ -0,0 +1,80 @@ +package com.backendsystemdesignlab.notification.notification.domain; + +import com.backendsystemdesignlab.notification.user.domain.User; +import jakarta.persistence.*; + +import java.time.LocalDateTime; + +@Entity +@Table( + name = "notifications", + uniqueConstraints = { + @UniqueConstraint( + name = "uk_notification_event_id", + columnNames = "event_id" + ) + } +) +public class Notification { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "event_id", nullable = false, length = 100) + private String eventId; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @Enumerated(EnumType.STRING) + @Column(nullable = false, length = 20) + private NotificationStatus status; + + @Column(nullable = false, updatable = false) + private LocalDateTime createdAt; + + protected Notification() {} + + public Notification(String eventId, User user) { + this.eventId = eventId; + this.user = user; + this.status = NotificationStatus.PENDING; + this.createdAt = LocalDateTime.now(); + } + + public void startProcessing() { + this.status = NotificationStatus.PROCESSING; + } + + public void complete() { + this.status = NotificationStatus.COMPLETED; + } + + public void fail() { + this.status = NotificationStatus.FAILED; + } + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public String getEventId() { + return eventId; + } + + public User getUser() { + return user; + } + + public NotificationStatus getStatus() { + return status; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } +} diff --git a/src/main/java/com/backendsystemdesignlab/notification/notification/domain/NotificationDelivery.java b/src/main/java/com/backendsystemdesignlab/notification/notification/domain/NotificationDelivery.java new file mode 100644 index 0000000..df874af --- /dev/null +++ b/src/main/java/com/backendsystemdesignlab/notification/notification/domain/NotificationDelivery.java @@ -0,0 +1,86 @@ +package com.backendsystemdesignlab.notification.notification.domain; + +import com.backendsystemdesignlab.notification.user.domain.NotificationChannel; +import jakarta.persistence.*; + +import java.time.LocalDateTime; + +@Entity +@Table(name = "notification_deliveries") +public class NotificationDelivery { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "notification_id", nullable = false) + private Notification notification; + + @Enumerated(EnumType.STRING) + @Column(nullable = false, length = 20) + private NotificationChannel channel; + + @Column(nullable = false, length = 512) + private String destination; + + @Enumerated(EnumType.STRING) + @Column(nullable = false, length = 20) + private DeliveryStatus status; + + @Column(nullable = false) + private int attemptCount; + + private LocalDateTime sentAt; + + protected NotificationDelivery() {} + + public NotificationDelivery(Notification notification, NotificationChannel channel, String destination) { + this.notification = notification; + this.channel = channel; + this.destination = destination; + this.status = DeliveryStatus.PENDING; + this.attemptCount = 0; + } + + public void recordAttempt() { + this.attemptCount++; + } + + public void markSent() { + this.status = DeliveryStatus.SENT; + this.sentAt = LocalDateTime.now(); + } + + public void markFailed() { + this.status = DeliveryStatus.FAILED; + } + + public Long getId() { + return id; + } + + public Notification getNotification() { + return notification; + } + + public NotificationChannel getChannel() { + return channel; + } + + public String getDestination() { + return destination; + } + + public DeliveryStatus getStatus() { + return status; + } + + public int getAttemptCount() { + return attemptCount; + } + + public LocalDateTime getSentAt() { + return sentAt; + } +} diff --git a/src/main/java/com/backendsystemdesignlab/notification/notification/domain/NotificationStatus.java b/src/main/java/com/backendsystemdesignlab/notification/notification/domain/NotificationStatus.java new file mode 100644 index 0000000..4b7cf29 --- /dev/null +++ b/src/main/java/com/backendsystemdesignlab/notification/notification/domain/NotificationStatus.java @@ -0,0 +1,8 @@ +package com.backendsystemdesignlab.notification.notification.domain; + +public enum NotificationStatus { + PENDING, // 알림 생성 + PROCESSING, // 실제 채널 전송 중 + COMPLETED, // 모든 필요한 전송 처리 완료 + FAILED // 알림 처리 실패 +}