Notification.java
package com.newbit.notification.command.domain.aggregate;
import jakarta.persistence.*;
import lombok.*;
import java.time.LocalDateTime;
@Entity
@Table(name = "notification")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
public class Notification {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long notificationId;
private String content;
private Boolean isRead;
private Long serviceId;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "notification_type_id", nullable = false)
private NotificationType notificationType;
@Column(name = "user_id", nullable = false)
private Long userId;
public static Notification create(Long userId, NotificationType type, Long serviceId, String content) {
return Notification.builder()
.userId(userId)
.notificationType(type)
.serviceId(serviceId)
.content(content)
.isRead(false)
.createdAt(LocalDateTime.now())
.updatedAt(LocalDateTime.now())
.build();
}
public void markAsRead() {
this.isRead = true;
}
}