1 | package it.finki.charitable.entities;
|
---|
2 |
|
---|
3 | import javax.persistence.*;
|
---|
4 | import java.time.LocalDate;
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | @Entity
|
---|
9 | @Table(name = "donation_post")
|
---|
10 | public class DonationPost {
|
---|
11 |
|
---|
12 | @SequenceGenerator(
|
---|
13 | name = "donation_post_sequence",
|
---|
14 | sequenceName = "donation_post_sequence",
|
---|
15 | allocationSize = 1
|
---|
16 | )
|
---|
17 | @GeneratedValue(
|
---|
18 | strategy = GenerationType.SEQUENCE,
|
---|
19 | generator = "donation_post_sequence"
|
---|
20 | )
|
---|
21 | @Id
|
---|
22 | @Column(
|
---|
23 | name = "id",
|
---|
24 | nullable = false,
|
---|
25 | updatable = false
|
---|
26 | )
|
---|
27 | private Long id;
|
---|
28 |
|
---|
29 | private String title;
|
---|
30 | @Column(
|
---|
31 | name = "description",
|
---|
32 | columnDefinition = "TEXT"
|
---|
33 | )
|
---|
34 | private String description;
|
---|
35 | private float fundsNeeded;
|
---|
36 | private String currency;
|
---|
37 | private LocalDate dateDue;
|
---|
38 | private String bankAccount;
|
---|
39 |
|
---|
40 | @ElementCollection
|
---|
41 | List<String> phoneNumbers;
|
---|
42 |
|
---|
43 | @ElementCollection
|
---|
44 | List<String> images;
|
---|
45 |
|
---|
46 | @ElementCollection
|
---|
47 | List<String> moderatorImages;
|
---|
48 |
|
---|
49 | @ManyToOne
|
---|
50 | @JoinColumn(
|
---|
51 | nullable = false,
|
---|
52 | name = "app_user_id"
|
---|
53 | )
|
---|
54 | private AppUser user;
|
---|
55 |
|
---|
56 | @OneToMany
|
---|
57 | private List<FundsCollected> fundsCollected = new ArrayList<>();
|
---|
58 |
|
---|
59 | @Transient
|
---|
60 | public List<String> getImagesPath() {
|
---|
61 | if (images == null || id == null) return null;
|
---|
62 |
|
---|
63 | List<String> photoPaths = new ArrayList<>();
|
---|
64 | for(String path: images) {
|
---|
65 | photoPaths.add("../../../../post-photos/" + id + "/" + path);
|
---|
66 | }
|
---|
67 |
|
---|
68 | return photoPaths;
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Transient
|
---|
72 | public List<String> getModeratorPath() {
|
---|
73 | if (images == null || id == null) return null;
|
---|
74 |
|
---|
75 | List<String> photoPaths = new ArrayList<>();
|
---|
76 | for(String path: images) {
|
---|
77 | photoPaths.add("../../../../moderator-photos/" + id + "/" + path);
|
---|
78 | }
|
---|
79 |
|
---|
80 | return photoPaths;
|
---|
81 | }
|
---|
82 |
|
---|
83 | @Transient
|
---|
84 | public List<String> getPhotosForDeletion() {
|
---|
85 | if (images == null || id == null) return null;
|
---|
86 |
|
---|
87 | List<String> photoPaths = new ArrayList<>();
|
---|
88 | for(String path: images) {
|
---|
89 | photoPaths.add("post-photos\\" + id + "\\" + path);
|
---|
90 | }
|
---|
91 | photoPaths.add("post-photos\\" + id);
|
---|
92 |
|
---|
93 | for(String path: moderatorImages) {
|
---|
94 | photoPaths.add("moderator-photos\\" + id + "\\" + path);
|
---|
95 | }
|
---|
96 | photoPaths.add("moderator-photos\\" + id);
|
---|
97 |
|
---|
98 | return photoPaths;
|
---|
99 | }
|
---|
100 |
|
---|
101 | public DonationPost() {
|
---|
102 | }
|
---|
103 |
|
---|
104 | public Long getId() {
|
---|
105 | return id;
|
---|
106 | }
|
---|
107 |
|
---|
108 | public void setId(Long id) {
|
---|
109 | this.id = id;
|
---|
110 | }
|
---|
111 |
|
---|
112 | public String getTitle() {
|
---|
113 | return title;
|
---|
114 | }
|
---|
115 |
|
---|
116 | public void setTitle(String title) {
|
---|
117 | this.title = title;
|
---|
118 | }
|
---|
119 |
|
---|
120 | public String getDescription() {
|
---|
121 | return description;
|
---|
122 | }
|
---|
123 |
|
---|
124 | public void setDescription(String description) {
|
---|
125 | this.description = description;
|
---|
126 | }
|
---|
127 |
|
---|
128 | public float getFundsNeeded() {
|
---|
129 | return fundsNeeded;
|
---|
130 | }
|
---|
131 |
|
---|
132 | public void setFundsNeeded(float fundsNeeded) {
|
---|
133 | this.fundsNeeded = fundsNeeded;
|
---|
134 | }
|
---|
135 |
|
---|
136 | public String getCurrency() {
|
---|
137 | return currency;
|
---|
138 | }
|
---|
139 |
|
---|
140 | public void setCurrency(String currency) {
|
---|
141 | this.currency = currency;
|
---|
142 | }
|
---|
143 |
|
---|
144 | public LocalDate getDateDue() {
|
---|
145 | return dateDue;
|
---|
146 | }
|
---|
147 |
|
---|
148 | public void setDateDue(LocalDate dateDue) {
|
---|
149 | this.dateDue = dateDue;
|
---|
150 | }
|
---|
151 |
|
---|
152 | public String getBankAccount() {
|
---|
153 | return bankAccount;
|
---|
154 | }
|
---|
155 |
|
---|
156 | public void setBankAccount(String bankAccount) {
|
---|
157 | this.bankAccount = bankAccount;
|
---|
158 | }
|
---|
159 |
|
---|
160 | public List<String> getPhoneNumbers() {
|
---|
161 | return phoneNumbers;
|
---|
162 | }
|
---|
163 |
|
---|
164 | public void setPhoneNumbers(List<String> phoneNumbers) {
|
---|
165 | this.phoneNumbers = phoneNumbers;
|
---|
166 | }
|
---|
167 |
|
---|
168 | public List<String> getImages() {
|
---|
169 | return images;
|
---|
170 | }
|
---|
171 |
|
---|
172 | public void setImages(List<String> images) {
|
---|
173 | this.images = images;
|
---|
174 | }
|
---|
175 |
|
---|
176 | public List<String> getModeratorImages() {
|
---|
177 | return moderatorImages;
|
---|
178 | }
|
---|
179 |
|
---|
180 | public void setModeratorImages(List<String> moderatorImages) {
|
---|
181 | this.moderatorImages = moderatorImages;
|
---|
182 | }
|
---|
183 |
|
---|
184 | public AppUser getUser() {
|
---|
185 | return user;
|
---|
186 | }
|
---|
187 |
|
---|
188 | public void setUser(AppUser user) {
|
---|
189 | this.user = user;
|
---|
190 | }
|
---|
191 |
|
---|
192 | public List<FundsCollected> getFundsCollected() {
|
---|
193 | return fundsCollected;
|
---|
194 | }
|
---|
195 |
|
---|
196 | public void setFundsCollected(List<FundsCollected> fundsCollected) {
|
---|
197 | this.fundsCollected = fundsCollected;
|
---|
198 | }
|
---|
199 | }
|
---|