-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserSubscriptionEntity.java
More file actions
57 lines (46 loc) · 1.32 KB
/
UserSubscriptionEntity.java
File metadata and controls
57 lines (46 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package org.openpodcastapi.opa.subscription;
import jakarta.persistence.*;
import lombok.*;
import org.openpodcastapi.opa.user.UserEntity;
import java.time.Instant;
import java.util.UUID;
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
@Table(name = "user_subscription")
public class UserSubscriptionEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Generated
private Long id;
@Column(unique = true, nullable = false, updatable = false, columnDefinition = "uuid")
private UUID uuid;
@ManyToOne
@JoinColumn(name = "user_id")
private UserEntity user;
@ManyToOne
@JoinColumn(name = "subscription_id")
private SubscriptionEntity subscription;
@Column(nullable = false, updatable = false)
private Instant createdAt;
@Column(nullable = false)
private Instant updatedAt;
@Column
private Instant unsubscribedAt;
@PrePersist
public void prePersist() {
this.setUuid(UUID.randomUUID());
final Instant timestamp = Instant.now();
// Store the created date and set an updated timestamp
this.setCreatedAt(timestamp);
this.setUpdatedAt(timestamp);
}
@PreUpdate
public void preUpdate() {
// Store the timestamp of the update
this.setUpdatedAt(Instant.now());
}
}