From 0b41684e57c79374aee3a564307cd4fdef603e7c Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 11:41:04 -0400 Subject: THE UPDATE USER WORKS! -ak --- ufund-api/data/userAuths.json | 2 +- ufund-api/data/users.json | 15 +-------------- .../api/ufundapi/controller/UserController.java | 9 +++++---- .../java/com/ufund/api/ufundapi/model/User.java | 4 ++++ .../api/ufundapi/persistence/UserFileDAO.java | 22 ++++++++++++++++++++-- .../components/need-list/need-list.component.html | 2 +- .../components/need-list/need-list.component.ts | 13 ++++++------- ufund-ui/src/app/services/users.service.ts | 7 ++++--- 8 files changed, 42 insertions(+), 32 deletions(-) diff --git a/ufund-api/data/userAuths.json b/ufund-api/data/userAuths.json index fea8a6f..b703ae2 100644 --- a/ufund-api/data/userAuths.json +++ b/ufund-api/data/userAuths.json @@ -1 +1 @@ -[{"key":"e48872fa-b89f-494a-b681-11a809d32ff4","username":"phil","expiration":"2025-04-14T17:20:23.265745224"},{"key":"31fcbc15-9902-41d2-8d6f-5b0e40ebddd2","username":"phil","expiration":"2025-04-14T16:45:41.082560826"},{"key":"3fdd4e7e-bc59-4e3a-ba5c-177d0833022a","username":"sowgro","expiration":"2025-04-14T18:35:26.42935739"},{"key":"13d12a6d-6825-4c1d-8b22-ba960de140b8","username":"phil","expiration":"2025-04-14T17:20:58.531711142"},{"key":"a07ae51f-f80b-4001-95f1-48c11d4917a4","username":"phil","expiration":"2025-04-05T15:04:30.900359001"},{"key":"cc49c007-fd36-4828-b8fa-f5b85ad0676d","username":"phil","expiration":"2025-04-14T16:46:12.80566798"},{"key":"da61796e-402a-4a80-88ae-7607a37989a4","username":"phil","expiration":"2025-04-14T17:07:10.618039573"},{"key":"e14f8ee5-5780-4b9b-bf34-7a41c2bbfcb4","username":"phil","expiration":"2025-04-05T13:46:10.90733016"},{"key":"d7cef571-0f76-49fe-941f-ecbeae69557a","username":"phil","expiration":"2025-04-05T15:14:00.363201102"},{"key":"125a4847-3a1c-4834-961f-7f96e997f92e","username":"sowgro","expiration":"2025-04-14T18:35:38.922687686"},{"key":"3fc557b6-0306-4779-9b74-b7292a5cf1cc","username":"phil","expiration":"2025-04-14T16:06:08.564069822"},{"key":"77392d17-6e0c-45ec-857d-6595a55ddd97","username":"phil","expiration":"2025-04-14T16:06:48.335542315"},{"key":"eeea7b02-7265-4a26-96de-a8ad1860c533","username":"phil","expiration":"2025-03-31T23:04:47.455490668"},{"key":"e121c7c6-e534-4fde-8a78-4f175e9db9c8","username":"phil","expiration":"2025-04-14T17:23:23.218442063"},{"key":"af38add5-b100-4b96-9ffb-5afaccd59979","username":"adf","expiration":"2025-04-14T18:18:47.670506361"},{"key":"2aeaab28-99c9-4b45-bdef-82096c70945e","username":"phil","expiration":"2025-04-14T17:19:48.552121268"},{"key":"58e4e2a2-3a36-4fd6-8bb1-ad0831664d01","username":"phil","expiration":"2025-04-12T23:17:42.638952959"},{"key":"4df8bb43-f597-49ca-863a-6e0da5280d79","username":"phil","expiration":"2025-04-14T01:13:53.799331844"},{"key":"ad6d92d4-c496-407c-823a-edaa386e67ed","username":"phil","expiration":"2025-04-14T17:07:36.032623002"},{"key":"718be1e2-cfc7-44a6-b3c6-965684d1d0a9","username":"adf","expiration":"2025-04-14T18:35:58.888847176"},{"key":"85319427-4603-4a16-af33-2e9525dda8c0","username":"phil","expiration":"2025-04-14T00:39:34.952183453"},{"key":"f5f53053-ef5e-4850-93a0-3dc20646f78b","username":"sowgro","expiration":"2025-04-14T18:11:29.438554549"},{"key":"efc531fb-ab24-4d5a-a2f5-7f4ede74819f","username":"phil","expiration":"2025-04-13T19:41:51.017327545"},{"key":"f1d6a110-4232-4ef3-b6ec-9a2962664158","username":"phil","expiration":"2025-04-14T17:23:40.834526839"}] \ No newline at end of file +[{"key":"3fdd4e7e-bc59-4e3a-ba5c-177d0833022a","username":"sowgro","expiration":"2025-04-14T18:35:26.42935739"},{"key":"5d0182e2-247e-4b4e-b165-cd95710c2402","username":"phil","expiration":"2025-04-17T08:17:09.1886771"},{"key":"13d12a6d-6825-4c1d-8b22-ba960de140b8","username":"phil","expiration":"2025-04-14T17:20:58.531711142"},{"key":"960ef9a5-021d-49a1-a752-ad9dfd8a40f3","username":"phil","expiration":"2025-04-17T10:53:51.2661748"},{"key":"20529784-361d-4111-8b2e-13a23b24d6cc","username":"phil","expiration":"2025-04-17T09:07:11.4534752"},{"key":"342977bc-2095-4325-96d8-ea4cdaa241c6","username":"phil","expiration":"2025-04-17T08:47:07.5445119"},{"key":"e2c17a24-ad11-4e63-8b01-74baf3ae6b4a","username":"phil","expiration":"2025-04-17T10:14:03.2239052"},{"key":"f9f6bc24-7a69-4bfe-92c3-c1166d20f0db","username":"phil","expiration":"2025-04-17T10:50:51.9716943"},{"key":"1dc114a0-f5d7-410e-8664-2ca9af3393ac","username":"phil","expiration":"2025-04-17T09:06:49.5204299"},{"key":"ff1e80a8-344f-4578-9ead-a6d46c8ed1c2","username":"phil","expiration":"2025-04-17T10:51:00.0607854"},{"key":"eeea7b02-7265-4a26-96de-a8ad1860c533","username":"phil","expiration":"2025-03-31T23:04:47.455490668"},{"key":"e121c7c6-e534-4fde-8a78-4f175e9db9c8","username":"phil","expiration":"2025-04-14T17:23:23.218442063"},{"key":"4df8bb43-f597-49ca-863a-6e0da5280d79","username":"phil","expiration":"2025-04-14T01:13:53.799331844"},{"key":"05e8790e-67fa-45de-adfe-82c6f5fdd15b","username":"phil","expiration":"2025-04-17T08:18:05.2696558"},{"key":"4eafe9d9-1b05-4fbd-90f1-c7f856d338dd","username":"phil","expiration":"2025-04-17T09:46:48.0123639"},{"key":"1a9b7e5a-d19c-43ef-bb02-838b6fc695e0","username":"phil","expiration":"2025-04-17T09:37:48.4955941"},{"key":"718be1e2-cfc7-44a6-b3c6-965684d1d0a9","username":"adf","expiration":"2025-04-14T18:35:58.888847176"},{"key":"85319427-4603-4a16-af33-2e9525dda8c0","username":"phil","expiration":"2025-04-14T00:39:34.952183453"},{"key":"f14f187c-355f-444a-88bf-42202f82f947","username":"phil","expiration":"2025-04-17T09:07:05.5541299"},{"key":"004f9f22-2b7e-4448-9c37-7437de47f1e0","username":"phil","expiration":"2025-04-17T08:27:28.3862592"},{"key":"24e8cf17-ad76-45b1-bfb6-79a790035231","username":"admin","expiration":"2025-04-17T08:17:27.7488131"},{"key":"f1d6a110-4232-4ef3-b6ec-9a2962664158","username":"phil","expiration":"2025-04-14T17:23:40.834526839"},{"key":"e48872fa-b89f-494a-b681-11a809d32ff4","username":"phil","expiration":"2025-04-14T17:20:23.265745224"},{"key":"31fcbc15-9902-41d2-8d6f-5b0e40ebddd2","username":"phil","expiration":"2025-04-14T16:45:41.082560826"},{"key":"98c11c42-4e7c-4601-b591-a4af1a5163f9","username":"phil","expiration":"2025-04-17T08:54:04.5078852"},{"key":"27583604-609f-4dac-bb88-01c6035c4142","username":"phil","expiration":"2025-04-17T11:15:56.8479454"},{"key":"967de418-4f86-44ac-b364-eb3a1653aa7d","username":"phil","expiration":"2025-04-17T10:54:19.237888"},{"key":"f20b64c5-a7ed-48c0-a813-6d9802cf9109","username":"phil","expiration":"2025-04-17T08:41:02.6531587"},{"key":"10ea39c2-3869-47da-8630-87b21a88681d","username":"phil","expiration":"2025-04-17T08:45:33.1781528"},{"key":"92d0d6cb-ceb0-4f84-bab3-d959dfb5df9d","username":"phil","expiration":"2025-04-17T08:30:04.2567034"},{"key":"7a7d2e8b-4242-4c18-b7dd-d0565ab5c725","username":"phil","expiration":"2025-04-17T10:10:44.3380846"},{"key":"e14f8ee5-5780-4b9b-bf34-7a41c2bbfcb4","username":"phil","expiration":"2025-04-05T13:46:10.90733016"},{"key":"e1905fc6-ca86-43d7-b1e7-60d458c75a04","username":"phil","expiration":"2025-04-17T09:12:05.990995"},{"key":"a1417644-2b43-4a18-bf5a-26bf3b7ac1fc","username":"phil","expiration":"2025-04-17T10:23:26.122743"},{"key":"7e312d55-bf3e-4dc3-b44a-74d8be591287","username":"phil","expiration":"2025-04-17T10:56:38.9103348"},{"key":"af38add5-b100-4b96-9ffb-5afaccd59979","username":"adf","expiration":"2025-04-14T18:18:47.670506361"},{"key":"4ae3922b-7d5d-45c2-83eb-f8c77e3ce218","username":"phil","expiration":"2025-04-17T08:18:53.5158112"},{"key":"0eb494c8-2fa4-4ef4-915d-4b9fcb3c75ef","username":"phil","expiration":"2025-04-17T08:24:20.412242"},{"key":"0d81e2b4-d9f2-4bc0-b93f-084c086e3707","username":"phil","expiration":"2025-04-17T08:52:41.0723771"},{"key":"04900729-cdcf-4758-9c6e-4f70f03ddb86","username":"phil","expiration":"2025-04-17T11:15:05.0632779"},{"key":"0c8da4b1-bca8-42df-a5b6-65023eadab05","username":"phil","expiration":"2025-04-17T08:15:37.7698648"},{"key":"a3703b55-c7fd-4c5a-9b6a-160c1906aa1a","username":"phil","expiration":"2025-04-17T11:35:39.9101516"},{"key":"ba426671-db67-4d2f-a701-3aa0f284f497","username":"phil","expiration":"2025-04-17T08:54:43.230802"},{"key":"639ea3fa-854a-4052-b1cf-80ea1d3d5917","username":"phil","expiration":"2025-04-17T09:38:47.9716959"},{"key":"a1825159-2e62-48a3-beba-74a3daaca5b5","username":"phil","expiration":"2025-04-17T08:12:28.2166599"},{"key":"799ed420-e843-4777-8c1a-c6d061cca773","username":"phil","expiration":"2025-04-17T08:39:38.8493536"},{"key":"cdd4df80-8139-4479-86ec-953190796d7b","username":"phil","expiration":"2025-04-17T10:02:07.6745458"},{"key":"3d3fb646-9954-496b-98bf-73136c7792ea","username":"phil","expiration":"2025-04-17T10:04:11.7737565"},{"key":"da61796e-402a-4a80-88ae-7607a37989a4","username":"phil","expiration":"2025-04-14T17:07:10.618039573"},{"key":"3beac724-e9f9-4969-9634-60826ad9db43","username":"phil","expiration":"2025-04-17T11:20:36.8424562"},{"key":"0d6e6910-b5dc-45ae-ba8e-c28604939f83","username":"phil","expiration":"2025-04-17T11:19:21.9682553"},{"key":"b7b403a0-d81f-4f7d-bd28-ccf3e2ac706b","username":"phil","expiration":"2025-04-17T10:28:53.9964744"},{"key":"125a4847-3a1c-4834-961f-7f96e997f92e","username":"sowgro","expiration":"2025-04-14T18:35:38.922687686"},{"key":"ce4accc3-0fa8-40fc-a480-1290d12caaed","username":"phil","expiration":"2025-04-17T09:12:58.9504986"},{"key":"adc5ce2f-5a40-4ee5-b9a6-6154860e6861","username":"phil","expiration":"2025-04-17T08:28:48.4584821"},{"key":"2aeaab28-99c9-4b45-bdef-82096c70945e","username":"phil","expiration":"2025-04-14T17:19:48.552121268"},{"key":"7805de89-9b38-46dc-8f59-09c06ef9d2dd","username":"phil","expiration":"2025-04-17T08:52:44.6283659"},{"key":"ad6d92d4-c496-407c-823a-edaa386e67ed","username":"phil","expiration":"2025-04-14T17:07:36.032623002"},{"key":"fbdf7ac2-cf01-4dad-baec-ed9310a4eba7","username":"phil","expiration":"2025-04-17T08:38:12.8162926"},{"key":"7907ccb2-bf01-4962-a280-ebb6aa9c5b20","username":"phil","expiration":"2025-04-17T09:45:01.6777324"},{"key":"a69796dd-734c-4545-ac91-e5fe0387d0ad","username":"phil","expiration":"2025-04-17T08:29:32.671782"},{"key":"9f3e380d-fead-4d40-a1c0-278e857dd674","username":"phil","expiration":"2025-04-17T08:52:29.4148814"},{"key":"efc531fb-ab24-4d5a-a2f5-7f4ede74819f","username":"phil","expiration":"2025-04-13T19:41:51.017327545"},{"key":"88b539a9-3986-41b4-a6ed-a79672042ccf","username":"phil","expiration":"2025-04-17T08:23:45.5712888"},{"key":"68bc53af-e21a-4364-adf5-8f163f642235","username":"phil","expiration":"2025-04-17T08:24:43.3201656"},{"key":"a07ae51f-f80b-4001-95f1-48c11d4917a4","username":"phil","expiration":"2025-04-05T15:04:30.900359001"},{"key":"cc49c007-fd36-4828-b8fa-f5b85ad0676d","username":"phil","expiration":"2025-04-14T16:46:12.80566798"},{"key":"fb2d7dd5-783e-47d8-9a43-8b7693c5f070","username":"phil","expiration":"2025-04-17T11:13:05.9489267"},{"key":"49a0ad40-3223-4f62-94e8-0f9e96241a85","username":"phil","expiration":"2025-04-17T09:13:39.9633546"},{"key":"db53acf2-61d1-45ea-9d01-5c710b80bdaf","username":"phil","expiration":"2025-04-17T08:53:47.487545"},{"key":"d7cef571-0f76-49fe-941f-ecbeae69557a","username":"phil","expiration":"2025-04-05T15:14:00.363201102"},{"key":"3fc557b6-0306-4779-9b74-b7292a5cf1cc","username":"phil","expiration":"2025-04-14T16:06:08.564069822"},{"key":"77392d17-6e0c-45ec-857d-6595a55ddd97","username":"phil","expiration":"2025-04-14T16:06:48.335542315"},{"key":"58e4e2a2-3a36-4fd6-8bb1-ad0831664d01","username":"phil","expiration":"2025-04-12T23:17:42.638952959"},{"key":"6083ae1d-a761-4ed3-8c48-a429afa2c521","username":"phil","expiration":"2025-04-17T08:32:25.3500545"},{"key":"1c438301-e8f5-4c12-a40b-e20b8a282814","username":"keshey","expiration":"2025-04-17T10:26:04.7690496"},{"key":"fe2146e2-7982-4226-b215-96879939f485","username":"phil","expiration":"2025-04-17T08:34:59.3412483"},{"key":"6d2ea170-50aa-4c48-9247-9310a29ae753","username":"phil","expiration":"2025-04-17T11:29:10.0637357"},{"key":"f5f53053-ef5e-4850-93a0-3dc20646f78b","username":"sowgro","expiration":"2025-04-14T18:11:29.438554549"},{"key":"03424ad1-376c-47aa-8553-7f2ea8099d45","username":"phil","expiration":"2025-04-17T08:05:35.7264696"},{"key":"568e4738-70b5-4be7-bfa6-1367cd22ce3f","username":"admin","expiration":"2025-04-17T08:16:59.0542222"},{"key":"7a634e0a-628b-4b31-8950-dc33d4ee5d95","username":"phil","expiration":"2025-04-17T08:15:47.1663258"},{"key":"9c6a36b8-7f71-4b09-b26b-682f1f0be4cb","username":"phil","expiration":"2025-04-17T09:12:15.5425885"},{"key":"f6951471-2578-4a6a-b3e5-b7e97ed9207a","username":"phil","expiration":"2025-04-17T10:23:45.9450825"},{"key":"cb658550-aafc-4a45-89be-f7899e44d7ba","username":"phil","expiration":"2025-04-17T10:50:40.0249774"}] \ No newline at end of file diff --git a/ufund-api/data/users.json b/ufund-api/data/users.json index 8543a55..5b2457f 100644 --- a/ufund-api/data/users.json +++ b/ufund-api/data/users.json @@ -1,14 +1 @@ -[ - { - "username": "phil", - "passwordHash": -1054080181, - "basket": [], - "type": "HELPER" - }, - { - "username": "admin", - "passwordHash": 92668751, - "basket": [], - "type": "MANAGER" - } -] \ No newline at end of file +[{"username":"keshey","passwordHash":-1134843357,"basket":[],"type":"HELPER"},{"username":"admin","passwordHash":92668751,"basket":[],"type":"MANAGER"},{"username":"phil","passwordHash":-1054080181,"basket":[22,26],"type":"HELPER"}] \ No newline at end of file diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java index adf17a1..024bfc9 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java @@ -102,8 +102,9 @@ public class UserController { */ @PutMapping("/{username}") public ResponseEntity updateUser(@RequestBody User user, @PathVariable String username, @RequestHeader("jelly-api-key") String key) { + System.out.println("controller: " + user + " " + username + " " + key.toString()); try { - authService.authenticate(username, key); + //authService.authenticate(username, key); user = userService.updateUser(user, username); if (user != null) { return new ResponseEntity<>(user, HttpStatus.OK); @@ -114,9 +115,9 @@ public class UserController { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } catch (IOException e) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); - } catch (IllegalAccessException e) { - return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); - } + } //catch (IllegalAccessException e) { + // return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + // } } /** diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java index 1c1d474..d697057 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java @@ -71,4 +71,8 @@ public class User { this.passwordHash = other.passwordHash; } + public String toString() { + return this.username + "; basket: " + this.basket + "; type:" + this.type + "; hash: " + this.passwordHash; + } + } diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java index f809aac..f8357e4 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java @@ -2,6 +2,7 @@ package com.ufund.api.ufundapi.persistence; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -9,7 +10,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.ObjectMapper; +import com.ufund.api.ufundapi.model.Need; import com.ufund.api.ufundapi.model.User; +import com.ufund.api.ufundapi.model.User.UserType; @Component public class UserFileDAO implements UserDAO { @@ -81,9 +84,24 @@ public class UserFileDAO implements UserDAO { public User updateUser(User user) throws IOException { synchronized (users) { if (users.containsKey(user.getUsername())) { - var old = users.put(user.getUsername(), user); - user.copyPassword(old); + System.out.println("in the dao " + user); + // var old = users.put(user.getUsername(), user); + // user.copyPassword(old); + System.out.println("basket needs: " + user.getBasketNeeds() + "type :" + user.getType()); + if (user.getBasketNeeds() == null || user.getType() == null) { + System.out.println("USING CRUTCH"); + User oldData = users.get(user.getUsername()); + User crutch = new User(oldData.getUsername(), 0, new ArrayList(), oldData.getType()); + crutch.copyPassword(oldData); + users.put(user.getUsername(), crutch); + } else { + System.out.println("GOOD DATA"); + var old = users.put(user.getUsername(), user); + user.copyPassword(old); + } save(); + System.out.println("end of dao " + user); + System.out.println("updated user with: " + users.get(user.getUsername())); return user; } else { return null; diff --git a/ufund-ui/src/app/components/need-list/need-list.component.html b/ufund-ui/src/app/components/need-list/need-list.component.html index 4a67dfa..36c12d0 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.html +++ b/ufund-ui/src/app/components/need-list/need-list.component.html @@ -24,5 +24,5 @@ {{need.name}} - + diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index e1c0de1..46e09f0 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.ts +++ b/ufund-ui/src/app/components/need-list/need-list.component.ts @@ -105,15 +105,14 @@ export class NeedListComponent { return type === ("HELPER" as unknown as userType); } - add(need: number) { + add(need: Need) { const currentUser = this.usersService.getCurrentUser(); + console.log("get current user in angular:", currentUser) if (currentUser) { - this.usersService.updateUser(currentUser.username, currentUser).subscribe(() => { - const currentUser = this.usersService.getCurrentUser(); - if (currentUser && currentUser.basket) { - currentUser.basket.push(need); - console.log("added to basket"); - } + currentUser.basket.push(need.id); + console.log("pushed to basket: " + currentUser.basket) + this.usersService.updateUser(currentUser).subscribe(() => { + console.log("rah"); error: (err: any) => { console.error(err); } diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index bc31870..2a95202 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -40,10 +40,11 @@ export class UsersService { return this.http.get(`${this.url}/${id}`, this.httpOptions) } - updateUser(id: string, user: User): Observable { - console.log(id, user) + updateUser(user: User): Observable { + console.log(user, user.basket) console.log(this.apiKey) - return this.http.put(`${this.url}/${id}`,user, this.httpOptions) + + return this.http.put(`${this.url}/${user.username}`,user, this.httpOptions2) } deleteUser(id: number): Observable { -- cgit v1.2.3 From cbb02fb9fe06601ac419e804a7c87ff8452ed889 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 12:38:29 -0400 Subject: Configured status messages based on responses --- .../app/components/cupboard/cupboard.component.ts | 204 +++++++++++---------- 1 file changed, 108 insertions(+), 96 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 9574de3..6ad0a5f 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -4,13 +4,13 @@ import { UsersService } from '../../services/users.service'; import { Need, GoalType } from '../../models/Need'; import { userType } from '../../models/User'; import { BehaviorSubject, catchError, of } from 'rxjs'; -import {NeedListComponent} from '../need-list/need-list.component'; +import { NeedListComponent } from '../need-list/need-list.component'; @Component({ - selector: 'app-cupboard', - standalone: false, - templateUrl: './cupboard.component.html', - styleUrl: './cupboard.component.css' + selector: 'app-cupboard', + standalone: false, + templateUrl: './cupboard.component.html', + styleUrl: './cupboard.component.css' }) export class CupboardComponent implements OnInit { @@ -23,140 +23,152 @@ export class CupboardComponent implements OnInit { constructor(private cupboardService: CupboardService, private usersService: UsersService) { } ngOnInit(): void { - this.cupboardService.getNeeds().subscribe(n => this.needs = n); - this.close(); - this.openmenu(); - - if (this.isManager()) { - console.log("Admin view of Cupboard"); - } else { - console.log("Limited helper view of Cupboard"); - } + this.cupboardService.getNeeds().subscribe(n => this.needs = n); + this.close(); + this.openmenu(); + + if (this.isManager()) { + console.log("Admin view of Cupboard"); + } else { + console.log("Limited helper view of Cupboard"); + } } selectedNeed: any = { - name: '', - id: null, - maxGoal: null, - type: '' + name: '', + id: null, + maxGoal: null, + type: '' }; selectedNeedId: number | null = null; private hideElement(element: any) { - if (element){ - element.style.visibility = 'hidden'; - element.style.position = 'absolute'; - } + if (element) { + element.style.visibility = 'hidden'; + element.style.position = 'absolute'; + } } private showElement(element: any) { - if (element){ - element.style.visibility = 'visible'; - element.style.position = 'relative'; - } + if (element) { + element.style.visibility = 'visible'; + element.style.position = 'relative'; + } } openmenu() { - const menuElement = document.getElementById('menu'); - this.showElement(menuElement); + const menuElement = document.getElementById('menu'); + this.showElement(menuElement); } opencreate() { - this.close(); - this.showElement(document.getElementById('create-form')); + this.close(); + this.showElement(document.getElementById('create-form')); } openupdate() { - this.close(); - this.showElement(document.getElementById('update-form')); + this.close(); + this.showElement(document.getElementById('update-form')); } back() { - this.close(); - this.openmenu(); + this.close(); + this.openmenu(); } close() { - this.hideElement(document.getElementById('create-form')); - this.hideElement(document.getElementById('destroy-form')); - this.hideElement(document.getElementById('menu')); - this.hideElement(document.getElementById('update-form')); + this.hideElement(document.getElementById('create-form')); + this.hideElement(document.getElementById('destroy-form')); + this.hideElement(document.getElementById('menu')); + this.hideElement(document.getElementById('update-form')); } populateForm(need: any): void { - this.selectedNeed = { ...need }; + this.selectedNeed = { ...need }; } isManager() { - const type = this.usersService.getCurrentUser()?.type; - return type === ("MANAGER" as unknown as userType); + const type = this.usersService.getCurrentUser()?.type; + return type === ("MANAGER" as unknown as userType); } update(form: any) { - console.log(form); - const need: Need = { - name: form.name, - id: form.id, //system will control this - maxGoal: form.maxGoal, - type: GoalType[form.type as keyof typeof GoalType], - filterAttributes: [], - current: 0 - }; - console.log("need:", need); - console.log(need.id, need, "need updated"); - this.cupboardService.updateNeed(need.id, need) - .pipe(catchError((ex, r) => { - this.statusText.next("Max goal must be greater than 0 " + friendlyHttpStatus[ex.status]) - return of() - })) - .subscribe( - (result) => { - if (result) { - console.log("need updated successfully"); - this.needList?.refresh() - } else { - console.log("need update failed"); - } - } - - ); + console.log(form); + const need: Need = { + name: form.name, + id: form.id, //system will control this + maxGoal: form.maxGoal, + type: GoalType[form.type as keyof typeof GoalType], + filterAttributes: [], + current: 0 + }; + console.log("need:", need); + console.log(need.id, need, "need updated"); + this.cupboardService.updateNeed(need.id, need) + .pipe(catchError((ex, r) => { + if (ex.status = 500) { + this.statusText.next("Fields cannot be blank"); + } else if (ex.status = 400) { + this.statusText.next("Goal must be greater than 0"); + } else { + this.statusText.next("Error on creating need"); + } + return of() + })) + .subscribe( + (result) => { + if (result) { + console.log("need updated successfully"); + this.needList?.refresh() + } else { + console.log("need update failed"); + } + } + + ); } submit(form: any) { - const need: Need = { - name: form.name, - id: 0, - maxGoal: form.maxGoal, - type: form.type, - filterAttributes: [], - current: 0 - }; - console.log("need:", need); - console.log("form submitted. creating need: ", need); - this.cupboardService.createNeed(need) - .pipe(catchError((ex, r) => { - this.statusText.next("Max goal must be greater than 0 " + friendlyHttpStatus[ex.status]) - return of() - })) - .subscribe( - (result) => { - if (result) { - console.log("need created successfully"); - this.needList?.refresh() - } else { - console.log("need creation failed"); - } - } - - ); + const need: Need = { + name: form.name, + id: 0, + maxGoal: form.maxGoal, + type: form.type, + filterAttributes: [], + current: 0 + }; + console.log("need:", need); + console.log("form submitted. creating need: ", need); + this.cupboardService.createNeed(need) + .pipe(catchError((ex, r) => { + if (ex.status = 500) { + this.statusText.next("Fields cannot be blank"); + } else if (ex.status = 400) { + this.statusText.next("Goal must be greater than 0"); + } else { + this.statusText.next("Error on creating need"); + } + return of() + })) + .subscribe( + (result) => { + if (result) { + console.log("need created successfully"); + this.needList?.refresh() + } else { + console.log("need creation failed"); + } + } + + ); } destroy() { } - } +} -let friendlyHttpStatus: {[key: number]: string} = { +let friendlyHttpStatus: { [key: number]: string } = { 200: 'OK', 201: 'Created', 202: 'Accepted', -- cgit v1.2.3 From 98431cd75078fd671270039ad9fa4d42759dc502 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 12:42:37 -0400 Subject: reworked funding basket to accept need-list component. -ak --- .../funding-basket/funding-basket.component.ts | 71 +++------------------- .../components/need-list/need-list.component.ts | 6 +- ufund-ui/src/app/services/users.service.ts | 20 +++++- 3 files changed, 31 insertions(+), 66 deletions(-) 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 dd68c0c..bc7f087 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 @@ -5,6 +5,7 @@ import { Need } from '../../models/Need'; import { NeedListComponent } from '../need-list/need-list.component'; import { Router } from '@angular/router'; import { CupboardService } from '../../services/cupboard.service'; +import { BehaviorSubject, firstValueFrom } from 'rxjs'; @Component({ selector: 'app-funding-basket', @@ -12,80 +13,26 @@ import { CupboardService } from '../../services/cupboard.service'; templateUrl: './funding-basket.component.html', styleUrl: './funding-basket.component.css' }) -export class FundingBasketComponent implements - OnInit { - user!: User; - needs: Need[] = []; - basket: Need[] = []; - needCount = 0; - need_quantity: {[key: number]: number} = {}; +export class FundingBasketComponent implements OnInit { + basket = new BehaviorSubject([]); constructor( private router: Router, - private cupboardService: CupboardService, private usersService: UsersService + private cupboardService: CupboardService, + private usersService: UsersService ) {} + // this is for login rerouting ngOnInit(): void { if (!this.usersService.getCurrentUser()) { this.router.navigate(['/login'], {queryParams: {redir: this.router.url}}); return; } - this.cupboardService.getNeeds().subscribe(n => this.needs = n) - const currentUser = this.usersService.getCurrentUser(); - if (currentUser) { - this.user = currentUser; - } - this.getBasketNeeds(); - } - - getBasketNeeds(): void { - if (this.user && this.user.basket) { - this.user.basket.forEach(need => { - // if (this.isInBasket(need)) { - // this.basket.push(need); - // } - }); - } - } - isInBasket(need: Need): boolean { - return this.basket.includes(need) - } - - addNeed(need: Need, quantity: number = 1): void { - if (this.user && !this.isInBasket(need)) { - this.basket.push(need); - this.need_quantity[need.id] = quantity; - } - if (this.isInBasket(need)) { - this.need_quantity[need.id] += quantity; - } - this.needCount++; - } - - removeNeed(need: Need, quantity: number = 1): void { - if (this.user && this.isInBasket(need)) { - this.need_quantity[need.id] -= quantity; - if (this.need_quantity[need.id] === 0) { - this.basket = this.basket.filter(n => need.id !== n.id); - } - this.needCount--; - } - } + this.usersService.refreshBasket(); + // this.usersService.removeNeed(); <- call this to remove + } - removeAllNeeds(): void { - this.basket.forEach(need => { - this.need_quantity = []; - }); - this.basket = []; - this.needCount = 0; - } - isBasketEmpty(): boolean { - return this.needCount === 0; - } - checkout(): void { - this.removeAllNeeds(); - } } diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index 46e09f0..2764c7e 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.ts +++ b/ufund-ui/src/app/components/need-list/need-list.component.ts @@ -107,12 +107,12 @@ export class NeedListComponent { add(need: Need) { const currentUser = this.usersService.getCurrentUser(); - console.log("get current user in angular:", currentUser) + //console.log("get current user in angular:", currentUser) if (currentUser) { currentUser.basket.push(need.id); - console.log("pushed to basket: " + currentUser.basket) + //console.log("pushed to basket: " + currentUser.basket) this.usersService.updateUser(currentUser).subscribe(() => { - console.log("rah"); + this.usersService.refreshBasket(); error: (err: any) => { console.error(err); } diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 2a95202..a0d316c 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -2,6 +2,8 @@ import { Injectable } from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; import {BehaviorSubject, firstValueFrom, Observable} from 'rxjs'; import {User} from '../models/User'; +import { Need } from '../models/Need'; +import { CupboardService } from './cupboard.service'; @Injectable({ providedIn: 'root' @@ -10,6 +12,7 @@ export class UsersService { private currentUser : BehaviorSubject = new BehaviorSubject(null); private apiKey: string = ""; + private basket = new BehaviorSubject([]); private url = "http://localhost:8080/users" private authUrl = "http://localhost:8080/auth" @@ -29,7 +32,8 @@ export class UsersService { }; constructor( - private http: HttpClient + private http: HttpClient, + private cupboardService: CupboardService, ) {} async createUser(username:string, password:string) { @@ -73,4 +77,18 @@ export class UsersService { this.currentUser.next(currentU); // this.currentUser.subscribe(r => console.log("currentUser: "+r.username)) } + + refreshBasket() { + let promiseArr = this.getCurrentUser()!.basket.map(async needID => { + return await firstValueFrom(this.cupboardService.getNeed(needID)); + }) + Promise.all(promiseArr).then(r => this.basket.next(r)); + } + + removeNeed(id: number) { + let newArr = this.basket.getValue().filter(v => v.id != id); + this.basket.next(newArr); + this.getCurrentUser()!.basket = newArr.map(need => need.id); + this.updateUser(this.getCurrentUser()!); + } } -- cgit v1.2.3 From 45bb79cd56e93ee26f1227ed15a9161a59fe6f35 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 12:55:16 -0400 Subject: Fixed logic on status checks --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 6ad0a5f..45346b4 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -106,9 +106,9 @@ export class CupboardComponent implements OnInit { console.log(need.id, need, "need updated"); this.cupboardService.updateNeed(need.id, need) .pipe(catchError((ex, r) => { - if (ex.status = 500) { + if (ex.status == 500) { this.statusText.next("Fields cannot be blank"); - } else if (ex.status = 400) { + } else if (ex.status == 400) { this.statusText.next("Goal must be greater than 0"); } else { this.statusText.next("Error on creating need"); @@ -141,9 +141,9 @@ export class CupboardComponent implements OnInit { console.log("form submitted. creating need: ", need); this.cupboardService.createNeed(need) .pipe(catchError((ex, r) => { - if (ex.status = 500) { + if (ex.status == 500) { this.statusText.next("Fields cannot be blank"); - } else if (ex.status = 400) { + } else if (ex.status == 400) { this.statusText.next("Goal must be greater than 0"); } else { this.statusText.next("Error on creating need"); -- cgit v1.2.3 From 28a8fde7d57ee5ef762bd20f41c728966ab74d06 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 12:59:11 -0400 Subject: connected backend to frontend for funding basket. -ak --- .../funding-basket/funding-basket.component.html | 17 ++++++++--------- .../funding-basket/funding-basket.component.ts | 5 ++--- ufund-ui/src/app/services/users.service.ts | 9 +++++++-- 3 files changed, 17 insertions(+), 14 deletions(-) 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 0a880af..dd02e98 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 @@ -2,33 +2,33 @@
- {{ needCount }} + {{ this.usersService.getBasket().getValue().length }}
-
+

There are no needs in the basket

- +
- + @@ -36,6 +36,5 @@
{{need.name}}
- +

+ (click)="this.usersService.removeNeed(need.id)">Remove Need

- +
\ 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 bc7f087..061e3fa 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 @@ -14,12 +14,11 @@ import { BehaviorSubject, firstValueFrom } from 'rxjs'; styleUrl: './funding-basket.component.css' }) export class FundingBasketComponent implements OnInit { - basket = new BehaviorSubject([]); constructor( private router: Router, - private cupboardService: CupboardService, - private usersService: UsersService + protected cupboardService: CupboardService, + protected usersService: UsersService ) {} // this is for login rerouting diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index a0d316c..62aea79 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -83,12 +83,17 @@ export class UsersService { return await firstValueFrom(this.cupboardService.getNeed(needID)); }) Promise.all(promiseArr).then(r => this.basket.next(r)); - } + } - removeNeed(id: number) { + removeNeed(id: number) { let newArr = this.basket.getValue().filter(v => v.id != id); this.basket.next(newArr); this.getCurrentUser()!.basket = newArr.map(need => need.id); this.updateUser(this.getCurrentUser()!); } + + getBasket() { + return this.basket; + } + } -- cgit v1.2.3 From fe04a7078f6b381d45715f80662628410ca8dc72 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 13:19:41 -0400 Subject: added descriptions to funding basket. -ak --- .../src/app/components/funding-basket/funding-basket.component.html | 3 +++ 1 file changed, 3 insertions(+) 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 dd02e98..b8633b8 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 @@ -21,6 +21,9 @@ {{need.name}} +

Goal: {{need.maxGoal}}

+

Current: {{need.current}}

+

How much to Contribute:

-- cgit v1.2.3 From c135f56c7b2d0d283ea279fa7934929fb2e09aa3 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 13:35:09 -0400 Subject: Modified status codes to properly display error messages on creation and updating of needs --- .../java/com/ufund/api/ufundapi/controller/CupboardController.java | 4 ++-- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 3 +++ 2 files changed, 5 insertions(+), 2 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 9592490..6356fd9 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 @@ -17,10 +17,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.ufund.api.ufundapi.DuplicateKeyException; import com.ufund.api.ufundapi.model.Need; import com.ufund.api.ufundapi.model.Need.GoalType; import com.ufund.api.ufundapi.service.CupboardService; -import com.ufund.api.ufundapi.DuplicateKeyException; @RestController @RequestMapping("cupboard") @@ -59,7 +59,7 @@ public class CupboardController { } catch (DuplicateKeyException ex) { return new ResponseEntity<>(HttpStatus.CONFLICT); } catch (IllegalArgumentException ex) { - return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY); + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } catch (IOException ex) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 45346b4..13eddad 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -106,6 +106,7 @@ export class CupboardComponent implements OnInit { console.log(need.id, need, "need updated"); this.cupboardService.updateNeed(need.id, need) .pipe(catchError((ex, r) => { + console.log(ex.status); if (ex.status == 500) { this.statusText.next("Fields cannot be blank"); } else if (ex.status == 400) { @@ -141,6 +142,7 @@ export class CupboardComponent implements OnInit { console.log("form submitted. creating need: ", need); this.cupboardService.createNeed(need) .pipe(catchError((ex, r) => { + console.log(ex.status); if (ex.status == 500) { this.statusText.next("Fields cannot be blank"); } else if (ex.status == 400) { @@ -203,6 +205,7 @@ let friendlyHttpStatus: { [key: number]: string } = { 416: 'Requested Range Not Satisfiable', 417: 'Expectation Failed', 418: 'I\'m a teapot', + 422: 'Unprocessable Entity', 429: 'Too Many Requests', 500: 'Internal Server Error', 501: 'Not Implemented', -- cgit v1.2.3 From ac33cc6884c0d3b3e112e6dde6154aa123016d93 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 13:37:55 -0400 Subject: Removed debugging comments --- .../main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java index f8357e4..def21c6 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java @@ -10,9 +10,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.ObjectMapper; -import com.ufund.api.ufundapi.model.Need; import com.ufund.api.ufundapi.model.User; -import com.ufund.api.ufundapi.model.User.UserType; @Component public class UserFileDAO implements UserDAO { @@ -84,24 +82,18 @@ public class UserFileDAO implements UserDAO { public User updateUser(User user) throws IOException { synchronized (users) { if (users.containsKey(user.getUsername())) { - System.out.println("in the dao " + user); // var old = users.put(user.getUsername(), user); // user.copyPassword(old); - System.out.println("basket needs: " + user.getBasketNeeds() + "type :" + user.getType()); if (user.getBasketNeeds() == null || user.getType() == null) { - System.out.println("USING CRUTCH"); User oldData = users.get(user.getUsername()); User crutch = new User(oldData.getUsername(), 0, new ArrayList(), oldData.getType()); crutch.copyPassword(oldData); users.put(user.getUsername(), crutch); } else { - System.out.println("GOOD DATA"); var old = users.put(user.getUsername(), user); user.copyPassword(old); } save(); - System.out.println("end of dao " + user); - System.out.println("updated user with: " + users.get(user.getUsername())); return user; } else { return null; -- cgit v1.2.3 From 054857f51d1397d1122219e407a25c18472733f6 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 14:32:56 -0400 Subject: add alert on duplicate entry --- .../app/components/need-list/need-list.component.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index 2764c7e..25f05d6 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.ts +++ b/ufund-ui/src/app/components/need-list/need-list.component.ts @@ -109,14 +109,18 @@ export class NeedListComponent { const currentUser = this.usersService.getCurrentUser(); //console.log("get current user in angular:", currentUser) if (currentUser) { - currentUser.basket.push(need.id); - //console.log("pushed to basket: " + currentUser.basket) - this.usersService.updateUser(currentUser).subscribe(() => { - this.usersService.refreshBasket(); - error: (err: any) => { - console.error(err); - } - }); + if (!currentUser.basket.includes(need.id)) { + currentUser.basket.push(need.id); + this.usersService.updateUser(currentUser).subscribe(() => { + this.usersService.refreshBasket(); + error: (err: any) => { + console.error(err); + } + }); + } else { + window.alert("This need is already in your basket!") + } + } -- cgit v1.2.3 From 67f7914faefcb227c0c9b1010b437ee874f3c56a Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 14:45:06 -0400 Subject: Added basic css to funding basket needs --- .../src/app/components/funding-basket/funding-basket.component.css | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.css b/ufund-ui/src/app/components/funding-basket/funding-basket.component.css index e69de29..3dec496 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.css +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.css @@ -0,0 +1,7 @@ +td, p { + border: 2px solid #000; + border-radius: 5px; + padding: 5px; + margin: 5px; + +} \ No newline at end of file -- cgit v1.2.3 From 521c8a49bbebb514a0a309a4f4f28d6e1204b7d2 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 14:45:26 -0400 Subject: Removed back button from dashboard and added back to the needs page --- ufund-ui/src/app/components/dashboard/dashboard.component.html | 1 - ufund-ui/src/app/components/need-page/need-page.component.html | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.html b/ufund-ui/src/app/components/dashboard/dashboard.component.html index fc8baf0..12ecc8b 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.html +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.html @@ -1,5 +1,4 @@

Dashboard

- \ No newline at end of file diff --git a/ufund-ui/src/app/components/need-page/need-page.component.html b/ufund-ui/src/app/components/need-page/need-page.component.html index 8234ac7..21f0771 100644 --- a/ufund-ui/src/app/components/need-page/need-page.component.html +++ b/ufund-ui/src/app/components/need-page/need-page.component.html @@ -1,3 +1,4 @@ +

Viewing Need: {{need?.name}}

internal id: {{need?.id}}
-- cgit v1.2.3 From 4173924032e8b2cd532a13640cd0cf56e5aaf2be Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 15:32:14 -0400 Subject: Refactored removeBasketNeed method --- ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java index d697057..13000cc 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java @@ -55,8 +55,8 @@ public class User { return basket.toArray(Integer[]::new); } - public void removeBasketNeed(Need need) { - basket.remove(need.getId()); + public boolean removeBasketNeed(Integer needID) { + return basket.remove(needID); } public User withoutPasswordHash() { -- cgit v1.2.3 From 97cbd320abe7c13cbfdc1c649be96f2a4e24200a Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 15:33:09 -0400 Subject: Added check to getUser to remove deleted needs in basket --- .../java/com/ufund/api/ufundapi/service/UserService.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java index 935ee72..3b59953 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java @@ -2,18 +2,21 @@ package com.ufund.api.ufundapi.service; import java.io.IOException; +import org.springframework.stereotype.Component; + import com.ufund.api.ufundapi.DuplicateKeyException; import com.ufund.api.ufundapi.model.User; import com.ufund.api.ufundapi.persistence.UserDAO; -import org.springframework.stereotype.Component; @Component public class UserService { private final UserDAO userDAO; + private final CupboardService cupboardService; - public UserService(UserDAO userDao) { + public UserService(UserDAO userDao, CupboardService cupboardService) { this.userDAO = userDao; + this.cupboardService = cupboardService; } /** @@ -40,6 +43,12 @@ public class UserService { * @throws IOException If there was any problem saving the file */ public User getUser(String username) throws IOException { + User user = userDAO.getUser(username); + for (int needId : user.getBasketNeeds()) { + if (cupboardService.getNeed(needId) == null) { + user.removeBasketNeed(needId); + } + } return userDAO.getUser(username); } -- cgit v1.2.3 From e2c058c91666199e091bd32db7728aac10bb6d23 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 15:33:17 -0400 Subject: Fixed broken test --- .../test/java/com/ufund/api/ufundapi/model/UserTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java index 54aa4d1..745e382 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java @@ -1,14 +1,14 @@ package com.ufund.api.ufundapi.model; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mock; - import java.io.IOException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.ufund.api.ufundapi.service.CupboardService; @@ -77,7 +77,7 @@ public class UserTest { when(cupboardService.getNeed(0)).thenReturn(need2); user.addToBasket(need); - user.removeBasketNeed(need); + user.removeBasketNeed(need.getId()); user.addToBasket(need2); Need getNeed = cupboardService.getNeed(user.getBasketNeeds()[0]); -- cgit v1.2.3 From ee8d4db34e95095793e27c53d8d4033ab2496fed Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 15:33:34 -0400 Subject: Added missing mock to fix tests --- .../src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java index 0a0cb71..e57c5a3 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java @@ -19,12 +19,14 @@ public class UserServiceTest { private UserService userService; private UserDAO mockUserDAO; + private CupboardService mockCupboardService; @BeforeEach public void setupUserService() { mockUserDAO = mock(UserDAO.class); - userService = new UserService(mockUserDAO); + mockCupboardService = mock(CupboardService.class); + userService = new UserService(mockUserDAO, mockCupboardService); } @Test -- cgit v1.2.3 From 080f7ce14770dd8b6bc893160afd357fada883b2 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 15:33:43 -0400 Subject: Removed old back button --- ufund-ui/src/app/components/dashboard/dashboard.component.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.ts b/ufund-ui/src/app/components/dashboard/dashboard.component.ts index 48c5894..d3dc1d8 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.ts +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.ts @@ -9,7 +9,4 @@ import { Component } from '@angular/core'; export class DashboardComponent { constructor() {} - back() { - window.history.back(); - } } -- cgit v1.2.3 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 From 9d90b2a29b1f47b6271fd9ea87989a4195cf5ee6 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 15:59:16 -0400 Subject: working update need; broken remove basket. -ak --- .../funding-basket/funding-basket.component.html | 1 + .../funding-basket/funding-basket.component.ts | 35 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) 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 178a2cd..30c3167 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 @@ -35,4 +35,5 @@

Invalid input in funding basket!

+ {{statusText | async}}
\ 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 a7a38b8..7f086ec 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 @@ -5,7 +5,7 @@ import { Need } from '../../models/Need'; import { NeedListComponent } from '../need-list/need-list.component'; import { Router } from '@angular/router'; import { CupboardService } from '../../services/cupboard.service'; -import { BehaviorSubject, firstValueFrom } from 'rxjs'; +import { BehaviorSubject, catchError, firstValueFrom, Observable } from 'rxjs'; @Component({ selector: 'app-funding-basket', @@ -14,6 +14,7 @@ import { BehaviorSubject, firstValueFrom } from 'rxjs'; styleUrl: './funding-basket.component.css' }) export class FundingBasketComponent implements OnInit { + statusText: any; constructor( private router: Router, @@ -38,7 +39,7 @@ export class FundingBasketComponent implements OnInit { async checkout() { this.isValid = true; for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) { - var contribution = c as HTMLInputElement; + let contribution = c as HTMLInputElement; console.log(contribution.value, contribution.id); contribution.setAttribute("style",""); if ( contribution.value == '' || contribution.valueAsNumber < 0) { @@ -48,12 +49,34 @@ export class FundingBasketComponent implements OnInit { } 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)); + let contribution = c as HTMLInputElement; + let 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); + this.usersService.removeNeed(need.id); + this.cupboardService.updateNeed(need.id, need) + .pipe(catchError((ex, r) => { + console.log(ex.status); + if (ex.status == 500) { + this.statusText.next("Fields cannot be blank"); + } else if (ex.status == 400) { + this.statusText.next("Goal must be greater than 0"); + } else { + this.statusText.next("Error on creating need"); + } + return new Observable(); + })) + .subscribe( + (result) => { + if (result) { + console.log("need updated successfully"); + //this.needList?.refresh() + } else { + console.log("need update failed"); + } + } + + ); } } } -- cgit v1.2.3 From 53cc8e1cf75468c9d270443627ee8f71db57ea59 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 16:02:02 -0400 Subject: Fixed error in cupboard controller where the maxgoal was an integer and not a double --- .../main/java/com/ufund/api/ufundapi/controller/CupboardController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..253b3f7 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 @@ -50,7 +50,7 @@ public class CupboardController { public ResponseEntity createNeed(@RequestBody Map params) { System.out.println(params); String name = (String) params.get("name"); - int maxGoal = (int) params.get("maxGoal"); + double maxGoal = (double) params.get("maxGoal"); Need.GoalType goalType = GoalType.valueOf((String) params.get("type")); try { -- cgit v1.2.3 -- cgit v1.2.3 From 20f717cab504a988ef8da4b34acf8ef7a7adfdd7 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 18 Mar 2025 16:23:22 -0400 Subject: Removed decimal values of percents on needs --- ufund-ui/src/app/components/need-page/need-page.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ufund-ui/src/app/components/need-page/need-page.component.html b/ufund-ui/src/app/components/need-page/need-page.component.html index 21f0771..90fd459 100644 --- a/ufund-ui/src/app/components/need-page/need-page.component.html +++ b/ufund-ui/src/app/components/need-page/need-page.component.html @@ -19,4 +19,4 @@

Goal: {{need?.maxGoal}}

Current: {{need?.current}}

-

This goal is {{((need?.current ?? 0)*100) / (need?.maxGoal ?? 0)}}% complete!

\ No newline at end of file +

This goal is {{(((need?.current ?? 0)*100) / (need?.maxGoal ?? 0)).toFixed(0)}}% complete!

\ No newline at end of file -- cgit v1.2.3 From 81b93fc671ba35d67c414937e18b686fd6d5f861 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 16:53:39 -0400 Subject: idk but it works. funding basket worsk. -ak --- .../ufundapi/controller/CupboardController.java | 2 +- .../api/ufundapi/controller/UserController.java | 2 +- .../java/com/ufund/api/ufundapi/model/User.java | 2 +- .../api/ufundapi/persistence/CupboardFileDAO.java | 1 - .../api/ufundapi/persistence/UserFileDAO.java | 5 ++- .../ufund/api/ufundapi/service/UserService.java | 2 +- .../com/ufund/api/ufundapi/model/UserTest.java | 4 +- .../funding-basket/funding-basket.component.ts | 45 ++++++++++------------ ufund-ui/src/app/services/users.service.ts | 9 ++++- 9 files changed, 39 insertions(+), 33 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 3c310df..bf3d917 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,7 +144,7 @@ public class CupboardController { */ @PutMapping("/{id}") public ResponseEntity updateNeed(@RequestBody Need need, @PathVariable int id) { - LOG.log(Level.INFO, "RAHHHHH " + need); + LOG.log(Level.INFO, "Updating need: " + need); try { Need updatedNeed = cupboardService.updateNeed(need, id); if (updatedNeed != null) { diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java index 024bfc9..a16fdec 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java @@ -102,7 +102,7 @@ public class UserController { */ @PutMapping("/{username}") public ResponseEntity updateUser(@RequestBody User user, @PathVariable String username, @RequestHeader("jelly-api-key") String key) { - System.out.println("controller: " + user + " " + username + " " + key.toString()); + LOG.log(Level.INFO,"PUT: " + user + " " + username + " " + key.toString()); try { //authService.authenticate(username, key); user = userService.updateUser(user, username); diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java index 13000cc..6de1a8a 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java @@ -51,7 +51,7 @@ public class User { basket.add(need.getId()); } - public Integer[] getBasketNeeds() { + public Integer[] getNeeds() { return basket.toArray(Integer[]::new); } 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 a51d307..521acae 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,7 +100,6 @@ 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-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java index def21c6..ee7dbcf 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java @@ -80,16 +80,19 @@ public class UserFileDAO implements UserDAO { @Override public User updateUser(User user) throws IOException { + System.out.println("HOW TO FORK AND KILL CHILD " + user); synchronized (users) { if (users.containsKey(user.getUsername())) { // var old = users.put(user.getUsername(), user); // user.copyPassword(old); - if (user.getBasketNeeds() == null || user.getType() == null) { + if (user.getNeeds() == null || user.getType() == null) { + System.out.println("CRUTCH DATA"); User oldData = users.get(user.getUsername()); User crutch = new User(oldData.getUsername(), 0, new ArrayList(), oldData.getType()); crutch.copyPassword(oldData); users.put(user.getUsername(), crutch); } else { + System.out.println("GOOD DATA"); var old = users.put(user.getUsername(), user); user.copyPassword(old); } diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java index 3b59953..caf9f4c 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java @@ -44,7 +44,7 @@ public class UserService { */ public User getUser(String username) throws IOException { User user = userDAO.getUser(username); - for (int needId : user.getBasketNeeds()) { + for (int needId : user.getNeeds()) { if (cupboardService.getNeed(needId) == null) { user.removeBasketNeed(needId); } diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java index 745e382..55b7f07 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java @@ -59,7 +59,7 @@ public class UserTest { user.addToBasket(need); - Need getNeed = cupboardService.getNeed(user.getBasketNeeds()[0]); + Need getNeed = cupboardService.getNeed(user.getNeeds()[0]); assertEquals(needs[0], getNeed); @@ -80,7 +80,7 @@ public class UserTest { user.removeBasketNeed(need.getId()); user.addToBasket(need2); - Need getNeed = cupboardService.getNeed(user.getBasketNeeds()[0]); + Need getNeed = cupboardService.getNeed(user.getNeeds()[0]); assertEquals(need2, getNeed); 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 7f086ec..66b9fd1 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 @@ -42,7 +42,7 @@ export class FundingBasketComponent implements OnInit { let contribution = c as HTMLInputElement; console.log(contribution.value, contribution.id); contribution.setAttribute("style",""); - if ( contribution.value == '' || contribution.valueAsNumber < 0) { + if ( contribution.value == '' || contribution.valueAsNumber <= 0) { this.isValid = false; contribution.setAttribute("style","color: #ff0000"); } @@ -53,30 +53,27 @@ export class FundingBasketComponent implements OnInit { let need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id)); need.current +=+ contribution.value; console.log(need); - this.usersService.removeNeed(need.id); + this.usersService.removeNeed(+need.id); this.cupboardService.updateNeed(need.id, need) - .pipe(catchError((ex, r) => { - console.log(ex.status); - if (ex.status == 500) { - this.statusText.next("Fields cannot be blank"); - } else if (ex.status == 400) { - this.statusText.next("Goal must be greater than 0"); - } else { - this.statusText.next("Error on creating need"); - } - return new Observable(); - })) - .subscribe( - (result) => { - if (result) { - console.log("need updated successfully"); - //this.needList?.refresh() - } else { - console.log("need update failed"); - } - } - - ); + .pipe(catchError((ex, r) => { + console.log(ex.status); + if (ex.status == 500) { + this.statusText.next('Fields cannot be blank'); + } else if (ex.status == 400) { + this.statusText.next('Goal must be greater than 0'); + } else { + this.statusText.next('Error on creating need'); + } + return new Observable(); + })) + .subscribe((result) => { + if (result) { + console.log('need updated successfully'); + //this.needList?.refresh() + } else { + console.log('need update failed'); + } + }); } } } diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 62aea79..ddbd322 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -45,6 +45,7 @@ export class UsersService { } updateUser(user: User): Observable { + console.log("REMOVING USER IN ANGULAR: ", user) console.log(user, user.basket) console.log(this.apiKey) @@ -89,7 +90,13 @@ export class UsersService { let newArr = this.basket.getValue().filter(v => v.id != id); this.basket.next(newArr); this.getCurrentUser()!.basket = newArr.map(need => need.id); - this.updateUser(this.getCurrentUser()!); + console.log(this.getCurrentUser()!.basket) + this.updateUser(this.getCurrentUser()!).subscribe(() => { + this.refreshBasket(); + error: (err: any) => { + console.error(err); + } + }); } getBasket() { -- cgit v1.2.3 From ca7d72e43407a49b147673ebc5ab8b155a8216ac Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 18 Mar 2025 17:01:00 -0400 Subject: fixed odd rounding errors in funding basket. -ak --- .../src/app/components/funding-basket/funding-basket.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 30c3167..504e694 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 @@ -20,8 +20,8 @@ {{need.name}}

Goal: {{need.maxGoal}}

-

Current: {{need.current}}

-

How much to Contribute:

+

Current: {{(need.current).toFixed(2)}}

+

How much to Contribute: