Changeset b8a8d06
- Timestamp:
- 10/16/21 15:07:33 (3 years ago)
- Branches:
- master
- Children:
- 2d8c0e7
- Parents:
- 7888b17
- Location:
- src/main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/it/finki/charitable/controller/DonationPostController.java
r7888b17 rb8a8d06 50 50 @RequestParam String telekom, 51 51 @RequestParam String a1, 52 @RequestParam(defaultValue = "202 1-01-01") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate dateDue,52 @RequestParam(defaultValue = "2020-01-01") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate dateDue, 53 53 @RequestParam String bankAccount, 54 54 @RequestParam MultipartFile titleImage, … … 56 56 @RequestParam MultipartFile[] moderatorImages) { 57 57 58 System.out.println(moderatorImages.length); 59 if(titleImage.isEmpty() || (moderatorImages.length == 1 && moderatorImages[0].isEmpty())) { 60 model.addAttribute("error", true); 61 return "upload"; 62 } 63 64 if(title.isBlank() || fundsNeeded.isBlank() || currency.isBlank() || description.isBlank() || bankAccount.isBlank() || dateDue.equals(LocalDate.of(2020,1,1))) { 65 model.addAttribute("error", true); 66 return "upload"; 67 } 68 58 69 DonationPost post = new DonationPost(); 59 70 post.setTitle(title); … … 61 72 try { 62 73 float funds = Float.parseFloat(fundsNeeded); 74 if (funds <= 0) { 75 model.addAttribute("error", true); 76 return "upload"; 77 } 63 78 post.setFundsNeeded(funds); 64 79 } catch (NumberFormatException e) { 65 e.printStackTrace(); 80 model.addAttribute("error", true); 81 return "upload"; 66 82 } 67 83 … … 215 231 } 216 232 217 @RequestMapping( "/donate")233 @RequestMapping(value="/donate", method = RequestMethod.POST) 218 234 public String donate(Model model, @RequestParam Long postid, 219 235 @RequestParam String cardName, … … 221 237 @RequestParam String expiryDate, 222 238 @RequestParam String cvv, 223 @RequestParam floatamount) {239 @RequestParam String amount) { 224 240 225 241 DonationPost post = donationPostService.getById(postid); 226 FundsCollected funds = new FundsCollected("Online donation", amount); 242 if(post == null || !post.getApproved()) { 243 return "index"; 244 } 245 246 float donatedAmount; 247 try { 248 donatedAmount = Float.parseFloat(amount); 249 if (donatedAmount <= 0) { 250 return String.format("redirect:/post?postid=%d&error", postid); 251 } 252 post.setFundsNeeded(donatedAmount); 253 } catch (NumberFormatException e) { 254 return String.format("redirect:/post?postid=%d&error", postid); 255 } 256 257 FundsCollected funds = new FundsCollected("Online donation", donatedAmount); 227 258 fundsCollectedService.save(funds); 228 259 … … 230 261 donationPostService.save(post); 231 262 232 DonationInformation donationInformation = new DonationInformation( amount, post.getId(), post.getTitle());263 DonationInformation donationInformation = new DonationInformation(donatedAmount, post.getId(), post.getTitle()); 233 264 donationInformationService.save(donationInformation); 234 265 MainUser user = (MainUser) userService.loadUserByUsername(SecurityContextHolder.getContext().getAuthentication().getName()); … … 239 270 } 240 271 241 @RequestMapping( "/report")272 @RequestMapping(value="/report", method = RequestMethod.POST) 242 273 public String report(@RequestParam Long postid, 243 274 @RequestParam String description) { -
src/main/resources/templates/post.html
r7888b17 rb8a8d06 77 77 Report 78 78 </button> 79 <div id="error" class="text-danger" hidden>Donation error</div> 79 80 80 81 <!-- Modal --> … … 197 198 </div> 198 199 <script src="/js/bootstrap.min.js"></script> 200 <script> 201 location.search 202 .substr(1) 203 .split("&") 204 .forEach(function (item) { 205 tmp = item.split("="); 206 if (tmp[0] === "error") { 207 document.getElementById("error").hidden = false; 208 } 209 }); 210 </script> 199 211 <script th:inline="javascript" th:unless="${notFound}" sec:authorize="isAuthenticated()"> 200 212 /*<![CDATA[*/ -
src/main/resources/templates/reportPost.html
r7888b17 rb8a8d06 71 71 72 72 <div th:if="${report}"> 73 <a class="btn btn-success" th:href="@{/moderator/dismiss(postid=${post.id})}">Dismiss </a>73 <a class="btn btn-success" th:href="@{/moderator/dismiss(postid=${post.id})}">Dismiss reports</a> 74 74 <button type="button" class="btn btn-danger" data-bs-toggle="modal" 75 75 data-bs-target="#staticBackdrop"> -
src/main/resources/templates/upload.html
r7888b17 rb8a8d06 16 16 <br/> 17 17 <div class="row"> 18 <div th:if="${error}" class="text-danger">Error uploading post</div> 18 19 <div class="col-md-4" id="left"> 19 20 <form th:action="@{/newPost}" method="post" id="myForm" enctype="multipart/form-data" class="row g-3">
Note:
See TracChangeset
for help on using the changeset viewer.