Matthias Andreas Benkard | 4982faa | 2021-02-24 06:45:39 +0100 | [diff] [blame] | 1 | package eu.mulk.demos.blog; |
| 2 | |
| 3 | import io.quarkus.hibernate.orm.panache.PanacheEntity; |
| 4 | import java.time.Instant; |
| 5 | import java.util.List; |
| 6 | import javax.persistence.Column; |
| 7 | import javax.persistence.Entity; |
| 8 | import javax.persistence.FetchType; |
| 9 | import javax.persistence.ManyToMany; |
| 10 | import javax.persistence.ManyToOne; |
| 11 | import javax.persistence.OneToMany; |
| 12 | |
| 13 | @Entity |
| 14 | public class Post extends PanacheEntity { |
| 15 | |
| 16 | public String title; |
| 17 | |
| 18 | public Instant publicationDate; |
| 19 | |
| 20 | @Column(columnDefinition = "TEXT") |
| 21 | public String body; |
| 22 | |
| 23 | @ManyToOne(fetch = FetchType.LAZY) |
| 24 | public Author author; |
| 25 | |
| 26 | @ManyToMany(fetch = FetchType.LAZY) |
| 27 | public List<Category> categories; |
| 28 | |
Matthias Andreas Benkard | 0c009e8 | 2021-02-26 07:23:27 +0100 | [diff] [blame^] | 29 | @OneToMany(fetch = FetchType.LAZY, mappedBy = "post") |
Matthias Andreas Benkard | 4982faa | 2021-02-24 06:45:39 +0100 | [diff] [blame] | 30 | public List<Comment> comments; |
Matthias Andreas Benkard | 0c009e8 | 2021-02-26 07:23:27 +0100 | [diff] [blame^] | 31 | |
| 32 | public static Post create(Author author, String title) { |
| 33 | var p = new Post(); |
| 34 | p.title = title; |
| 35 | p.publicationDate = Instant.now(); |
| 36 | p.body = ""; |
| 37 | p.author = author; |
| 38 | return p; |
| 39 | } |
Matthias Andreas Benkard | 4982faa | 2021-02-24 06:45:39 +0100 | [diff] [blame] | 40 | } |