Changeset f8007b3
- Timestamp:
- 09/03/21 11:34:33 (3 years ago)
- Branches:
- master
- Children:
- 194776a
- Parents:
- f0d5cb7
- Location:
- src/main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/it/finki/charitable/controller/UserProfileController.java
rf0d5cb7 rf8007b3 1 1 package it.finki.charitable.controller; 2 2 3 import it.finki.charitable.entities.AppUser; 4 import it.finki.charitable.entities.DonationInformation; 5 import it.finki.charitable.entities.DonationPost; 6 import it.finki.charitable.entities.MainUser; 3 import it.finki.charitable.entities.*; 7 4 import it.finki.charitable.security.PasswordEncoder; 8 5 import it.finki.charitable.services.DonationPostService; 6 import it.finki.charitable.services.FundsCollectedService; 9 7 import it.finki.charitable.services.UserService; 10 8 import org.springframework.security.core.context.SecurityContextHolder; … … 23 21 private final UserService userService; 24 22 private final DonationPostService donationPostService; 23 private final FundsCollectedService fundsCollectedService; 25 24 26 public UserProfileController(UserService userService, DonationPostService donationPostService ) {25 public UserProfileController(UserService userService, DonationPostService donationPostService, FundsCollectedService fundsCollectedService) { 27 26 this.userService = userService; 28 27 this.donationPostService = donationPostService; 28 this.fundsCollectedService = fundsCollectedService; 29 29 } 30 30 … … 105 105 } 106 106 107 @RequestMapping("/addFunds") 108 public String addFunds(@RequestParam Long postid, 109 @RequestParam String type, 110 @RequestParam float amount) { 111 112 DonationPost post = donationPostService.getById(postid); 113 FundsCollected funds = new FundsCollected(type, amount); 114 fundsCollectedService.save(funds); 115 116 post.getFundsCollected().add(funds); 117 donationPostService.save(post); 118 return "redirect:/myPosts"; 119 } 120 107 121 @ModelAttribute("user") 108 122 public AppUser addAttributes() { -
src/main/resources/templates/myProfile.html
rf0d5cb7 rf8007b3 241 241 <a class="btn btn-sm btn-outline-secondary" 242 242 th:href="@{/post(postid=${post.id})}">Open</a> 243 <a class="btn btn-sm btn-success" href="#">Add Collected Funds</a> 243 <button type="button" class="btn btn-primary" data-bs-toggle="modal" 244 th:data-bs-target="'#a' + ${post.id}"> 245 Add collected funds 246 </button> 244 247 <a class="btn btn-sm btn-danger" 245 248 th:href="@{/deletePost(postid=${post.id})}">Delete</a> … … 250 253 <img th:src="${post.imagesPath[0]}" width="200" height="250" 251 254 style="object-fit: contain"> 255 </div> 256 </div> 257 <div class="modal fade" th:id="'a' + ${post.id}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" 258 aria-labelledby="staticBackdropLabel" aria-hidden="true"> 259 <div class="modal-dialog modal-dialog-centered"> 260 <div class="modal-content"> 261 <div class="modal-header"> 262 <h5 class="modal-title" id="staticBackdropLabel">Add funds</h5> 263 <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> 264 </div> 265 <div class="modal-body"> 266 <div class="card-body"> 267 <form th:id="'my-form' + ${post.id}" th:action="@{/addFunds(postid=${post.id})}" method="post"> 268 <div class="row"> 269 <div class="col"> 270 <select class="input-group-text" name="type"> 271 <option value="Bank donation">Bank donation</option> 272 <option value="Phone donation">Phone donation</option> 273 </select> 274 </div> 275 <div class="col"> 276 <input type="number" class="input-group-text" name="amount"> 277 </div> 278 </div> 279 </form> 280 </div> 281 </div> 282 <div class="modal-footer"> 283 <input class="btn btn-primary" type="submit" th:form="'my-form' + ${post.id}"> 284 </div> 285 </div> 252 286 </div> 253 287 </div> … … 260 294 </div> 261 295 </div> 296 297 262 298 <script src="/js/bootstrap.min.js"></script> 263 299 <script th:inline="javascript">
Note:
See TracChangeset
for help on using the changeset viewer.