From cd9dfcec9e7ae9fe6f08b61927b16cf76b8bcef7 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 15:49:08 -0400 Subject: debug of checkout. -ak --- .../ufundapi/controller/CupboardController.java | 1 + .../api/ufundapi/persistence/CupboardFileDAO.java | 1 + .../funding-basket/funding-basket.component.html | 19 ++++++--------- .../funding-basket/funding-basket.component.ts | 28 +++++++++++++++++++++- 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 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 @@

There are no needs in the basket

- +
@@ -18,20 +18,14 @@ @@ -39,5 +33,6 @@
- - {{need.name}} - + {{need.name}}

Goal: {{need.maxGoal}}

Current: {{need.current}}

-

How much to Contribute:

-
- -
+

How much to Contribute:


- +

- +

Invalid input in funding basket!

+
\ 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); + } + } + } + } -- cgit v1.2.3