Files
no-copy/src/main/java/ru/soune/nocopy/entity/notification/Notification.java
T
vladp 5f063354e6
Test Workflow / test (push) Successful in 4s
dev add updateTime
2026-04-06 12:37:49 +07:00

59 lines
1.5 KiB
Java

package ru.soune.nocopy.entity.notification;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import ru.soune.nocopy.entity.user.User;
import java.time.LocalDateTime;
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Getter @Setter
@Builder
@Table(name = "notifications", indexes = {
@Index(name = "idx_user_status", columnList = "user_id, status"),
@Index(name = "idx_user_created", columnList = "user_id, created_at DESC")
})
public class Notification {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "created_at", updatable = false)
@CreatedDate
private LocalDateTime createdAt = LocalDateTime.now();
@LastModifiedDate
@Column(name = "updated_at")
private LocalDateTime updatedAt;
@Column(name = "message")
private String message;
@Enumerated(EnumType.STRING)
@Column(name = "notification_type")
private NotificationType notificationType;
@Column(name = "status")
private NotificationStatus status = NotificationStatus.NEW;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@JsonIgnore
private User user;
@PrePersist
public void prePersist() {
if (this.createdAt == null) {
this.createdAt = LocalDateTime.now();
}
this.updatedAt = LocalDateTime.now();
}
}