aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java1
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java1
-rw-r--r--ufund-ui/src/app/components/funding-basket/funding-basket.component.html19
-rw-r--r--ufund-ui/src/app/components/funding-basket/funding-basket.component.ts28
4 files changed, 36 insertions, 13 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
index 6356fd9..3c310df 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
@@ -144,6 +144,7 @@ public class CupboardController {
*/
@PutMapping("/{id}")
public ResponseEntity<Need> updateNeed(@RequestBody Need need, @PathVariable int id) {
+ LOG.log(Level.INFO, "RAHHHHH " + need);
try {
Need updatedNeed = cupboardService.updateNeed(need, id);
if (updatedNeed != null) {
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java
index 521acae..a51d307 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java
@@ -100,6 +100,7 @@ public class CupboardFileDAO implements CupboardDAO {
@Override
public Need updateNeed(Need need) throws IOException {
+ System.out.println("UPDATING NEED FOR " + need);
synchronized (needs) {
if (needs.containsKey(need.getId())) {
needs.put(need.getId(), need);
diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html
index b8633b8..178a2cd 100644
--- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html
+++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html
@@ -9,7 +9,7 @@
<h2>There are no needs in the basket</h2>
</div>
-<table class="needs" *ngIf="this.usersService.getBasket().getValue().length != 0">
+<table class="needs" id="funding-basket" *ngIf="this.usersService.getBasket().getValue().length != 0">
<thead>
<tr>
<th class="need"></th>
@@ -18,20 +18,14 @@
<tbody>
<tr *ngFor="let need of usersService.getBasket().getValue()">
<td>
- <a routerLink="/need/{{need.id}}">
- {{need.name}}
- </a>
+ <a routerLink="/need/{{need.id}}">{{need.name}}</a>
<p>Goal: {{need.maxGoal}}</p>
<p>Current: {{need.current}}</p>
- <p>How much to Contribute: <input type="number" #contribution></p>
- <div>
- <!-- <button type="button" class="addNeed" title="add need"
- (click)="addNeed(need)">Add Need</button> -->
- </div>
+ <p>How much to Contribute: <input type="number" placeholder="insert value" min="0" id={{need.id}} class="contribution"></p>
<br>
<div>
- <button type="button" class="removeNeed" title="delete need"
- (click)="this.usersService.removeNeed(need.id)">Remove Need</button>
+ <button type="button" class="removeNeed" title="delete need"
+ (click)="this.usersService.removeNeed(need.id)">Remove Need</button>
</div>
</td>
</tr>
@@ -39,5 +33,6 @@
</table>
<br>
<div>
- <button type="submit" class="checkout" title="checkout">Checkout</button>
+ <p *ngIf="!isValid">Invalid input in funding basket!</p>
+ <button type="submit" class="checkout" title="checkout" (click)="checkout()">Checkout</button>
</div> \ No newline at end of file
diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
index 061e3fa..a7a38b8 100644
--- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
+++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
@@ -1,4 +1,4 @@
-import {Component, OnInit} from '@angular/core';
+import {Component, Input, OnInit, ViewChild} from '@angular/core';
import {User} from '../../models/User';
import { UsersService } from '../../services/users.service';
import { Need } from '../../models/Need';
@@ -21,6 +21,9 @@ export class FundingBasketComponent implements OnInit {
protected usersService: UsersService
) {}
+ @ViewChild("contribution") contribution?: Input;
+ @Input() isValid: boolean = true;
+
// this is for login rerouting
ngOnInit(): void {
if (!this.usersService.getCurrentUser()) {
@@ -32,6 +35,29 @@ export class FundingBasketComponent implements OnInit {
// this.usersService.removeNeed(); <- call this to remove
}
+ async checkout() {
+ this.isValid = true;
+ for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) {
+ var contribution = c as HTMLInputElement;
+ console.log(contribution.value, contribution.id);
+ contribution.setAttribute("style","");
+ if ( contribution.value == '' || contribution.valueAsNumber < 0) {
+ this.isValid = false;
+ contribution.setAttribute("style","color: #ff0000");
+ }
+ }
+ if (this.isValid) {
+ for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) {
+ var contribution = c as HTMLInputElement;
+ var need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id));
+ need.current +=+ contribution.value;
+ console.log(need);
+ this.cupboardService.updateNeed(+contribution.id, need);
+ this.usersService.removeNeed(+contribution.id);
+ }
+ }
+ }
+
}