[6e7b472] | 1 | package com.wediscussmovies.project.model;
|
---|
| 2 |
|
---|
[7a0bf79] | 3 | import lombok.Data;
|
---|
| 4 |
|
---|
[6e7b472] | 5 | import javax.persistence.*;
|
---|
| 6 | import java.sql.Date;
|
---|
| 7 | import java.util.List;
|
---|
| 8 |
|
---|
[7a0bf79] | 9 | @Data
|
---|
[6e7b472] | 10 | @Entity
|
---|
[2a5d6a3] | 11 | @Table (name="discussions")
|
---|
[6e7b472] | 12 | public class Discussion {
|
---|
| 13 | @Id
|
---|
| 14 | @GeneratedValue
|
---|
| 15 | private int discussion_id;
|
---|
| 16 |
|
---|
| 17 | @ManyToOne
|
---|
| 18 | @Column(name = "movie_id")
|
---|
| 19 | private Movie movie;
|
---|
| 20 |
|
---|
| 21 | @ManyToOne()
|
---|
| 22 | @Column(name = "person_id")
|
---|
| 23 | private Person person;
|
---|
| 24 |
|
---|
| 25 | @ManyToOne
|
---|
| 26 | @Column(name = "user_id")
|
---|
| 27 | private User user;
|
---|
| 28 |
|
---|
| 29 | @Column(name = "text", length = 1000, nullable = false)
|
---|
| 30 | private String text;
|
---|
| 31 |
|
---|
| 32 | @Column(name = "title", length = 1000, nullable = false)
|
---|
| 33 | private String title;
|
---|
| 34 |
|
---|
| 35 | @Column(name = "date", nullable = false)
|
---|
| 36 | private Date date;
|
---|
| 37 |
|
---|
[2a5d6a3] | 38 | @Column(name = "type", nullable = false)
|
---|
| 39 | private DiscussionType type;
|
---|
[6e7b472] | 40 | @OneToMany
|
---|
| 41 | private List<Reply> replies;
|
---|
[2a5d6a3] | 42 |
|
---|
| 43 | public Discussion() {
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | public Discussion(String title, String text, User user, Movie movie, Date valueOf) {
|
---|
| 47 | this.title = title;
|
---|
| 48 | this.text = text;
|
---|
| 49 | this.user = user;
|
---|
| 50 | this.date = valueOf;
|
---|
| 51 | this.movie = movie;
|
---|
| 52 | this.type = DiscussionType.M;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public Discussion(String title, String text, User user, Person person, Date valueOf) {
|
---|
| 56 | this.title = title;
|
---|
| 57 | this.text = text;
|
---|
| 58 | this.user = user;
|
---|
| 59 | this.date = valueOf;
|
---|
| 60 | this.person = person;
|
---|
| 61 | this.type = DiscussionType.P;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 |
|
---|
[6e7b472] | 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | /*
|
---|
| 69 | create table discussions(
|
---|
| 70 | discussion_id serial primary key,
|
---|
| 71 | type char(1) not null,
|
---|
| 72 | text varchar(1000) not null,
|
---|
| 73 | title varchar(250) not null,
|
---|
| 74 | date date not null,
|
---|
| 75 | user_id integer not null,
|
---|
| 76 | movie_id integer,
|
---|
| 77 | person_id integer,
|
---|
| 78 | constraint fk_user_created foreign key (user_id) references users(user_id)
|
---|
| 79 | on delete cascade on update cascade,
|
---|
| 80 | constraint ck_type_discussion check( (type = 'M' and movie_id notnull and person_id isnull)
|
---|
| 81 | or (type='P' and person_id notnull and movie_id isnull)),
|
---|
| 82 | constraint fk_discussion_movie foreign key (movie_id) references movies(movie_id)
|
---|
| 83 | on delete cascade on update cascade,
|
---|
| 84 | constraint fk_discussion_person foreign key (person_id) references persons(person_id)
|
---|
| 85 | on delete cascade on update cascade
|
---|
| 86 | );
|
---|
| 87 |
|
---|
| 88 | */ |
---|