source: Git/src/main/java/com/wediscussmovies/project/model/Discussion.java@ 2a5d6a3

main
Last change on this file since 2a5d6a3 was 2a5d6a3, checked in by Petar Partaloski <ppartaloski@…>, 2 years ago

Controller, Repository and Service layer improvements, Entity updating

  • Property mode set to 100644
File size: 2.3 KB
Line 
1package com.wediscussmovies.project.model;
2
3import lombok.Data;
4
5import javax.persistence.*;
6import java.sql.Date;
7import java.util.List;
8
9@Data
10@Entity
11@Table (name="discussions")
12public 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
38 @Column(name = "type", nullable = false)
39 private DiscussionType type;
40 @OneToMany
41 private List<Reply> replies;
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
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 */
Note: See TracBrowser for help on using the repository browser.