Changeset b8a8d06 for src/main/java/it
- Timestamp:
- 10/16/21 15:07:33 (3 years ago)
- Branches:
- master
- Children:
- 2d8c0e7
- Parents:
- 7888b17
- File:
-
- 1 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) {
Note:
See TracChangeset
for help on using the changeset viewer.