summaryrefslogtreecommitdiff
path: root/pse-server/src/main/java/org/psesquared/server/model/Subscription.java
blob: b130fcac08e451be29cbf25531a9868fa7b02fca (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package org.psesquared.server.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.NamedAttributeNode;
import jakarta.persistence.NamedEntityGraph;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;

/**
 * A podcast that was subscribed.
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "subscriptions")
@NamedEntityGraph(name = "graph.Subscription.episodes",
    attributeNodes = @NamedAttributeNode("episodes"))
public class Subscription implements Serializable {

  /**
   * A primary key for the table.
   */
  @JsonIgnore
  @Id
  @GeneratedValue(strategy=GenerationType.SEQUENCE)
  @Column(name = "id", updatable = false)
  private Long id;

  /**
   * The URL for the RSS-Feed of the Podcast.
   */
  @Column(name = "url", nullable = false)
  private String url;

  /**
   * The title of the Podcast.
   */
  @Column(name = "title")
  private String title;

  /**
   * Timestamp of the last time the RSS-Feed was fetched.
   */
  @Column(name = "timestamp")
  private long timestamp;

  /**
   * The list of SubscriptionActions of this podcast.
   */
  @JsonIgnore
  @OneToMany(mappedBy = "subscription",
      cascade = CascadeType.REMOVE)
  private List<SubscriptionAction> subscriptionActions;

  /**
   * The episodes of a subscription.
   */
  @JsonIgnore
  @OneToMany(mappedBy = "subscription", cascade = CascadeType.REMOVE)
  private final List<Episode> episodes = new ArrayList<>();

  /**
   * Adds an episode to the list of episodes.
   *
   * @param episode The to be added episode
   */
  public void addEpisode(@NonNull final Episode episode) {
    this.episodes.add(episode);
  }

}