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 | private Boolean approved;
|
---|
40 |
|
---|
41 | @ElementCollection
|
---|
42 | List<String> phoneNumbers;
|
---|
43 |
|
---|
44 | @ElementCollection
|
---|
45 | List<String> images;
|
---|
46 |
|
---|
47 | @ElementCollection
|
---|
48 | List<String> moderatorImages;
|
---|
49 |
|
---|
50 | @ManyToOne
|
---|
51 | @JoinColumn(
|
---|
52 | nullable = false,
|
---|
53 | name = "app_user_id"
|
---|
54 | )
|
---|
55 | private AppUser user;
|
---|
56 |
|
---|
57 | @ManyToOne
|
---|
58 | private Moderator moderator;
|
---|
59 |
|
---|
60 | @OneToMany
|
---|
61 | private List<FundsCollected> fundsCollected = new ArrayList<>();
|
---|
62 |
|
---|
63 | private Float totalFundsCollected = 0f;
|
---|
64 | private LocalDate createdAt;
|
---|
65 | private Integer riskFactor = 101;
|
---|
66 |
|
---|
67 | @Transient
|
---|
68 | public List<String> getImagesPath() {
|
---|
69 | if (images == null || id == null) return null;
|
---|
70 |
|
---|
71 | List<String> photoPaths = new ArrayList<>();
|
---|
72 | for(String path: images) {
|
---|
73 | photoPaths.add("../../../../post-photos/" + id + "/" + path);
|
---|
74 | }
|
---|
75 |
|
---|
76 | return photoPaths;
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Transient
|
---|
80 | public List<String> getModeratorPath() {
|
---|
81 | if (images == null || id == null) return null;
|
---|
82 |
|
---|
83 | List<String> photoPaths = new ArrayList<>();
|
---|
84 |
|
---|
85 | for(String path: images) {
|
---|
86 | photoPaths.add("../../../../post-photos/" + id + "/" + path);
|
---|
87 | }
|
---|
88 |
|
---|
89 | for(String path: moderatorImages) {
|
---|
90 | photoPaths.add("../../../../moderator-photos/" + id + "/" + path);
|
---|
91 | }
|
---|
92 |
|
---|
93 | return photoPaths;
|
---|
94 | }
|
---|
95 |
|
---|
96 | @Transient
|
---|
97 | public List<String> getPhotosForDeletion() {
|
---|
98 | if (images == null || id == null) return null;
|
---|
99 |
|
---|
100 | List<String> photoPaths = new ArrayList<>();
|
---|
101 | for(String path: images) {
|
---|
102 | photoPaths.add("post-photos\\" + id + "\\" + path);
|
---|
103 | }
|
---|
104 | photoPaths.add("post-photos\\" + id);
|
---|
105 |
|
---|
106 | for(String path: moderatorImages) {
|
---|
107 | photoPaths.add("moderator-photos\\" + id + "\\" + path);
|
---|
108 | }
|
---|
109 | photoPaths.add("moderator-photos\\" + id);
|
---|
110 |
|
---|
111 | return photoPaths;
|
---|
112 | }
|
---|
113 |
|
---|
114 | public DonationPost() {
|
---|
115 | }
|
---|
116 |
|
---|
117 | public Long getId() {
|
---|
118 | return id;
|
---|
119 | }
|
---|
120 |
|
---|
121 | public void setId(Long id) {
|
---|
122 | this.id = id;
|
---|
123 | }
|
---|
124 |
|
---|
125 | public String getTitle() {
|
---|
126 | return title;
|
---|
127 | }
|
---|
128 |
|
---|
129 | public void setTitle(String title) {
|
---|
130 | this.title = title;
|
---|
131 | }
|
---|
132 |
|
---|
133 | public String getDescription() {
|
---|
134 | return description;
|
---|
135 | }
|
---|
136 |
|
---|
137 | public void setDescription(String description) {
|
---|
138 | this.description = description;
|
---|
139 | }
|
---|
140 |
|
---|
141 | public float getFundsNeeded() {
|
---|
142 | return fundsNeeded;
|
---|
143 | }
|
---|
144 |
|
---|
145 | public void setFundsNeeded(float fundsNeeded) {
|
---|
146 | this.fundsNeeded = fundsNeeded;
|
---|
147 | }
|
---|
148 |
|
---|
149 | public String getCurrency() {
|
---|
150 | return currency;
|
---|
151 | }
|
---|
152 |
|
---|
153 | public void setCurrency(String currency) {
|
---|
154 | this.currency = currency;
|
---|
155 | }
|
---|
156 |
|
---|
157 | public LocalDate getDateDue() {
|
---|
158 | return dateDue;
|
---|
159 | }
|
---|
160 |
|
---|
161 | public void setDateDue(LocalDate dateDue) {
|
---|
162 | this.dateDue = dateDue;
|
---|
163 | }
|
---|
164 |
|
---|
165 | public String getBankAccount() {
|
---|
166 | return bankAccount;
|
---|
167 | }
|
---|
168 |
|
---|
169 | public void setBankAccount(String bankAccount) {
|
---|
170 | this.bankAccount = bankAccount;
|
---|
171 | }
|
---|
172 |
|
---|
173 | public Boolean getApproved() {
|
---|
174 | return approved;
|
---|
175 | }
|
---|
176 |
|
---|
177 | public void setApproved(Boolean approved) {
|
---|
178 | this.approved = approved;
|
---|
179 | }
|
---|
180 |
|
---|
181 | public List<String> getPhoneNumbers() {
|
---|
182 | return phoneNumbers;
|
---|
183 | }
|
---|
184 |
|
---|
185 | public void setPhoneNumbers(List<String> phoneNumbers) {
|
---|
186 | this.phoneNumbers = phoneNumbers;
|
---|
187 | }
|
---|
188 |
|
---|
189 | public List<String> getImages() {
|
---|
190 | return images;
|
---|
191 | }
|
---|
192 |
|
---|
193 | public void setImages(List<String> images) {
|
---|
194 | this.images = images;
|
---|
195 | }
|
---|
196 |
|
---|
197 | public List<String> getModeratorImages() {
|
---|
198 | return moderatorImages;
|
---|
199 | }
|
---|
200 |
|
---|
201 | public void setModeratorImages(List<String> moderatorImages) {
|
---|
202 | this.moderatorImages = moderatorImages;
|
---|
203 | }
|
---|
204 |
|
---|
205 | public AppUser getUser() {
|
---|
206 | return user;
|
---|
207 | }
|
---|
208 |
|
---|
209 | public void setUser(AppUser user) {
|
---|
210 | this.user = user;
|
---|
211 | }
|
---|
212 |
|
---|
213 | public Moderator getModerator() {
|
---|
214 | return moderator;
|
---|
215 | }
|
---|
216 |
|
---|
217 | public void setModerator(Moderator moderator) {
|
---|
218 | this.moderator = moderator;
|
---|
219 | }
|
---|
220 |
|
---|
221 | public List<FundsCollected> getFundsCollected() {
|
---|
222 | return fundsCollected;
|
---|
223 | }
|
---|
224 |
|
---|
225 | public void setFundsCollected(List<FundsCollected> fundsCollected) {
|
---|
226 | this.fundsCollected = fundsCollected;
|
---|
227 | }
|
---|
228 |
|
---|
229 | public Float getTotalFundsCollected() {
|
---|
230 | return totalFundsCollected;
|
---|
231 | }
|
---|
232 |
|
---|
233 | public void setTotalFundsCollected(Float totalFundsCollected) {
|
---|
234 | this.totalFundsCollected = totalFundsCollected;
|
---|
235 | }
|
---|
236 |
|
---|
237 | public LocalDate getCreatedAt() {
|
---|
238 | return createdAt;
|
---|
239 | }
|
---|
240 |
|
---|
241 | public void setCreatedAt(LocalDate createdAt) {
|
---|
242 | this.createdAt = createdAt;
|
---|
243 | }
|
---|
244 |
|
---|
245 | public Integer getRiskFactor() {
|
---|
246 | return riskFactor;
|
---|
247 | }
|
---|
248 |
|
---|
249 | public void setRiskFactor(Integer riskFactor) {
|
---|
250 | this.riskFactor = riskFactor;
|
---|
251 | }
|
---|
252 | }
|
---|