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 | @Transient
|
---|
64 | public List<String> getImagesPath() {
|
---|
65 | if (images == null || id == null) return null;
|
---|
66 |
|
---|
67 | List<String> photoPaths = new ArrayList<>();
|
---|
68 | for(String path: images) {
|
---|
69 | photoPaths.add("../../../../post-photos/" + id + "/" + path);
|
---|
70 | }
|
---|
71 |
|
---|
72 | return photoPaths;
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Transient
|
---|
76 | public List<String> getModeratorPath() {
|
---|
77 | if (images == null || id == null) return null;
|
---|
78 |
|
---|
79 | List<String> photoPaths = new ArrayList<>();
|
---|
80 |
|
---|
81 | for(String path: images) {
|
---|
82 | photoPaths.add("../../../../post-photos/" + id + "/" + path);
|
---|
83 | }
|
---|
84 |
|
---|
85 | for(String path: moderatorImages) {
|
---|
86 | photoPaths.add("../../../../moderator-photos/" + id + "/" + path);
|
---|
87 | }
|
---|
88 |
|
---|
89 | return photoPaths;
|
---|
90 | }
|
---|
91 |
|
---|
92 | @Transient
|
---|
93 | public List<String> getPhotosForDeletion() {
|
---|
94 | if (images == null || id == null) return null;
|
---|
95 |
|
---|
96 | List<String> photoPaths = new ArrayList<>();
|
---|
97 | for(String path: images) {
|
---|
98 | photoPaths.add("post-photos\\" + id + "\\" + path);
|
---|
99 | }
|
---|
100 | photoPaths.add("post-photos\\" + id);
|
---|
101 |
|
---|
102 | for(String path: moderatorImages) {
|
---|
103 | photoPaths.add("moderator-photos\\" + id + "\\" + path);
|
---|
104 | }
|
---|
105 | photoPaths.add("moderator-photos\\" + id);
|
---|
106 |
|
---|
107 | return photoPaths;
|
---|
108 | }
|
---|
109 |
|
---|
110 | public DonationPost() {
|
---|
111 | }
|
---|
112 |
|
---|
113 | public Long getId() {
|
---|
114 | return id;
|
---|
115 | }
|
---|
116 |
|
---|
117 | public void setId(Long id) {
|
---|
118 | this.id = id;
|
---|
119 | }
|
---|
120 |
|
---|
121 | public String getTitle() {
|
---|
122 | return title;
|
---|
123 | }
|
---|
124 |
|
---|
125 | public void setTitle(String title) {
|
---|
126 | this.title = title;
|
---|
127 | }
|
---|
128 |
|
---|
129 | public String getDescription() {
|
---|
130 | return description;
|
---|
131 | }
|
---|
132 |
|
---|
133 | public void setDescription(String description) {
|
---|
134 | this.description = description;
|
---|
135 | }
|
---|
136 |
|
---|
137 | public float getFundsNeeded() {
|
---|
138 | return fundsNeeded;
|
---|
139 | }
|
---|
140 |
|
---|
141 | public void setFundsNeeded(float fundsNeeded) {
|
---|
142 | this.fundsNeeded = fundsNeeded;
|
---|
143 | }
|
---|
144 |
|
---|
145 | public String getCurrency() {
|
---|
146 | return currency;
|
---|
147 | }
|
---|
148 |
|
---|
149 | public void setCurrency(String currency) {
|
---|
150 | this.currency = currency;
|
---|
151 | }
|
---|
152 |
|
---|
153 | public LocalDate getDateDue() {
|
---|
154 | return dateDue;
|
---|
155 | }
|
---|
156 |
|
---|
157 | public void setDateDue(LocalDate dateDue) {
|
---|
158 | this.dateDue = dateDue;
|
---|
159 | }
|
---|
160 |
|
---|
161 | public String getBankAccount() {
|
---|
162 | return bankAccount;
|
---|
163 | }
|
---|
164 |
|
---|
165 | public void setBankAccount(String bankAccount) {
|
---|
166 | this.bankAccount = bankAccount;
|
---|
167 | }
|
---|
168 |
|
---|
169 | public Boolean getApproved() {
|
---|
170 | return approved;
|
---|
171 | }
|
---|
172 |
|
---|
173 | public void setApproved(Boolean approved) {
|
---|
174 | this.approved = approved;
|
---|
175 | }
|
---|
176 |
|
---|
177 | public List<String> getPhoneNumbers() {
|
---|
178 | return phoneNumbers;
|
---|
179 | }
|
---|
180 |
|
---|
181 | public void setPhoneNumbers(List<String> phoneNumbers) {
|
---|
182 | this.phoneNumbers = phoneNumbers;
|
---|
183 | }
|
---|
184 |
|
---|
185 | public List<String> getImages() {
|
---|
186 | return images;
|
---|
187 | }
|
---|
188 |
|
---|
189 | public void setImages(List<String> images) {
|
---|
190 | this.images = images;
|
---|
191 | }
|
---|
192 |
|
---|
193 | public List<String> getModeratorImages() {
|
---|
194 | return moderatorImages;
|
---|
195 | }
|
---|
196 |
|
---|
197 | public void setModeratorImages(List<String> moderatorImages) {
|
---|
198 | this.moderatorImages = moderatorImages;
|
---|
199 | }
|
---|
200 |
|
---|
201 | public AppUser getUser() {
|
---|
202 | return user;
|
---|
203 | }
|
---|
204 |
|
---|
205 | public void setUser(AppUser user) {
|
---|
206 | this.user = user;
|
---|
207 | }
|
---|
208 |
|
---|
209 | public Moderator getModerator() {
|
---|
210 | return moderator;
|
---|
211 | }
|
---|
212 |
|
---|
213 | public void setModerator(Moderator moderator) {
|
---|
214 | this.moderator = moderator;
|
---|
215 | }
|
---|
216 |
|
---|
217 | public List<FundsCollected> getFundsCollected() {
|
---|
218 | return fundsCollected;
|
---|
219 | }
|
---|
220 |
|
---|
221 | public void setFundsCollected(List<FundsCollected> fundsCollected) {
|
---|
222 | this.fundsCollected = fundsCollected;
|
---|
223 | }
|
---|
224 | }
|
---|