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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.backendsystemdesignlab.notification.notification.domain;

public enum DeliveryStatus {
PENDING,
SENT,
FAILED
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.backendsystemdesignlab.notification.notification.domain;

public enum NotificationStatus {
PENDING, // 알림 생성
PROCESSING, // 실제 채널 전송 중
COMPLETED, // 모든 필요한 전송 처리 완료
FAILED // 알림 처리 실패
}