aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbenal01 <bja4245@rit.edu>2025-04-01 09:34:36 -0400
committerbenal01 <bja4245@rit.edu>2025-04-01 09:34:36 -0400
commit7ed26c5ee7171a502f6f8527fc55de2bb77eab3b (patch)
tree2046e58c146097aac21c9e352771420c31df6589
parentef46ddd082bb91d0262363536d46fe3eb4da47be (diff)
parentd8330f1ac85b26d08ca4df5ce3875078d7b4f47f (diff)
downloadJellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.tar.gz
JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.tar.bz2
JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.zip
Merge branch 'main' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b-jellysolutions
-rw-r--r--README.md13
-rw-r--r--etc/Acceptance Test Plan.xlsxbin30698 -> 71297 bytes
-rw-r--r--start.bat9
-rw-r--r--ufund-api/.gitignore6
-rw-r--r--ufund-api/data/cupboard.json2
-rw-r--r--ufund-api/data/userAuths.json2
-rw-r--r--ufund-api/data/users.json2
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java18
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java143
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java68
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java34
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java46
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/model/UserAuth.java7
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java31
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserAuthFIleDAO.java16
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java22
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java58
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java35
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java11
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java7
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java323
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java42
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java63
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java11
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java76
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java18
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java18
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java37
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java124
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java13
-rw-r--r--ufund-ui/public/jf.pngbin0 -> 1159826 bytes
-rw-r--r--ufund-ui/src/app/app-routing.module.ts14
-rw-r--r--ufund-ui/src/app/app.component.css70
-rw-r--r--ufund-ui/src/app/app.component.html19
-rw-r--r--ufund-ui/src/app/app.component.ts39
-rw-r--r--ufund-ui/src/app/app.module.ts8
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.css59
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.html82
-rw-r--r--ufund-ui/src/app/components/cupboard/cupboard.component.ts175
-rw-r--r--ufund-ui/src/app/components/dashboard/dashboard.component.css7
-rw-r--r--ufund-ui/src/app/components/dashboard/dashboard.component.html7
-rw-r--r--ufund-ui/src/app/components/dashboard/dashboard.component.ts50
-rw-r--r--ufund-ui/src/app/components/funding-basket/funding-basket.component.css85
-rw-r--r--ufund-ui/src/app/components/funding-basket/funding-basket.component.html112
-rw-r--r--ufund-ui/src/app/components/funding-basket/funding-basket.component.ts136
-rw-r--r--ufund-ui/src/app/components/home-page/home-page.component.css38
-rw-r--r--ufund-ui/src/app/components/home-page/home-page.component.html13
-rw-r--r--ufund-ui/src/app/components/home-page/home-page.component.ts10
-rw-r--r--ufund-ui/src/app/components/login/login.component.css30
-rw-r--r--ufund-ui/src/app/components/login/login.component.html16
-rw-r--r--ufund-ui/src/app/components/login/login.component.ts26
-rw-r--r--ufund-ui/src/app/components/mini-need-list/mini-need-list.component.css56
-rw-r--r--ufund-ui/src/app/components/mini-need-list/mini-need-list.component.html17
-rw-r--r--ufund-ui/src/app/components/mini-need-list/mini-need-list.component.ts19
-rw-r--r--ufund-ui/src/app/components/need-edit/need-edit.component.css21
-rw-r--r--ufund-ui/src/app/components/need-edit/need-edit.component.html24
-rw-r--r--ufund-ui/src/app/components/need-edit/need-edit.component.ts61
-rw-r--r--ufund-ui/src/app/components/need-list/need-list.component.css120
-rw-r--r--ufund-ui/src/app/components/need-list/need-list.component.html91
-rw-r--r--ufund-ui/src/app/components/need-list/need-list.component.ts275
-rw-r--r--ufund-ui/src/app/components/need-page/need-page.component.css73
-rw-r--r--ufund-ui/src/app/components/need-page/need-page.component.html62
-rw-r--r--ufund-ui/src/app/components/need-page/need-page.component.ts96
-rw-r--r--ufund-ui/src/app/components/signup/signup.component.css73
-rw-r--r--ufund-ui/src/app/components/signup/signup.component.html31
-rw-r--r--ufund-ui/src/app/components/signup/signup.component.ts167
-rw-r--r--ufund-ui/src/app/components/toast/toast.component.css57
-rw-r--r--ufund-ui/src/app/components/toast/toast.component.html7
-rw-r--r--ufund-ui/src/app/components/toast/toast.component.ts37
-rw-r--r--ufund-ui/src/app/models/Need.ts20
-rw-r--r--ufund-ui/src/app/models/User.ts2
-rw-r--r--ufund-ui/src/app/services/auth.service.ts67
-rw-r--r--ufund-ui/src/app/services/cupboard.service.ts30
-rw-r--r--ufund-ui/src/app/services/toasts.service.ts27
-rw-r--r--ufund-ui/src/app/services/users.service.ts73
-rw-r--r--ufund-ui/src/index.html16
-rw-r--r--ufund-ui/src/styles.css70
77 files changed, 2894 insertions, 949 deletions
diff --git a/README.md b/README.md
index 2ab375e..42f5a07 100644
--- a/README.md
+++ b/README.md
@@ -25,8 +25,7 @@ An online U-Fund system built in Java **21** and __Angular 19__
2. Execute `mvn compile exec:java`
3. CD into the ufund-ui directory in a new terminal
4. Execute `ng serve -o`
-3. Open in your browser `http://localhost:8080/`
-4. _add any other steps required or examples of how to use/run_
+3. Open in your browser `http://localhost:4200/`
## Known bugs and disclaimers
(It may be the case that your implementation is not perfect.)
@@ -41,8 +40,9 @@ reports in HTML.
To run tests on all tiers together do this:
-1. Execute `mvn clean test jacoco:report`
-2. Open in your browser the file at `PROJECT_API_HOME/target/site/jacoco/index.html`
+1. CD into ufund/api
+2. Execute `mvn clean test jacoco:report`
+3. Open in your browser the file at `PROJECT_API_HOME/target/site/jacoco/index.html`
To run tests on a single tier do this:
@@ -68,10 +68,7 @@ To run tests on all the tiers in isolation do this:
## How to setup/run/test program
1. Tester, first obtain the Acceptance Test plan
-2. IP address of target machine running the app
-3. Execute ________
-4. ...
-5. ...
+2. Run the batch file
## License
diff --git a/etc/Acceptance Test Plan.xlsx b/etc/Acceptance Test Plan.xlsx
index dd55e20..396cc1c 100644
--- a/etc/Acceptance Test Plan.xlsx
+++ b/etc/Acceptance Test Plan.xlsx
Binary files differ
diff --git a/start.bat b/start.bat
new file mode 100644
index 0000000..a19b267
--- /dev/null
+++ b/start.bat
@@ -0,0 +1,9 @@
+@echo off
+
+cd ufund-api
+
+start cmd /k "mvn compile exec:java"
+
+cd ../ufund-ui
+
+start cmd /k "ng serve -o" \ No newline at end of file
diff --git a/ufund-api/.gitignore b/ufund-api/.gitignore
index 052bd9d..24d3397 100644
--- a/ufund-api/.gitignore
+++ b/ufund-api/.gitignore
@@ -32,5 +32,7 @@ build/
.vscode/
### application specific ###
-# /src/main/resources/application.properties
-# /data/cupboard.json \ No newline at end of file
+ufund-api/src/main/resources/application.properties
+ufund-api/data/cupboard.json
+ufund-api/data/users.json
+ufund-api/data/userAuths.json \ No newline at end of file
diff --git a/ufund-api/data/cupboard.json b/ufund-api/data/cupboard.json
index abc2293..0e3917f 100644
--- a/ufund-api/data/cupboard.json
+++ b/ufund-api/data/cupboard.json
@@ -1 +1 @@
-[{"name":"Jellyfish Hats","id":26,"maxGoal":10.0,"type":"MONETARY","filterAttributes":["#savethejellyfish","Clothing","Storefront"],"current":0.0},{"name":"Pollution Re-Filtering","id":27,"maxGoal":1.0E7,"type":"MONETARY","filterAttributes":["Cleanup","Donations","Third-Party"],"current":0.0},{"name":"Coral re-re-habilitation","id":28,"maxGoal":10000.0,"type":"MONETARY","filterAttributes":["Preservation","#savethecoral","#helloPhil"],"current":0.0}] \ No newline at end of file
+[{"name":"Pollution Filters","location":"New York Harbor","id":5,"maxGoal":1000.0,"type":"PHYSICAL","urgent":true,"filterAttributes":[],"current":0.0,"description":"One thousand heavy duty pollution filters need to be installed as soon as possible throughout the new york harbor."},{"name":"Diving Equipment","location":"Gulf of Mexico","id":6,"maxGoal":120000.0,"type":"MONETARY","urgent":false,"filterAttributes":[],"current":0.0,"description":"Our research team in mexico needs new deep sea rated equipment to continue their research on the ecosystem! Until the equipment funding is fully reached and gear installed, no more progress can be made."},{"name":"Dog Fish research","location":"RIT","id":8,"maxGoal":1000000.0,"type":"MONETARY","urgent":true,"filterAttributes":[],"current":0.0,"description":"Dog Fish are a very interesting species that many research facilities are not researching. The funding will go towards starting research papers on the species."},{"name":"Fish Food Promotion","location":"","id":10,"maxGoal":1000.0,"type":"MONETARY","urgent":true,"filterAttributes":[],"current":0.0,"description":"The money will be spent on a small advertising campaign at a local pet store, where free fish food will be given out to people willing to listen to our cause."},{"name":"Harpoons","location":"Atlantic City","id":11,"maxGoal":25.0,"type":"PHYSICAL","urgent":false,"filterAttributes":[],"current":0.0,"description":"Harpoons are needed for an upcoming whaling museum exhibit. We aren't picky, and need any harpoons that would be interesting for display. We are accepting any harpoons at least 30 years old, but the older the better."},{"name":"Sea Urchin Hats","location":"Seaworld","id":12,"maxGoal":90.0,"type":"PHYSICAL","urgent":true,"filterAttributes":[],"current":0.0,"description":"Seaworld's sea urchins will be wearing your hats as a part of a promo! Hats donated will be used as a part of an awareness exhibit at Seaworld."},{"name":"Awareness Exhibit","location":"Seneca Park Zoo","id":13,"maxGoal":1.0E7,"type":"MONETARY","urgent":false,"filterAttributes":[],"current":0.0,"description":"Getting the Jelly Solutions message out is our top priority. We would like to open a large exhibit featuring all the endangered species due to climate change, overfishing, and pollution. Sadly, this wouldn't be cheap as we want to really get the message across to visitors through different animals, scenes, info boards, and videos."},{"name":"New Whale","location":"Seneca Park Zoo","id":14,"maxGoal":1.0,"type":"PHYSICAL","urgent":false,"filterAttributes":[],"current":0.0,"description":"Seneca park zoo needs a new whale for the upcoming promotional exhibit! The zoo will provide a commemorative plaque for the donor."},{"name":"New Gosnell Algae Filter","location":"Gosnell College","id":15,"maxGoal":40.0,"type":"MONETARY","urgent":true,"filterAttributes":[],"current":0.0,"description":"The Gosnell College fish tank gets way to dirty way too quickly. $40 surely could replace the filter with a more effective one."},{"name":"Awareness Lunches","location":"Colleges and Highschools","id":16,"maxGoal":5000.0,"type":"MONETARY","urgent":false,"filterAttributes":[],"current":0.0,"description":"College and Highschool students would be great recruits for our volunteer events. The lunches would promote our cause and demonstrate ways that they could easily contribute to the movement."},{"name":"Fish Column for RIT Tours","location":"Wallace Library","id":17,"maxGoal":2.0E7,"type":"MONETARY","urgent":false,"filterAttributes":[],"current":0.0,"description":"RIT tours always run through Wallace Library into the SHED. What better way to encourage students to attend the college than a massive aquarium column? This would not only encourage students to join RIT, and could also raise awareness for our cause."},{"name":"Submarine Matinience","location":"New York Harbor","id":18,"maxGoal":1000000.0,"type":"MONETARY","urgent":true,"filterAttributes":[],"current":0.0,"description":"Submarines are necessary tools that many other needs cannot function without. These urgent repairs need to happen as soon as possible."},{"name":"Volunteering for Volunteer Lunches ","location":"Lake Ontario","id":19,"maxGoal":5.0,"type":"PHYSICAL","urgent":false,"filterAttributes":[],"current":0.0,"description":"We need staff to help organize our awareness lunches! The lunches will recruit interested people into volunteering for upcoming events and cleanups."},{"name":"Volunteer Misc. Equipment","location":"Lake Ontario","id":20,"maxGoal":2500.0,"type":"MONETARY","urgent":true,"filterAttributes":[],"current":0.0,"description":"$2500 is needed to cover the unforeseen costs of the upcoming beach cleanup. The money will be spent on nets and other tools for volunteers."},{"name":"Invasive eel removal","location":"Pacific Seafloor","id":21,"maxGoal":1.0E8,"type":"MONETARY","urgent":true,"filterAttributes":[],"current":0.0,"description":"The population of invasive eels are destroying ecosystems. We need to remove these eels and restore balance to these ecosystems as soon as possible."},{"name":"Fishing Liscense Enforcement","location":"Rochester Bridges","id":22,"maxGoal":10000.0,"type":"MONETARY","urgent":false,"filterAttributes":[],"current":0.0,"description":"Rochester citizens won't stop fishing off bridges no matter how many times we ask. The funding will go to increased enforcement of fishing licenses in delegated stocked areas."},{"name":"Waste Runoff Management","location":"RIT Watershed","id":23,"maxGoal":98000.0,"type":"MONETARY","urgent":true,"filterAttributes":[],"current":0.0,"description":"Waste runoff into the protected watershed near RIT is a consistent issue. We need funding to research how to best solve this problem."},{"name":"Lobbying for anti-dynamite fishing legislation","location":"Washington DC","id":24,"maxGoal":50000.0,"type":"MONETARY","urgent":false,"filterAttributes":[],"current":0.0,"description":"Dynamite fishing destroys ecosystems. Legislation needs to be passed as soon as possible! However, lobbyists aren't cheap. Any support to the fund would be greatly appreciated."},{"name":"Bioluminescence Tunnel","location":"Golisano College of Computing","id":26,"maxGoal":2.8E7,"type":"MONETARY","urgent":true,"filterAttributes":[],"current":0.0,"description":"Golisano needs a biolumenescence tunnel! The addition would be costly, but would make the building much more interesting to be in. People sometimes complain about the way the building feels, and this would be a great way to fix that."}] \ No newline at end of file
diff --git a/ufund-api/data/userAuths.json b/ufund-api/data/userAuths.json
index b703ae2..f86b1a4 100644
--- a/ufund-api/data/userAuths.json
+++ b/ufund-api/data/userAuths.json
@@ -1 +1 @@
-[{"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
+[{"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":"50019b5d-25ad-40fe-bd21-19d4dbe57a92","username":"phil","expiration":"2025-04-29T20:23:12.415416825"},{"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":"904f6de1-10ab-465d-abd8-be0612311251","username":"phil","expiration":"2025-04-29T20:24:45.666998397"},{"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":"25d6a49b-c185-460c-adbe-a874419d20aa","username":"phil","expiration":"2025-04-29T20:22:19.629805123"},{"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 5b2457f..9bddb7d 100644
--- a/ufund-api/data/users.json
+++ b/ufund-api/data/users.json
@@ -1 +1 @@
-[{"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
+[{"username":"keshey","passwordHash":-1134843357,"basket":[],"type":"HELPER"},{"username":"admin","passwordHash":92668751,"basket":[],"type":"MANAGER"},{"username":"phil","passwordHash":-1054080181,"basket":[],"type":"HELPER"}] \ No newline at end of file
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java
index b46d4ee..82b2c67 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java
@@ -2,6 +2,8 @@ package com.ufund.api.ufundapi.controller;
import java.io.IOException;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -17,6 +19,7 @@ import com.ufund.api.ufundapi.service.AuthService;
@RestController
@RequestMapping("auth")
public class AuthController {
+ private static final Logger LOG = Logger.getLogger(AuthController.class.getName());
private final AuthService authService;
public AuthController(AuthService authService) {
@@ -32,15 +35,18 @@ public class AuthController {
*/
@PostMapping("")
public ResponseEntity<String> login(@RequestBody Map<String, String> params) {
+ LOG.log(Level.INFO, "POST /auth body={0}", params);
String username = params.get("username");
String password = params.get("password");
try {
String key = authService.login(username, password);
return new ResponseEntity<>(key, HttpStatus.OK);
- } catch (IllegalAccessException e) {
- return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+ } catch (IllegalAccessException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
} catch (IOException ex) {
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -52,11 +58,13 @@ public class AuthController {
*/
@DeleteMapping("")
public ResponseEntity<Object> logout(@RequestHeader("jelly-api-key") String key) {
+ LOG.log(Level.INFO, "DELETE /auth key={0}", key);
try {
authService.logout(key);
return new ResponseEntity<>(HttpStatus.OK);
- } catch (IOException e) {
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ } catch (IOException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
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 36ae341..12fb0a9 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
@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@@ -20,6 +21,7 @@ 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.AuthService;
import com.ufund.api.ufundapi.service.CupboardService;
@RestController
@@ -27,14 +29,16 @@ import com.ufund.api.ufundapi.service.CupboardService;
public class CupboardController {
private static final Logger LOG = Logger.getLogger(CupboardController.class.getName());
private final CupboardService cupboardService;
+ private final AuthService authService;
/**
* Create a cupboard controller to receive REST signals
*
* @param cupboardService The Data Access Object
*/
- public CupboardController(CupboardService cupboardService) {
+ public CupboardController(CupboardService cupboardService, AuthService authService) {
this.cupboardService = cupboardService;
+ this.authService = authService;
}
/**
@@ -47,21 +51,33 @@ public class CupboardController {
* INTERNAL_SERVER_ERROR otherwise
*/
@PostMapping("")
- public ResponseEntity<Need> createNeed(@RequestBody Map<String, Object> params) {
- System.out.println(params);
+ public ResponseEntity<Object> createNeed(@RequestBody Map<String, Object> params, @RequestHeader("jelly-api-key") String key) {
+ LOG.log(Level.INFO, "POST /cupboard body={0}", params);
+
String name = (String) params.get("name");
- double maxGoal = (double) params.get("maxGoal");
+ String image = (String) params.get("image");
+ String location = (String) params.get("location");
+ double maxGoal = ((Number) params.get("maxGoal")).doubleValue();
+ boolean urgent = (Boolean) params.get("urgent");
+ String description = (String) params.get("description");
Need.GoalType goalType = GoalType.valueOf((String) params.get("type"));
try {
- Need need = cupboardService.createNeed(name, maxGoal, goalType);
+ authService.keyHasAccessToCupboard(key);
+ Need need = cupboardService.createNeed(name, image, location, maxGoal, goalType, urgent, description);
return new ResponseEntity<>(need, HttpStatus.OK);
} catch (DuplicateKeyException ex) {
- return new ResponseEntity<>(HttpStatus.CONFLICT);
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.CONFLICT);
} catch (IllegalArgumentException ex) {
- return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
+ } catch (IllegalAccessException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
} catch (IOException ex) {
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -74,39 +90,39 @@ public class CupboardController {
* ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise
*/
@GetMapping("")
- public ResponseEntity<Need[]> getNeeds() {
- LOG.info("GET /needs");
+ public ResponseEntity<Object> getNeeds() {
+ LOG.info("GET /cupboard");
try {
Need[] needs = cupboardService.getNeeds();
return new ResponseEntity<>(needs, HttpStatus.OK);
- } catch (IOException e) {
- LOG.log(Level.SEVERE, e.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
/**
- * Responds to the GET request for all {@linkplain Need need} whose name contains
- * the text in name
- *
- * @param name The name parameter which contains the text used to find the {@link Need need}
- *
- * @return ResponseEntity with array of {@link Need need} objects (may be empty) and
- * HTTP status of OK<br>
- * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise
- * <p>
- */
+ * Responds to the GET request for all {@linkplain Need need} whose name contains
+ * the text in name
+ *
+ * @param name The name parameter which contains the text used to find the {@link Need need}
+ *
+ * @return ResponseEntity with array of {@link Need need} objects (may be empty) and
+ * HTTP status of OK<br>
+ * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise
+ * <p>
+ */
@GetMapping("/")
- public ResponseEntity<Need[]> searchNeeds(@RequestParam String name) {
- LOG.info("GET /need/?name="+name);
+ public ResponseEntity<Object> searchNeeds(@RequestParam String name) {
+ LOG.info("GET /cupboard/?name="+name);
try {
Need[] needs = cupboardService.searchNeeds(name);
return new ResponseEntity<>(needs, HttpStatus.OK);
- } catch (IOException e) {
- LOG.log(Level.SEVERE,e.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE,ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -119,8 +135,8 @@ public class CupboardController {
* ResponseEntity with HTTP status of NOT_FOUND if not found<br>
*/
@GetMapping("/{id}")
- public ResponseEntity<Need> getNeed(@PathVariable int id) {
- LOG.log(Level.INFO, "GET /need/{0}", id);
+ public ResponseEntity<Object> getNeed(@PathVariable int id) {
+ LOG.log(Level.INFO, "GET /cupboard/{0}", id);
try {
Need need = cupboardService.getNeed(id);
@@ -129,9 +145,9 @@ public class CupboardController {
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
- } catch (IOException e) {
- LOG.log(Level.SEVERE, e.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -143,9 +159,10 @@ public class CupboardController {
* @return OK response and the need if it was successful, or INTERNAL_SERVER_ERROR if there was an issue
*/
@PutMapping("/{id}")
- public ResponseEntity<Need> updateNeed(@RequestBody Need need, @PathVariable int id) {
- LOG.log(Level.INFO, "Updating need: " + need);
+ public ResponseEntity<Object> updateNeed(@RequestBody Need need, @PathVariable int id, @RequestHeader("jelly-api-key") String key) {
+ LOG.log(Level.INFO, "PUT /cupboard/{0} body={1}", of(id, need));
try {
+ authService.keyHasAccessToCupboard(key);
Need updatedNeed = cupboardService.updateNeed(need, id);
if (updatedNeed != null) {
return new ResponseEntity<>(need, HttpStatus.OK);
@@ -153,11 +170,41 @@ public class CupboardController {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
} catch (IllegalArgumentException ex) {
- ex.printStackTrace();
- return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
+ } catch (IllegalAccessException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ }
+
+ /**
+ * Checks out a need by checkoutAmount
+ *
+ * @param data JSON object with parameters needID and amount
+ * @param key Key used to authenticate user
+ * @return OK if successful, other statuses if failure
+ */
+ @PutMapping("/checkout")
+ public ResponseEntity<Object> checkoutNeeds(@RequestBody Map<String, Integer> data, @RequestHeader("jelly-api-key") String key) {
+ int needID = data.get("needID");
+ int checkoutAmount = data.get("amount");
+ LOG.log(Level.INFO, "PUT /need/checkout body={0}", data);
+ try {
+ cupboardService.checkoutNeed(needID, checkoutAmount, key);
+ return new ResponseEntity<>(HttpStatus.OK);
+ } catch (IllegalArgumentException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
+ } catch (IllegalAccessException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
} catch (IOException ex) {
- ex.printStackTrace();
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -168,17 +215,27 @@ public class CupboardController {
* @return OK if the need was deleted, NOT_FOUND if the need was not found, or INTERNAL_SERVER_ERROR if an error occurred
*/
@DeleteMapping("/{id}")
- public ResponseEntity<Need> deleteNeed(@PathVariable int id) {
+ public ResponseEntity<Object> deleteNeed(@PathVariable int id, @RequestHeader("jelly-api-key") String key) {
+ LOG.log(Level.INFO, "DELETE /cupboard/{0}", id);
try {
+ authService.keyHasAccessToCupboard(key);
Need need = cupboardService.getNeed(id);
if (cupboardService.deleteNeed(id)) {
return new ResponseEntity<>(need, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
- }
- } catch (IOException e) {
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ } catch (IllegalAccessException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
+ private Object[] of(Object ...params) {
+ return params;
+ }
+
}
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 dfaad3a..a34e891 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
@@ -1,7 +1,6 @@
package com.ufund.api.ufundapi.controller;
import java.io.IOException;
-import java.security.InvalidParameterException;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -42,7 +41,8 @@ public class UserController {
* otherwise
*/
@PostMapping("")
- public ResponseEntity<User> createUser(@RequestBody Map<String, String> params) {
+ public ResponseEntity<Object> createUser(@RequestBody Map<String, String> params) {
+ LOG.log(Level.INFO, "POST /users body={0}", params);
String username = params.get("username");
String password = params.get("password");
@@ -54,9 +54,11 @@ public class UserController {
return new ResponseEntity<>(HttpStatus.CONFLICT);
}
} catch (DuplicateKeyException ex) {
- return new ResponseEntity<>(HttpStatus.CONFLICT);
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.CONFLICT);
} catch (IOException ex) {
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -71,11 +73,11 @@ public class UserController {
* ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise
*/
@GetMapping("/{username}")
- public ResponseEntity<User> getUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) {
- LOG.log(Level.INFO, "GET /user/{0}", username);
+ public ResponseEntity<Object> getUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) {
+ LOG.log(Level.INFO, "GET /user/{0} key={1}", of(username, key));
try {
- authService.authenticate(username, key);
+ authService.keyHasAccessToUser(username, key);
User user = userService.getUser(username);
if (user != null) {
return new ResponseEntity<>(user.withoutPasswordHash(), HttpStatus.OK);
@@ -83,10 +85,11 @@ public class UserController {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
} catch (IllegalAccessException ex) {
- return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
- } catch (IOException e) {
- LOG.log(Level.SEVERE, e.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -101,24 +104,26 @@ public class UserController {
* INTERNAL_SERVER_ERROR if there was an issue
*/
@PutMapping("/{username}")
- public ResponseEntity<User> updateUser(@RequestBody User user, @PathVariable String username, @RequestHeader("jelly-api-key") String key) {
- LOG.log(Level.INFO,"PUT: " + user + " " + username + " " + key.toString());
+ public ResponseEntity<Object> updateUser(@RequestBody User user, @PathVariable String username, @RequestHeader("jelly-api-key") String key) {
+ LOG.log(Level.INFO,"PUT /users/{0} body={1} key={2}", of(username, user, key));
try {
- //authService.authenticate(username, key);
+ authService.keyHasAccessToUser(username, key);
user = userService.updateUser(user, username);
if (user != null) {
return new ResponseEntity<>(user, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
- } catch (InvalidParameterException ex) {
- 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 (IllegalArgumentException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
+ } catch (IllegalAccessException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+ }
}
/**
@@ -130,20 +135,27 @@ public class UserController {
* INTERNAL_SERVER_ERROR if an error occurred
*/
@DeleteMapping("/{username}")
- public ResponseEntity<Boolean> deleteUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) {
+ public ResponseEntity<Object> deleteUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) {
+ LOG.log(Level.INFO, "DELETE /users/{0} id={1}", of(username, key));
try {
- authService.authenticate(username, key);
+ authService.keyHasAccessToUser(username, key);
if (userService.deleteUser(username)) {
return new ResponseEntity<>(HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
- } catch (IOException e) {
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
- } catch (IllegalAccessException e) {
- return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+ } catch (IllegalAccessException ex) {
+ LOG.log(Level.WARNING, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
+ private Object[] of(Object ...params) {
+ return params;
+ }
+
}
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java
index c0e9214..9b6170b 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java
@@ -10,38 +10,57 @@ public class Need {
}
@JsonProperty("name") private String name;
+ @JsonProperty("image") private String image;
+ @JsonProperty("location") private String location;
@JsonProperty("id") private int id;
@JsonProperty("filterAttributes") private String[] filterAttributes;
@JsonProperty("type") final private GoalType type;
@JsonProperty("maxGoal") private double maxGoal;
+ @JsonProperty("urgent") private boolean urgent;
@JsonProperty("current") private double current;
+ @JsonProperty("description") private String description;
/**
- * Create a new need
+ * Create a new need, used by the controller
*
* @param name The name of the need
+ * @param location The physical location of the need
* @param id The unique ID of the need
* @param maxGoal The maximum goal for this need
* @param type The type of need (monetary, physical)
+ * @param urgent The urgency of the need
+ * @param description The description of the need
*/
- public Need(@JsonProperty("name") String name, @JsonProperty("id") int id, @JsonProperty("maxGoal") double maxGoal, GoalType type) {
+ public Need(@JsonProperty("name") String name, @JsonProperty("image") String image, @JsonProperty("location") String location, @JsonProperty("id") int id, @JsonProperty("maxGoal") double maxGoal, @JsonProperty("type") GoalType type, @JsonProperty("urgent") boolean urgent, @JsonProperty("Description") String description) {
this.id = id;
+ this.image = image;
+ this.location = location;
this.name = name;
this.maxGoal = maxGoal;
this.type = type;
+ this.urgent = urgent;
+ this.description = description;
}
/**
* Create a new need
*
* @param name The name of the need
+ * @param image The image representation of the need
+ * @param location The location of the need
* @param maxGoal The maximum goal for this need
* @param type The type of need (monetary, physical)
+ * @param urgent The urgency of the need
+ * @param description The description of the need
*/
- public Need(String name, GoalType type, double maxGoal) {
+ public Need(String name, String image, String location, double maxGoal, GoalType type, boolean urgent, String description) {
this.name = name;
+ this.image = image;
+ this.location = location;
this.type = type;
this.maxGoal = maxGoal;
+ this.urgent = urgent;
+ this.description = description;
}
/**
@@ -51,11 +70,15 @@ public class Need {
*/
public Need(Need other) {
this.name = other.name;
+ this.image = other.image;
+ this.location = other.location;
this.id = other.id;
this.filterAttributes = other.filterAttributes;
this.type = other.type;
this.maxGoal = other.maxGoal;
this.current = other.current;
+ this.urgent = other.urgent;
+ this.description = other.description;
}
public String getName() {
@@ -82,10 +105,15 @@ public class Need {
return current;
}
+
public void setCurrent(double current) {
this.current = current;
}
+ public void incrementCurrent(double incrementAmount) {
+ this.current += incrementAmount;
+ }
+
public void setFilterAttributes(String[] filterAttributes) {
this.filterAttributes = filterAttributes;
}
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 6de1a8a..58b62df 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
@@ -12,18 +12,23 @@ public class User {
MANAGER
}
- @JsonProperty("username") private final String username;
- @JsonProperty("passwordHash") private int passwordHash;
- @JsonProperty("basket") private final List<Integer> basket;
- @JsonProperty("type") private final UserType type;
+ @JsonProperty("username")
+ private final String username;
+ @JsonProperty("passwordHash")
+ private int passwordHash;
+ @JsonProperty("basket")
+ private final List<Integer> basket;
+ @JsonProperty("type")
+ private final UserType type;
/**
* Create a new user
*
- * @param username The name of the user
- * @param basket A basket to copy from
+ * @param username The name of the user
+ * @param basket A basket to copy from
*/
- public User(@JsonProperty("username") String username, @JsonProperty("passwordHash") int passwordHash, @JsonProperty("basket") List<Integer> basket, @JsonProperty("type") UserType userType) {
+ public User(@JsonProperty("username") String username, @JsonProperty("passwordHash") int passwordHash,
+ @JsonProperty("basket") List<Integer> basket, @JsonProperty("type") UserType userType) {
this.username = username;
this.basket = basket;
this.passwordHash = passwordHash;
@@ -35,30 +40,46 @@ public class User {
username,
password.hashCode(),
new ArrayList<>(),
- UserType.HELPER
- );
+ UserType.HELPER);
}
public String getUsername() {
return username;
}
+ /**
+ * Verifies if the provided password's hash is the same as the user's actual
+ * hash
+ *
+ * @param password The password to check if valid
+ * @return True or false depending on if it's equal
+ */
public boolean verifyPassword(String password) {
return password.hashCode() == passwordHash;
}
+ /**
+ * Adds a need's ID to a user's basket
+ *
+ * @param need The need to add
+ */
public void addToBasket(Need need) {
basket.add(need.getId());
}
- public Integer[] getNeeds() {
+ public Integer[] getBasket() {
return basket.toArray(Integer[]::new);
}
- public boolean removeBasketNeed(Integer needID) {
- return basket.remove(needID);
+ public void removeBasketNeed(Integer needID) {
+ basket.remove(needID);
}
+ /**
+ * Returns a user without a password hash for security purposes
+ *
+ * @return new User with empty password hash
+ */
public User withoutPasswordHash() {
return new User(this.username, 0, this.basket, this.type);
}
@@ -71,6 +92,7 @@ public class User {
this.passwordHash = other.passwordHash;
}
+ @Override
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/model/UserAuth.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/UserAuth.java
index 1c11a28..78dccec 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/UserAuth.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/UserAuth.java
@@ -1,10 +1,10 @@
package com.ufund.api.ufundapi.model;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
import java.time.LocalDateTime;
import java.util.UUID;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
public class UserAuth {
@JsonProperty("key") String key;
@JsonProperty("username") String username;
@@ -12,12 +12,13 @@ public class UserAuth {
public UserAuth(@JsonProperty("key") String key, @JsonProperty("username") String username, @JsonProperty("expiration") LocalDateTime expiration) {
this.key = key;
- this.expiration = expiration;
this.username = username;
+ this.expiration = expiration;
}
/**
* Generate a new user authentication profile
+ *
* @param username the username the key will belong to
* @return The new user authentication profile
*/
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..7efda83 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
@@ -1,15 +1,16 @@
package com.ufund.api.ufundapi.persistence;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.ufund.api.ufundapi.model.Need;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
+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;
+
@Component
public class CupboardFileDAO implements CupboardDAO {
@@ -52,31 +53,20 @@ public class CupboardFileDAO implements CupboardDAO {
}
/**
- * Return an array of the needs
- *
- * @return An array of all the needs
- */
- private Need[] getNeedsArray() {
- return needs.values().toArray(Need[]::new);
- }
-
- /**
* Saves the needs to json
*
- * @return True if the save was successful, false otherwise
* @throws IOException If there was an IO issue saving the file
*/
- private boolean save() throws IOException {
- Need[] needArray = getNeedsArray();
+ private void save() throws IOException {
+ Need[] needArray = needs.values().toArray(Need[]::new);
objectMapper.writeValue(new File(filename), needArray);
- return true;
}
@Override
public Need[] getNeeds() {
synchronized (needs) {
- return getNeedsArray();
+ return needs.values().toArray(Need[]::new);
}
}
@@ -117,7 +107,8 @@ public class CupboardFileDAO implements CupboardDAO {
synchronized (needs) {
if (needs.containsKey(id)) {
needs.remove(id);
- return save();
+ save();
+ return true;
} else {
return false;
}
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserAuthFIleDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserAuthFIleDAO.java
index 1fc1e92..24a426b 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserAuthFIleDAO.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserAuthFIleDAO.java
@@ -1,15 +1,17 @@
package com.ufund.api.ufundapi.persistence;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.ufund.api.ufundapi.model.UserAuth;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
import java.io.File;
import java.io.IOException;
+import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ufund.api.ufundapi.model.UserAuth;
+
@Component
public class UserAuthFIleDAO implements UserAuthDAO {
@@ -35,7 +37,9 @@ public class UserAuthFIleDAO implements UserAuthDAO {
UserAuth[] userAuthKeysArray = objectMapper.readValue(new File(filename), UserAuth[].class);
for (UserAuth userAuth : userAuthKeysArray) {
- userAuthMap.put(userAuth.getKey(), userAuth);
+ if (userAuth.getExpiration().isAfter(LocalDateTime.now())) {
+ userAuthMap.put(userAuth.getKey(), userAuth);
+ }
}
}
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 6e900aa..ec94da8 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,9 +2,9 @@ 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;
+import java.util.Objects;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@@ -44,12 +44,10 @@ public class UserFileDAO implements UserDAO {
/**
* Saves the needs to json
*
- * @return True if the save was successful, false otherwise
* @throws IOException If there was an IO issue saving the file
*/
- private boolean save() throws IOException {
+ private void save() throws IOException {
objectMapper.writeValue(new File(filename), users.values());
- return true;
}
@Override
@@ -82,17 +80,8 @@ 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);
- if (user.getNeeds() == null || user.getType() == null) {
- User oldData = users.get(user.getUsername());
- User crutch = new User(oldData.getUsername(), 0, new ArrayList<Integer>(), oldData.getType());
- crutch.copyPassword(oldData);
- users.put(user.getUsername(), crutch);
- } else {
- var old = users.put(user.getUsername(), user);
- user.copyPassword(old);
- }
+ var old = users.put(user.getUsername(), user);
+ user.copyPassword(Objects.requireNonNull(old));
save();
return user;
} else {
@@ -106,7 +95,8 @@ public class UserFileDAO implements UserDAO {
synchronized (users) {
if (users.containsKey(username)) {
users.remove(username);
- return save();
+ save();
+ return true;
} else {
return false;
}
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java
index 87a16a6..cdce80d 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/AuthService.java
@@ -1,11 +1,12 @@
package com.ufund.api.ufundapi.service;
+import java.io.IOException;
+
+import org.springframework.stereotype.Component;
+
import com.ufund.api.ufundapi.model.User;
import com.ufund.api.ufundapi.model.UserAuth;
import com.ufund.api.ufundapi.persistence.UserAuthDAO;
-import org.springframework.stereotype.Component;
-
-import java.io.IOException;
@Component
public class AuthService {
@@ -24,18 +25,51 @@ public class AuthService {
* @param targetUsername The targetUsername of the user trying to be accessed.
* @param key The api key obtained by the client from logging in.
* @throws IllegalAccessException Thrown if access was denied to the user.
+ * @throws IOException Thrown on a file writing issue
+ */
+ public void keyHasAccessToUser(String targetUsername, String key) throws IllegalAccessException, IOException {
+ var userAuth = userAuthDAO.getUserAuth(key);
+ if (userAuth == null) {
+ throw new IllegalAccessException("Invalid authentication key");
+ }
+
+ var username = userAuth.getUsername();
+ var userType = userService.getUser(username).getType();
+ if (!username.equals(targetUsername) && userType != User.UserType.MANAGER) {
+ throw new IllegalAccessException("Provided key does not grant access to perform the requested operation");
+ }
+ }
+
+ /**
+ * Check if the provided key is valid
+ * @param key The api key obtained by the client from logging in.
+ * @throws IllegalAccessException Thrown if access was denied to the user.
+ * @throws IOException Thrown on a file writing issue
+ */
+ public void keyIsValid(String key) throws IOException, IllegalAccessException {
+ var userAuth = userAuthDAO.getUserAuth(key);
+ if (userAuth == null) {
+ throw new IllegalAccessException("Invalid authentication key");
+ }
+ }
+
+ /**
+ * Check if the provided key has access to edit the cupboard
+ * @param key The api key obtained by the client from logging in.
+ * @throws IllegalAccessException Thrown if access was denied to the user.
+ * @throws IOException Thrown on a file writing issue
*/
- public void authenticate(String targetUsername, String key) throws IllegalAccessException, IOException {
+ public void keyHasAccessToCupboard(String key) throws IOException, IllegalAccessException {
var userAuth = userAuthDAO.getUserAuth(key);
if (userAuth == null) {
- throw new IllegalAccessException("Unauthenticated");
+ throw new IllegalAccessException("Invalid authentication key");
+ }
+
+ var username = userAuth.getUsername();
+ var userType = userService.getUser(username).getType();
+ if (userType != User.UserType.MANAGER) {
+ throw new IllegalAccessException("Provided key does not grant access to perform the requested operation");
}
-//
-// var username = userAuth.getUsername();
-// var userType = userService.getUser(username).getType();
-// if (!username.equals(targetUsername) && userType != User.UserType.MANAGER) {
-// throw new IllegalAccessException("Unauthorized");
-// }
}
/**
@@ -50,7 +84,7 @@ public class AuthService {
public String login(String username, String password) throws IllegalAccessException, IOException {
var usr = userService.getUser(username);
if (usr == null || !usr.verifyPassword(password)) {
- throw new IllegalAccessException("Unauthorized");
+ throw new IllegalAccessException("Incorrect username or password");
}
var userAuth = UserAuth.generate(username);
userAuthDAO.addUserAuth(userAuth);
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java
index 2398745..993e7c1 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java
@@ -3,6 +3,7 @@ package com.ufund.api.ufundapi.service;
import java.io.IOException;
import java.util.Arrays;
+import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import com.ufund.api.ufundapi.DuplicateKeyException;
@@ -13,8 +14,10 @@ import com.ufund.api.ufundapi.persistence.CupboardDAO;
public class CupboardService {
private final CupboardDAO cupboardDAO;
+ final AuthService authService;
- public CupboardService(CupboardDAO cupboardDAO) {
+ public CupboardService(@Lazy AuthService authService, CupboardDAO cupboardDAO) {
+ this.authService = authService;
this.cupboardDAO = cupboardDAO;
}
@@ -22,16 +25,22 @@ public class CupboardService {
* Creates a new Need
*
* @param name The name of the need to create
+ * @param image The image representation of the need to create
+ * @param location The location of the new need
* @param maxGoal The max goal of the new need
* @param goalType The goal type of the new need
+ * @param urgent The urgency of the new need
+ * @param description The description of the new need
* @return The need that was created
* @throws IOException Thrown if there was any issue saving the data
* @throws DuplicateKeyException If there already exists a need with the same name
*/
- public Need createNeed(String name, double maxGoal, Need.GoalType goalType) throws IOException, DuplicateKeyException {
+ public Need createNeed(String name, String image, String location, double maxGoal, Need.GoalType goalType, boolean urgent, String description) throws IOException, DuplicateKeyException {
if (maxGoal <= 0) {
throw new IllegalArgumentException("Max Goal must be greater than zero");
+ } else if (goalType.equals(Need.GoalType.PHYSICAL) && maxGoal % 1 != 0) {
+ throw new IllegalArgumentException("Cannot have non whole number value for physical goal");
}
for (Need searchNeed : cupboardDAO.getNeeds()) {
@@ -40,7 +49,7 @@ public class CupboardService {
}
}
- Need need = new Need(name, goalType, maxGoal);
+ Need need = new Need(name, image, location, maxGoal, goalType, urgent, description);
return cupboardDAO.addNeed(need);
}
@@ -92,11 +101,30 @@ public class CupboardService {
}
if (need.getMaxGoal() <= 0) {
throw new IllegalArgumentException("Goal must be greater than 0");
+ } else if (need.getType().equals(Need.GoalType.PHYSICAL) && need.getMaxGoal() % 1 != 0) {
+ throw new IllegalArgumentException("Cannot have non whole number value for physical goal");
}
return cupboardDAO.updateNeed(need);
}
/**
+ * Checks out a need with the desired amount
+ *
+ * @param id The ID of the need to update
+ * @param checkoutAmount The amount to update the need by
+ * @throws IOException If there is an error reading the file
+ * @throws IllegalAccessException If the user has insufficient permission
+ */
+ public void checkoutNeed(int id, double checkoutAmount, String key) throws IOException, IllegalAccessException {
+ if (checkoutAmount <= 0) {
+ throw new IllegalArgumentException("Amount must be greater than 0");
+ }
+ authService.keyIsValid(key);
+ Need need = cupboardDAO.getNeed(id);
+ need.incrementCurrent(checkoutAmount);
+ }
+
+ /**
* Delete a need from the cupboard
*
* @param id the ID of the need
@@ -104,6 +132,7 @@ public class CupboardService {
* @throws IOException Thrown on any problem removing the need
*/
public boolean deleteNeed(int id) throws IOException {
+
return cupboardDAO.deleteNeed(id);
}
}
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 caf9f4c..6e27f50 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
@@ -12,7 +12,7 @@ import com.ufund.api.ufundapi.persistence.UserDAO;
public class UserService {
private final UserDAO userDAO;
- private final CupboardService cupboardService;
+ final CupboardService cupboardService;
public UserService(UserDAO userDao, CupboardService cupboardService) {
this.userDAO = userDao;
@@ -44,7 +44,10 @@ public class UserService {
*/
public User getUser(String username) throws IOException {
User user = userDAO.getUser(username);
- for (int needId : user.getNeeds()) {
+ if (user == null) {
+ return null;
+ }
+ for (int needId : user.getBasket()) {
if (cupboardService.getNeed(needId) == null) {
user.removeBasketNeed(needId);
}
@@ -55,7 +58,7 @@ public class UserService {
/**
* Updates a user
*
- * @param user The ID of the user to update
+ * @param user The ID of the user to update
* @param username The user object to set (note: the ID is ignored)
* @return The updated user object
* @throws IOException Thrown if there was any issue saving the data
@@ -77,5 +80,5 @@ public class UserService {
public boolean deleteUser(String username) throws IOException {
return userDAO.deleteUser(username);
}
-
+
}
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java
index 3d4637d..f4b5980 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java
@@ -8,7 +8,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.mockito.ArgumentMatchers.any;
-import org.mockito.Mockito;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -26,7 +25,7 @@ public class AuthControllerTest {
private Map<String, String> authMap;
@BeforeEach
- private void setupAuthController() {
+ public void setupAuthController() {
mockAuthService = mock(AuthService.class);
authController = new AuthController(mockAuthService);
@@ -76,7 +75,7 @@ public class AuthControllerTest {
}
@Test
- public void testLogout() throws IllegalAccessException, IOException {
+ public void testLogout() {
// Setup
String key = "123";
@@ -88,7 +87,7 @@ public class AuthControllerTest {
}
@Test
- public void testLogoutIOException() throws IllegalAccessException, IOException {
+ public void testLogoutIOException() throws IOException {
// Setup
String key = "123";
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
index 6ef6710..8572ec6 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
@@ -7,10 +7,11 @@ import static java.util.Map.entry;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.*;
+
+import com.ufund.api.ufundapi.service.AuthService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import org.springframework.http.HttpStatus;
import com.ufund.api.ufundapi.DuplicateKeyException;
@@ -21,29 +22,44 @@ import com.ufund.api.ufundapi.service.CupboardService;
public class CupboardControllerTest {
private CupboardController cupboardController;
private CupboardService mockCupboardService;
+ private final String key = "dummyKey";
+ private AuthService mockAuthService;
@BeforeEach
public void setupCupboardDAO() {
+ mockAuthService = mock(AuthService.class);
mockCupboardService = mock(CupboardService.class);
- cupboardController = new CupboardController(mockCupboardService);
+ cupboardController = new CupboardController(mockCupboardService, mockAuthService);
+
+ try {
+ doThrow().when(mockAuthService).keyHasAccessToCupboard(key);
+ } catch (Exception ignored) {}
}
@Test
public void createNeed() throws IOException, DuplicateKeyException {
String name = "Test";
+ String location = "Atlantis";
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
- var need = new Need(name, type, maxGoal);
- when(mockCupboardService.createNeed(name, maxGoal, type)).thenReturn(need);
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
+ when(mockCupboardService.createNeed(name, image, location, maxGoal, type, urgent, description)).thenReturn(need);
Map<String, Object> needMap = Map.ofEntries(
entry("name", "Test"),
- entry("maxGoal", 100.0),
- entry("type", "MONETARY")
+ entry("image", ""),
+ entry("location", "Atlantis"),
+ entry("maxGoal", 100),
+ entry("type", "MONETARY"),
+ entry("urgent", false),
+ entry("description", "")
);
- var res = cupboardController.createNeed(needMap);
+ var res = cupboardController.createNeed(needMap, key);
assertEquals(HttpStatus.OK, res.getStatusCode());
assertEquals(need, res.getBody());
@@ -51,41 +67,94 @@ public class CupboardControllerTest {
@Test
public void createNeedBadMaxGoal() throws IOException, DuplicateKeyException {
- when(mockCupboardService.createNeed("Name", -100, Need.GoalType.MONETARY)).thenThrow(new IllegalArgumentException());
+ when(mockCupboardService.createNeed("Test", "", "Atlantis", -100, Need.GoalType.MONETARY, false, "")).thenThrow(new IllegalArgumentException());
Map<String, Object> needMap = Map.ofEntries(
- entry("name", "Name"),
- entry("maxGoal", -100.0),
- entry("type", "MONETARY"));
+ entry("name", "Test"),
+ entry("image", ""),
+ entry("location", "Atlantis"),
+ entry("maxGoal", -100),
+ entry("type", "MONETARY"),
+ entry("urgent", false),
+ entry("description", "")
+ );
- var res = cupboardController.createNeed(needMap);
+ var res = cupboardController.createNeed(needMap, key);
assertEquals(HttpStatus.BAD_REQUEST, res.getStatusCode());
}
@Test
public void createNeedIOException() throws IOException, DuplicateKeyException {
- when(mockCupboardService.createNeed("Name", 100, Need.GoalType.MONETARY)).thenThrow(new IOException());
+ when(mockCupboardService.createNeed("Test", "", "Atlantis", 100, Need.GoalType.MONETARY, false, "")).thenThrow(new IOException());
Map<String, Object> needMap = Map.ofEntries(
- entry("name", "Name"),
- entry("maxGoal", 100.0),
- entry("type", "MONETARY"));
+ entry("name", "Test"),
+ entry("image", ""),
+ entry("location", "Atlantis"),
+ entry("maxGoal", 100),
+ entry("type", "MONETARY"),
+ entry("urgent", false),
+ entry("description", "")
+ );
- var res = cupboardController.createNeed(needMap);
+ var res = cupboardController.createNeed(needMap, key);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode());
}
@Test
+ public void createNeedConflict() throws IOException, DuplicateKeyException {
+ when(mockCupboardService.createNeed("Test", "", "Atlantis", 100, Need.GoalType.MONETARY, false, "")).thenThrow(new DuplicateKeyException(""));
+
+ Map<String, Object> needMap = Map.ofEntries(
+ entry("name", "Test"),
+ entry("image", ""),
+ entry("location", "Atlantis"),
+ entry("maxGoal", 100),
+ entry("type", "MONETARY"),
+ entry("urgent", false),
+ entry("description", "")
+ );
+
+ var res = cupboardController.createNeed(needMap, key);
+
+ assertEquals(HttpStatus.CONFLICT, res.getStatusCode());
+ }
+
+ @Test
+ public void createNeedUnauthorized() throws IOException, IllegalAccessException {
+ doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key);
+
+ Map<String, Object> needMap = Map.ofEntries(
+ entry("name", "Test"),
+ entry("location", "Atlantis"),
+ entry("maxGoal", 100),
+ entry("type", "MONETARY"),
+ entry("urgent", false)
+ );
+
+ var res = cupboardController.createNeed(needMap, key);
+
+ assertEquals(HttpStatus.UNAUTHORIZED, res.getStatusCode());
+ }
+
+ @Test
public void getNeeds() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeeds()).thenReturn(new Need[]{need});
var res = cupboardController.getNeeds();
assertEquals(HttpStatus.OK, res.getStatusCode());
- assertArrayEquals(new Need[]{need}, res.getBody());
+ assertArrayEquals(new Need[]{need}, (Need[]) res.getBody());
}
@Test
@@ -104,18 +173,25 @@ public class CupboardControllerTest {
var res = cupboardController.getNeeds();
assertEquals(HttpStatus.OK, res.getStatusCode());
- assertArrayEquals(new Need[]{}, res.getBody());
+ assertArrayEquals(new Need[]{}, (Need[]) res.getBody());
}
@Test
public void searchNeeds() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.searchNeeds("Na")).thenReturn(new Need[]{need});
var res = cupboardController.searchNeeds("Na");
assertEquals(HttpStatus.OK, res.getStatusCode());
- assertArrayEquals(new Need[]{need}, res.getBody());
+ assertArrayEquals(new Need[]{need}, (Need[]) res.getBody());
}
@Test
@@ -134,12 +210,19 @@ public class CupboardControllerTest {
var res = cupboardController.searchNeeds("Na");
assertEquals(HttpStatus.OK, res.getStatusCode());
- assertArrayEquals(new Need[]{}, res.getBody());
+ assertArrayEquals(new Need[]{}, (Need[]) res.getBody());
}
@Test
public void getNeed() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(need.getId())).thenReturn(need);
var res = cupboardController.getNeed(need.getId());
@@ -150,7 +233,14 @@ public class CupboardControllerTest {
@Test
public void getNeedIOException() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(need.getId())).thenThrow(new IOException());
var res = cupboardController.getNeed(need.getId());
@@ -160,7 +250,14 @@ public class CupboardControllerTest {
@Test
public void getNeedFail() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(need.getId())).thenReturn(null);
var res = cupboardController.getNeed(need.getId());
@@ -171,10 +268,17 @@ public class CupboardControllerTest {
@Test
public void updateNeeds() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.updateNeed(need, 1)).thenReturn(need);
- var res = cupboardController.updateNeed(need, 1);
+ var res = cupboardController.updateNeed(need, 1, key);
assertEquals(HttpStatus.OK, res.getStatusCode());
assertEquals(need, res.getBody());
@@ -182,21 +286,86 @@ public class CupboardControllerTest {
@Test
public void updateNeedsIOException() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.updateNeed(need, 1)).thenThrow(new IOException());
- var res = cupboardController.updateNeed(need, 1);
+ var res = cupboardController.updateNeed(need, 1, key);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode());
}
@Test
+ public void updateNeedMissing() throws IOException {
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
+ when(mockCupboardService.updateNeed(need, 1)).thenReturn(null);
+
+ var res = cupboardController.updateNeed(need, 1, key);
+
+ assertEquals(HttpStatus.NOT_FOUND, res.getStatusCode());
+ }
+
+ @Test
+ public void updateNeedBadRequest() throws IOException {
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
+ when(mockCupboardService.updateNeed(need, 1)).thenThrow(new IllegalArgumentException());
+
+ var res = cupboardController.updateNeed(need, 1, key);
+
+ assertEquals(HttpStatus.BAD_REQUEST, res.getStatusCode());
+ }
+
+ @Test
+ public void updateNeedUnauthorized() throws IOException, IllegalAccessException {
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
+ doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key);
+
+ var res = cupboardController.updateNeed(need, 1, key);
+
+ assertEquals(HttpStatus.UNAUTHORIZED, res.getStatusCode());
+ }
+
+ @Test
public void deleteNeed() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(1)).thenReturn(need);
when(mockCupboardService.deleteNeed(1)).thenReturn(true);
- var res = cupboardController.deleteNeed(1);
+ var res = cupboardController.deleteNeed(1, key);
assertEquals(HttpStatus.OK, res.getStatusCode());
}
@@ -206,18 +375,100 @@ public class CupboardControllerTest {
when(mockCupboardService.getNeed(1)).thenReturn(null);
when(mockCupboardService.deleteNeed(1)).thenReturn(false);
- var res = cupboardController.deleteNeed(1);
+ var res = cupboardController.deleteNeed(1, key);
assertEquals(HttpStatus.NOT_FOUND, res.getStatusCode());
}
@Test
+ public void deleteNeedUnauthorized() throws IOException, IllegalAccessException {
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
+ when(mockCupboardService.getNeed(1)).thenReturn(need);
+ doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key);
+
+ var res = cupboardController.deleteNeed(1, key);
+
+ assertEquals(HttpStatus.UNAUTHORIZED, res.getStatusCode());
+ }
+
+ @Test
public void deleteNeedIOException() throws IOException {
- var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
+ String name = "Test";
+ String location = "Atlantis";
+ int maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(1)).thenReturn(need);
when(mockCupboardService.deleteNeed(1)).thenThrow(new IOException());
- var res = cupboardController.deleteNeed(1);
+ var res = cupboardController.deleteNeed(1, key);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode());
+ }
+
+ @Test
+ public void checkoutNeeds() throws IOException, IllegalAccessException {
+ doNothing().when(mockCupboardService).checkoutNeed(0, 20, key);
+
+
+ Map<String, Integer> needMap = Map.ofEntries(
+ entry("needID", 0),
+ entry("amount", 20)
+ );
+
+ var res = cupboardController.checkoutNeeds(needMap, key);
+
+ assertEquals(HttpStatus.OK, res.getStatusCode());
+ }
+
+ @Test
+ public void checkoutNeedsBadRequest() throws IOException, IllegalAccessException {
+ doThrow(new IllegalArgumentException()).when(mockCupboardService).checkoutNeed(0, 20, key);
+
+ Map<String, Integer> needMap = Map.ofEntries(
+ entry("needID", 0),
+ entry("amount", 20)
+ );
+
+ var res = cupboardController.checkoutNeeds(needMap, key);
+
+ assertEquals(HttpStatus.BAD_REQUEST, res.getStatusCode());
+ }
+
+ @Test
+ public void checkoutNeedsUnauthorized() throws IOException, IllegalAccessException {
+ doThrow(new IllegalAccessException()).when(mockCupboardService).checkoutNeed(0, 20, key);
+
+ Map<String, Integer> needMap = Map.ofEntries(
+ entry("needID", 0),
+ entry("amount", 20)
+ );
+
+ var res = cupboardController.checkoutNeeds(needMap, key);
+
+ assertEquals(HttpStatus.UNAUTHORIZED, res.getStatusCode());
+ }
+
+ @Test
+ public void checkoutNeedsInternalError() throws IOException, IllegalAccessException {
+ doThrow(new IOException()).when(mockCupboardService).checkoutNeed(0, 20, key);
+
+ Map<String, Integer> needMap = Map.ofEntries(
+ entry("needID", 0),
+ entry("amount", 20)
+ );
+
+ var res = cupboardController.checkoutNeeds(needMap, key);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode());
}
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java
index 5542f49..5870a93 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java
@@ -50,12 +50,12 @@ public class UserControllerTest {
// Invoke
- ResponseEntity<User> response = userController.getUser(username, key);
+ ResponseEntity<Object> response = userController.getUser(username, key);
// Analyze
assertEquals(HttpStatus.OK, response.getStatusCode());
assertNotNull(response.getBody());
- assertEquals(user.getUsername(), response.getBody().getUsername());
+ assertEquals(user.getUsername(), ((User) response.getBody()).getUsername());
}
@Test
@@ -69,7 +69,7 @@ public class UserControllerTest {
// Invoke
- ResponseEntity<User> response = userController.getUser(username, key);
+ ResponseEntity<Object> response = userController.getUser(username, key);
// Analyze
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
@@ -82,10 +82,10 @@ public class UserControllerTest {
String key = UserAuth.generate(username).getKey();
// When getUser is called on the Mock User service, throw an IOException
// doThrow(new IllegalAccessException()).when(mockUserService).getUser(username);
- doThrow(new IllegalAccessException()).when(mockAuthService).authenticate(username, key);
+ doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key);
// Invoke
- ResponseEntity<User> response = userController.getUser(username, key);
+ ResponseEntity<Object> response = userController.getUser(username, key);
// Analyze
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
@@ -100,7 +100,7 @@ public class UserControllerTest {
doThrow(new IOException()).when(mockUserService).getUser(username);
// Invoke
- ResponseEntity<User> response = userController.getUser(username, key);
+ ResponseEntity<Object> response = userController.getUser(username, key);
// Analyze
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
@@ -119,7 +119,7 @@ public class UserControllerTest {
// Invoke
- ResponseEntity<User> response = userController.createUser(userMap);
+ ResponseEntity<Object> response = userController.createUser(userMap);
// Analyze
assertEquals(HttpStatus.CREATED, response.getStatusCode());
@@ -138,7 +138,7 @@ public class UserControllerTest {
// Invoke
- ResponseEntity<User> response = userController.createUser(userMap);
+ ResponseEntity<Object> response = userController.createUser(userMap);
// Analyze
assertEquals(HttpStatus.CONFLICT, response.getStatusCode());
@@ -154,7 +154,7 @@ public class UserControllerTest {
when(mockUserService.createUser(username, password)).thenThrow(DuplicateKeyException.class);
// Invoke
- ResponseEntity<User> response = userController.createUser(userMap);
+ ResponseEntity<Object> response = userController.createUser(userMap);
// Analyze
assertEquals(HttpStatus.CONFLICT, response.getStatusCode());
@@ -172,7 +172,7 @@ public class UserControllerTest {
// Invoke
- ResponseEntity<User> response = userController.createUser(userMap);
+ ResponseEntity<Object> response = userController.createUser(userMap);
// Analyze
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
@@ -189,7 +189,7 @@ public class UserControllerTest {
when(mockUserService.updateUser(user, username)).thenReturn(user);
// Invoke
- ResponseEntity<User> response = userController.updateUser(user, username, key);
+ ResponseEntity<Object> response = userController.updateUser(user, username, key);
// Analyze
assertEquals(HttpStatus.OK, response.getStatusCode());
@@ -207,7 +207,7 @@ public class UserControllerTest {
when(mockUserService.updateUser(user, username)).thenReturn(null);
// Invoke
- ResponseEntity<User> response = userController.updateUser(user, username, key);
+ ResponseEntity<Object> response = userController.updateUser(user, username, key);
// Analyze
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
@@ -223,7 +223,7 @@ public class UserControllerTest {
doThrow(new IOException()).when(mockUserService).updateUser(user, username);
// Invoke
- ResponseEntity<User> response = userController.updateUser(user, username, key);
+ ResponseEntity<Object> response = userController.updateUser(user, username, key);
// Analyze
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
@@ -237,14 +237,14 @@ public class UserControllerTest {
String key = UserAuth.generate(username).getKey();
// When updateUser is called on the Mock User service, throw a Invalid Parameter exception
// exception
- doThrow(new IllegalAccessException()).when(mockAuthService).authenticate(username, key);
+ doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key);
// Invoke
- ResponseEntity<User> response = userController.updateUser(user, username, key);
+ ResponseEntity<Object> response = userController.updateUser(user, username, key);
// Analyze
- assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
+ assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
}
@Test
@@ -256,7 +256,7 @@ public class UserControllerTest {
when(mockUserService.deleteUser(username)).thenReturn(true);
// Invoke
- ResponseEntity<Boolean> response = userController.deleteUser(username, key);
+ ResponseEntity<Object> response = userController.deleteUser(username, key);
// Analyze
assertEquals(HttpStatus.OK, response.getStatusCode());
@@ -271,7 +271,7 @@ public class UserControllerTest {
when(mockUserService.deleteUser(username)).thenReturn(false);
// Invoke
- ResponseEntity<Boolean> response = userController.deleteUser(username, key);
+ ResponseEntity<Object> response = userController.deleteUser(username, key);
// Analyze
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
@@ -286,7 +286,7 @@ public class UserControllerTest {
doThrow(new IOException()).when(mockUserService).deleteUser(username);
// Invoke
- ResponseEntity<Boolean> response = userController.deleteUser(username, key);
+ ResponseEntity<Object> response = userController.deleteUser(username, key);
// Analyze
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
@@ -298,10 +298,10 @@ public class UserControllerTest {
String username = "Test";
String key = UserAuth.generate(username).getKey();
// When deleteUser is called on the Mock User service, throw an IOException
- doThrow(new IllegalAccessException()).when(mockAuthService).authenticate(username, key);
+ doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key);
// Invoke
- ResponseEntity<Boolean> response = userController.deleteUser(username, key);
+ ResponseEntity<Object> response = userController.deleteUser(username, key);
// Analyze
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java
index 6b4ddfc..67d2b8f 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java
@@ -14,23 +14,30 @@ public class NeedTest {
public void createNeed() {
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
assertNotNull(need);
}
@Test
public void testFields() {
String name = "Jellyfish";
- int id = 0;
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
assertEquals(name, need.getName());
- assertEquals(id, need.getId());
+ assertEquals(0, need.getId());
assertEquals(maxGoal, need.getMaxGoal());
assertEquals(type, need.getType());
}
@@ -38,9 +45,13 @@ public class NeedTest {
@Test
public void testCurrentGoal() {
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
double current = 0.00;
need.setCurrent(current);
@@ -60,9 +71,13 @@ public class NeedTest {
public void testFilterAttributes() {
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
String[] filterAttributes = {"seaweed", "divers", "pacific", "plankton"};
@@ -75,9 +90,13 @@ public class NeedTest {
public void testSetMaxGoal() {
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
double newGoal = 200.00;
need.setMaxGoal(newGoal);
@@ -90,9 +109,13 @@ public class NeedTest {
public void testSetName() {
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
String newName = "TESTINGFUN";
need.setName(newName);
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 55b7f07..ed48f54 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
@@ -52,14 +52,14 @@ public class UserTest {
String expectedName = "Bob";
User user = User.create(expectedName, "pass");
- Need need = new Need("Test", 0, 100, Need.GoalType.MONETARY);
+ Need need = new Need("Test", "", "Atlantis", 0, 100, Need.GoalType.MONETARY, false, "");
Need[] needs = { need };
when(cupboardService.getNeed(0)).thenReturn(need);
user.addToBasket(need);
- Need getNeed = cupboardService.getNeed(user.getNeeds()[0]);
+ Need getNeed = cupboardService.getNeed(user.getBasket()[0]);
assertEquals(needs[0], getNeed);
@@ -71,16 +71,15 @@ public class UserTest {
String expectedName = "Bob";
User user = User.create(expectedName, "pass");
- Need need = new Need("Test", 0, 100, Need.GoalType.MONETARY);
- Need need2 = new Need("Test2", 0, 100, Need.GoalType.MONETARY);
-
+ Need need = new Need("Test", "", "Atlantis", 0, 100, Need.GoalType.MONETARY, false, "");
+ Need need2 = new Need("Test2", "", "Atlantis", 0, 100, Need.GoalType.MONETARY, false, "");
when(cupboardService.getNeed(0)).thenReturn(need2);
user.addToBasket(need);
user.removeBasketNeed(need.getId());
user.addToBasket(need2);
- Need getNeed = cupboardService.getNeed(user.getNeeds()[0]);
+ Need getNeed = cupboardService.getNeed(user.getBasket()[0]);
assertEquals(need2, getNeed);
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java
index f786a8c..76a8b40 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java
@@ -4,6 +4,7 @@ import java.io.File;
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.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -20,44 +21,40 @@ import com.ufund.api.ufundapi.model.Need.GoalType;
@Tag("Persistence-tier")
public class CupboardFileDAOTest {
- private CupboardFileDAO cupboardFileDao;
- private Need[] testNeeds;
- private ObjectMapper mockObjectMapper;
+ private CupboardFileDAO cupboardFileDao;
+ private Need[] testNeeds;
@BeforeEach
- public void setupCupboardFileDao() throws IOException {
- mockObjectMapper = mock(ObjectMapper.class);
- testNeeds = new Need[]{
- new Need("one", 0, 100, Need.GoalType.MONETARY),
- new Need("two", 1, 100, Need.GoalType.MONETARY),
- new Need("three", 2, 100, Need.GoalType.MONETARY)
+ public void setupCupboardFileDao() throws IOException {
+ ObjectMapper mockObjectMapper = mock(ObjectMapper.class);
+ testNeeds = new Need[] {
+ new Need("one", "", "Atlantis", 0, 100, Need.GoalType.MONETARY, false, ""),
+ new Need("two", "", "Atlantis", 1, 100, Need.GoalType.MONETARY, false, ""),
+ new Need("three", "", "Atlantis", 2, 100, Need.GoalType.MONETARY, false, "")
};
- // When the object mapper is supposed to read from the file
- // the mock object mapper will return the hero array above
- when(mockObjectMapper
- .readValue(new File("doesnt_matter.txt"),Need[].class))
- .thenReturn(testNeeds);
- cupboardFileDao = new CupboardFileDAO("doesnt_matter.txt",mockObjectMapper);
- }
-
- @Test
- public void getNeedsTest() {
- Need[] needs = cupboardFileDao.getNeeds();
- assertEquals(needs.length,testNeeds.length);
+ // When the object mapper is supposed to read from the file
+ // the mock object mapper will return the hero array above
+ when(mockObjectMapper.readValue(new File("doesnt_matter.txt"), Need[].class)).thenReturn(testNeeds);
+ cupboardFileDao = new CupboardFileDAO("doesnt_matter.txt", mockObjectMapper);
+ }
+
+ @Test
+ public void getNeedsTest() {
+ Need[] needs = cupboardFileDao.getNeeds();
+ assertEquals(needs.length, testNeeds.length);
assertEquals(needs[0].getName(), testNeeds[0].getName());
- }
+ }
- @Test
- public void getNeedTest() {
+ @Test
+ public void getNeedTest() {
Need need1 = cupboardFileDao.getNeed(0);
-
+
assertEquals(testNeeds[0], need1);
- }
+ }
@Test
public void createNeedTest() throws IOException {
- Need newNeed = new Need("sea urchin hats", 3, 100, GoalType.PHYSICAL);
-
+ Need newNeed = new Need("sea urchin hats", "", "Atlantis", 100, GoalType.PHYSICAL, false, "");
Need actualNeed = cupboardFileDao.addNeed(newNeed);
@@ -79,16 +76,37 @@ public class CupboardFileDAOTest {
}
@Test
+ public void deleteNeedTestFail() throws IOException {
+ Need undeletedNeed = cupboardFileDao.getNeed(0);
+ assertNotNull(undeletedNeed);
+
+ boolean nullNeed = cupboardFileDao.deleteNeed(20);
+ assertFalse(nullNeed);
+ }
+
+ @Test
public void updateNeedTest() throws IOException {
Need[] needs = cupboardFileDao.getNeeds();
Need unupdatedNeed = needs[needs.length - 1];
assertNotNull(unupdatedNeed);
- Need updatedNeed = new Need("sequin sea urchin hats", 2, 100, GoalType.PHYSICAL);
+ Need updatedNeed = new Need("sequin sea urchin hats", "", "Atlantis", 100, GoalType.PHYSICAL, false, "");
Need actualNeed = cupboardFileDao.updateNeed(updatedNeed);
assertEquals(actualNeed, updatedNeed);
assertNotEquals(actualNeed, unupdatedNeed);
}
+ @Test
+ public void updateNeedTestFail() throws IOException {
+ Need[] needs = cupboardFileDao.getNeeds();
+ Need unupdatedNeed = needs[needs.length - 1];
+ assertNotNull(unupdatedNeed);
+
+ Need updatedNeed = new Need("sequin sea urchin hats", "", "Atlantis", 5, 100, GoalType.PHYSICAL, false, "");
+
+ Need actualNeed = cupboardFileDao.updateNeed(updatedNeed);
+ assertNull(actualNeed);
+ }
+
}
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java
index f7db747..a4842c5 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java
@@ -2,6 +2,7 @@ package com.ufund.api.ufundapi.persistence;
import java.io.File;
import java.io.IOException;
+import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -18,22 +19,21 @@ import com.ufund.api.ufundapi.model.UserAuth;
public class UserAuthFileDAOTest {
private UserAuthFIleDAO userAuthFIleDAO;
- private ObjectMapper mockObjectMapper;
private UserAuth[] userAuths;
@BeforeEach
public void setupUserAuthFileDAO() throws IOException {
- mockObjectMapper = mock(ObjectMapper.class);
+ ObjectMapper mockObjectMapper = mock(ObjectMapper.class);
userAuths = new UserAuth[]{
- new UserAuth("123", "Phil", null),
- new UserAuth("456", "Bob", null),
- new UserAuth("789", "Steve", null)
+ new UserAuth("123", "Phil", LocalDateTime.MAX),
+ new UserAuth("456", "Bob", LocalDateTime.MAX),
+ new UserAuth("789", "Steve", LocalDateTime.MAX)
};
// When the object mapper is supposed to read from the file
// the mock object mapper will return the hero array above
when(mockObjectMapper
- .readValue(new File("doesnt_matter.txt"),UserAuth[].class))
+ .readValue(new File("doesnt_matter.txt"),UserAuth[].class))
.thenReturn(userAuths);
userAuthFIleDAO = new UserAuthFIleDAO(mockObjectMapper, "doesnt_matter.txt");
}
@@ -43,18 +43,18 @@ public class UserAuthFileDAOTest {
String key = "123";
UserAuth auth = userAuthFIleDAO.getUserAuth(key);
- assertEquals(auth, userAuths[0]);
+ assertEquals(userAuths[0], auth);
}
@Test
- public void addUserAuthTest() throws IOException {
+ public void addUserAuthTest() {
UserAuth auth = new UserAuth("999", "Fish", null);
assertDoesNotThrow(() -> userAuthFIleDAO.addUserAuth(auth));
}
@Test
- public void removeUserAuthTest() throws IOException {
+ public void removeUserAuthTest() {
String key = "123";
assertDoesNotThrow(() -> userAuthFIleDAO.removeUserAuth(key));
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java
index 9361188..2ee0fc0 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java
@@ -39,6 +39,24 @@ public class UserFileDAOTest {
userFileDAO = new UserFileDAO("doesnt_matter.txt",mockObjectMapper);
}
+ @Test
+ public void addUsersTest() throws IOException {
+ User user = User.create("Name", "Pass");
+
+ User addedUser = userFileDAO.addUser(user);
+
+ assertEquals(addedUser, user);
+ }
+
+ @Test
+ public void addUsersTestFail() throws IOException {
+ User user = User.create("bob", "test");
+
+ User existingUser = userFileDAO.addUser(user);
+
+ assertEquals(existingUser, testUsers[0]);
+ }
+
@Test
public void getUsersTest() {
User[] users = userFileDAO.getUsers();
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java
index 55cf7a9..4f58b12 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java
@@ -11,7 +11,6 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import com.ufund.api.ufundapi.DuplicateKeyException;
import com.ufund.api.ufundapi.model.User;
import com.ufund.api.ufundapi.model.UserAuth;
import com.ufund.api.ufundapi.persistence.UserAuthDAO;
@@ -41,39 +40,39 @@ public class AuthServiceTest {
}
@Test
- public void testAuthenticate() throws IOException {
+ public void testKeyIsValid() throws IOException {
// Mock
when(mockAuthDAO.getUserAuth(key)).thenReturn(new UserAuth(key, username, null));
when(mockUserService.getUser(username)).thenReturn(user);
// Analyze
- assertDoesNotThrow(() -> authService.authenticate(username, key));
+ assertDoesNotThrow(() -> authService.keyHasAccessToUser(username, key));
}
-// @Test
-// public void testAuthenticateMismatchName() throws IOException {
-// // Mock
-// when(mockAuthDAO.getUserAuth(key)).thenReturn(new UserAuth(key, "EvilFish", null));
-// when(mockUserService.getUser("EvilFish")).thenReturn(user);
-//
-// // Analyze
-// assertThrows(IllegalAccessException.class, () -> authService.authenticate(username, key));
-//
-// }
+ @Test
+ public void testKeyIsValidMismatchName() throws IOException {
+ // Mock
+ when(mockAuthDAO.getUserAuth(key)).thenReturn(new UserAuth(key, "EvilFish", null));
+ when(mockUserService.getUser("EvilFish")).thenReturn(user);
+
+ // Analyze
+ assertThrows(IllegalAccessException.class, () -> authService.keyHasAccessToUser(username, key));
+
+ }
@Test
- public void testAuthenticateMissingUserAuth() throws IOException {
+ public void testKeyIsValidMissingUserAuth() throws IOException {
// Mock
when(mockAuthDAO.getUserAuth(key)).thenReturn(null);
// Analyze
- assertThrows(IllegalAccessException.class, () -> authService.authenticate(username, key));
+ assertThrows(IllegalAccessException.class, () -> authService.keyHasAccessToUser(username, key));
}
@Test
- public void testLogin() throws IOException, DuplicateKeyException, IllegalAccessException {
+ public void testLogin() throws IOException {
// Mock
when(mockUserService.getUser(username)).thenReturn(user);
@@ -83,7 +82,7 @@ public class AuthServiceTest {
}
@Test
- public void testLoginNullUser() throws IOException, DuplicateKeyException, IllegalAccessException {
+ public void testLoginNullUser() throws IOException {
// Mock
when(mockUserService.getUser(username)).thenReturn(null);
@@ -92,7 +91,7 @@ public class AuthServiceTest {
}
@Test
- public void testLoginMismatchPasswords() throws IOException, DuplicateKeyException, IllegalAccessException {
+ public void testLoginMismatchPasswords() throws IOException {
// Mock
when(mockUserService.getUser(username)).thenReturn(User.create(username, "fries"));
@@ -101,7 +100,7 @@ public class AuthServiceTest {
}
@Test
- public void testLogout() throws IOException, DuplicateKeyException, IllegalAccessException {
+ public void testLogout() {
// Analyze
assertDoesNotThrow(() -> authService.logout(key));
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java
index 99ca23c..2a3c8ee 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java
@@ -27,7 +27,8 @@ public class CupboardServiceTest {
@BeforeEach
public void setupCupboardService() {
mockCupboardDAO = mock(CupboardDAO.class);
- cupboardService = new CupboardService(mockCupboardDAO);
+ AuthService mockAuthService = mock(AuthService.class);
+ cupboardService = new CupboardService(mockAuthService, mockCupboardDAO);
}
@@ -35,16 +36,20 @@ public class CupboardServiceTest {
public void testCreateNeed() throws IOException, DuplicateKeyException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
// When the same id is passed in, our mock User DAO will return the User object
when(mockCupboardDAO.addNeed(any())).thenReturn(need);
when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]);
// Invoke
- Need response = cupboardService.createNeed(name, maxGoal, type);
+ Need response = cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description);
// Analyze
assertNotNull(response);
@@ -52,12 +57,16 @@ public class CupboardServiceTest {
}
@Test
- public void testCreateNeedBadGoal() throws IOException, DuplicateKeyException {
+ public void testCreateNeedBadGoal() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = -100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = -100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
// When the same id is passed in, our mock User DAO will return the User object
when(mockCupboardDAO.addNeed(any())).thenReturn(need);
@@ -67,18 +76,21 @@ public class CupboardServiceTest {
// Need response = cupboardService.createNeed(name, maxGoal, type);
// Analyze
- assertThrows(IllegalArgumentException.class, () -> {
- cupboardService.createNeed(name, maxGoal, type);
- });
+ assertThrows(IllegalArgumentException.class, () ->
+ cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description));
}
@Test
- public void testCreateNeedDuplicate() throws IOException, DuplicateKeyException {
+ public void testCreateNeedDuplicate() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
Need[] needs = { need };
// When the same id is passed in, our mock User DAO will return the User object
@@ -89,18 +101,21 @@ public class CupboardServiceTest {
// Need response = cupboardService.createNeed(name, maxGoal, type);
// Analyze
- assertThrows(DuplicateKeyException.class, () -> {
- cupboardService.createNeed(name, maxGoal, type);
- });
+ assertThrows(DuplicateKeyException.class, () ->
+ cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description));
}
@Test
- public void testSearchNeeds() throws IOException, DuplicateKeyException {
+ public void testSearchNeeds() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
Need[] needs = { need };
// When the same id is passed in, our mock User DAO will return the User object
@@ -115,12 +130,16 @@ public class CupboardServiceTest {
}
@Test
- public void testSearchNeedsFail() throws IOException, DuplicateKeyException {
+ public void testSearchNeedsFail() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
Need[] needs = { need };
// When the same id is passed in, our mock User DAO will return the User object
@@ -134,59 +153,68 @@ public class CupboardServiceTest {
}
@Test
- public void testGetNeed() throws IOException, DuplicateKeyException {
+ public void testGetNeed() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- int id = 0;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
// When the same id is passed in, our mock User DAO will return the User object
- when(mockCupboardDAO.getNeed(id)).thenReturn(need);
+ when(mockCupboardDAO.getNeed(0)).thenReturn(need);
// Invoke
- Need response = cupboardService.getNeed(id);
+ Need response = cupboardService.getNeed(need.getId());
// Analyze
assertEquals(need, response);
}
@Test
- public void testUpdateNeed() throws IOException, DuplicateKeyException {
+ public void testUpdateNeed() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- int id = 0;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
- Need newNeed = new Need("Octopus", type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
+ Need newNeed = new Need("Octopus", image, location, maxGoal, type, urgent, description);
// When the same id is passed in, our mock User DAO will return the User object
when(mockCupboardDAO.updateNeed(any())).thenReturn(newNeed);
// Invoke
- Need response = cupboardService.updateNeed(newNeed, id);
+ Need response = cupboardService.updateNeed(newNeed, need.getId());
// Analyze
assertEquals(newNeed, response);
}
@Test
- public void testDeleteNeed() throws IOException, DuplicateKeyException {
+ public void testDeleteNeed() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- int id = 0;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
// When the same id is passed in, our mock User DAO will return the User object
- when(mockCupboardDAO.deleteNeed(id)).thenReturn(true);
+ when(mockCupboardDAO.deleteNeed(0)).thenReturn(true);
when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]);
// Invoke
- boolean response = cupboardService.deleteNeed(id);
+ boolean response = cupboardService.deleteNeed(need.getId());
Need[] responseNeeds = cupboardService.getNeeds();
// Analyze
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 e57c5a3..5adabf1 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,13 +19,12 @@ public class UserServiceTest {
private UserService userService;
private UserDAO mockUserDAO;
- private CupboardService mockCupboardService;
@BeforeEach
public void setupUserService() {
mockUserDAO = mock(UserDAO.class);
- mockCupboardService = mock(CupboardService.class);
+ CupboardService mockCupboardService = mock(CupboardService.class);
userService = new UserService(mockUserDAO, mockCupboardService);
}
@@ -47,7 +46,7 @@ public class UserServiceTest {
}
@Test
- public void testCreateUserDuplicate() throws IOException, DuplicateKeyException {
+ public void testCreateUserDuplicate() throws IOException {
// Setup
String username = "Jelly";
String password = "Fish";
@@ -62,7 +61,7 @@ public class UserServiceTest {
}
@Test
- public void testGetUser() throws IOException, DuplicateKeyException {
+ public void testGetUser() throws IOException {
// Setup
String username = "Jelly";
String password = "Fish";
@@ -76,7 +75,7 @@ public class UserServiceTest {
}
@Test
- public void testUpdateUser() throws IOException, DuplicateKeyException {
+ public void testUpdateUser() throws IOException {
// Setup
String username = "Jelly";
String password = "Fish";
@@ -94,7 +93,7 @@ public class UserServiceTest {
}
@Test
- public void testUpdateUserDifferentUsernames() throws IOException, DuplicateKeyException {
+ public void testUpdateUserDifferentUsernames() throws IOException {
// Setup
String username = "Jelly";
String password = "Fish";
@@ -112,7 +111,7 @@ public class UserServiceTest {
}
@Test
- public void testDeleteUser() throws IOException, DuplicateKeyException {
+ public void testDeleteUser() throws IOException {
// Setup
String username = "Jelly";
String password = "Fish";
diff --git a/ufund-ui/public/jf.png b/ufund-ui/public/jf.png
new file mode 100644
index 0000000..bbf95d5
--- /dev/null
+++ b/ufund-ui/public/jf.png
Binary files differ
diff --git a/ufund-ui/src/app/app-routing.module.ts b/ufund-ui/src/app/app-routing.module.ts
index 4b76654..89b6f67 100644
--- a/ufund-ui/src/app/app-routing.module.ts
+++ b/ufund-ui/src/app/app-routing.module.ts
@@ -6,14 +6,16 @@ import {LoginComponent} from './components/login/login.component';
import {HomePageComponent} from './components/home-page/home-page.component';
import {FundingBasketComponent} from './components/funding-basket/funding-basket.component';
import {NeedPageComponent} from './components/need-page/need-page.component';
+import {SignupComponent} from './components/signup/signup.component';
const routes: Routes = [
- {path: '', component: HomePageComponent},
- {path: 'login', component: LoginComponent},
- {path: 'cupboard', component: CupboardComponent},
- {path: 'dashboard', component: DashboardComponent},
- {path: 'basket', component: FundingBasketComponent},
- {path: 'need/:id', component: NeedPageComponent}
+ { path: '', component: HomePageComponent, title: "Home | JS" },
+ { path: 'login', component: LoginComponent, title: "Login | JS" },
+ { path: 'cupboard', component: CupboardComponent, title: "Cupboard | JS" },
+ { path: 'dashboard', component: DashboardComponent, title: "Dashboard | JS" },
+ { path: 'basket', component: FundingBasketComponent, title: "Basket | JS" },
+ { path: 'need/:id', component: NeedPageComponent, title: "Need | JS" },
+ { path: 'signup', component: SignupComponent, title: "Signup | JS" },
];
@NgModule({
diff --git a/ufund-ui/src/app/app.component.css b/ufund-ui/src/app/app.component.css
index e69de29..f4ed668 100644
--- a/ufund-ui/src/app/app.component.css
+++ b/ufund-ui/src/app/app.component.css
@@ -0,0 +1,70 @@
+:host {
+ display: flex;
+ flex-direction: column;
+ height: 100%;
+}
+
+#header {
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+ /*border-bottom: light-dark(#d3d3d3, black) solid 1px;*/
+ padding: 15px 20px;
+ /*background-color: light-dark(#f5f5f5, #2e2e2e);*/
+ z-index: 2;
+
+ h1 {
+ padding: 0;
+ margin: 0;
+ font-weight: 500;
+ /*text-decoration: none;*/
+ text-transform: uppercase;
+ font-size: 16pt;
+ letter-spacing: .5px;
+ }
+
+ div {
+ display: flex;
+ align-items: center;
+ gap: 20px;
+ }
+
+ /*div:has(a:hover) a {*/
+ /* color: light-dark(black, rgba(255, 255, 255, 0.5));*/
+ /*}*/
+
+ a {
+ color: light-dark(black, white);
+ text-decoration: none;
+ }
+
+ a:hover {
+ text-decoration: underline;
+ }
+
+ /*a {*/
+ /* display: block;*/
+ /* position: relative;*/
+ /* padding: 0.1em 0;*/
+ /*}*/
+
+ /*a::after {*/
+ /* content: '';*/
+ /* position: absolute;*/
+ /* bottom: 4px;*/
+ /* left: 0;*/
+ /* width: 100%;*/
+ /* height: 0.03em;*/
+ /* background-color: white;*/
+ /* opacity: 0;*/
+ /* transition: opacity 300ms, transform 300ms;*/
+ /*}*/
+
+ /*a:hover::after,*/
+ /*a:focus::after {*/
+ /* opacity: 1;*/
+ /* transform: translate3d(0, 0.2em, 0);*/
+ /*}*/
+
+
+}
diff --git a/ufund-ui/src/app/app.component.html b/ufund-ui/src/app/app.component.html
index a490237..959eada 100644
--- a/ufund-ui/src/app/app.component.html
+++ b/ufund-ui/src/app/app.component.html
@@ -1,6 +1,17 @@
-
-<h1>jelly solutions</h1>
-<span>{{currentUser$ | async}}</span> <br> <button *ngIf="currentUser$.value != 'Logged out.'" (click)="reloadPage()"> Log Out</button>
-<hr>
+<div id="header">
+ <div>
+ <a routerLink="/">
+ <h1>Jelly Solutions</h1>
+ </a>
+ </div>
+ <div>
+ <a routerLink="/dashboard">Dashboard</a>
+ <a routerLink="/cupboard">Cupboard</a>
+ <a routerLink="/basket">Basket</a>
+<!-- <span>{{currentUser$ | async}}</span>-->
+ <button *ngIf="currentUser | async" (click)="logout()"> Log Out</button>
+ <button *ngIf="!(currentUser | async)" (click)="login()"> Log In</button>
+ </div>
+</div>
<router-outlet />
diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts
index 7dc8ffb..2f98334 100644
--- a/ufund-ui/src/app/app.component.ts
+++ b/ufund-ui/src/app/app.component.ts
@@ -1,7 +1,10 @@
-import {Component, OnInit, Inject} from '@angular/core';
-import {UsersService} from './services/users.service';
+import {Component, OnInit, Inject, ViewContainerRef} from '@angular/core';
import {BehaviorSubject} from 'rxjs';
import { DOCUMENT } from '@angular/common';
+import {AuthService} from './services/auth.service';
+import {ToastsService} from './services/toasts.service';
+import {User} from './models/User';
+import {ActivatedRoute, Router} from '@angular/router';
@Component({
selector: 'app-root',
@@ -11,24 +14,38 @@ import { DOCUMENT } from '@angular/common';
})
export class AppComponent implements OnInit {
// title = 'ufund-ui';
- currentUser$: BehaviorSubject<string> = new BehaviorSubject<string>("Logged out.");
+ currentUser?: BehaviorSubject<User | null>;
constructor(
- private userService: UsersService,
+ private authService: AuthService,
+ private router: Router,
+ private route: ActivatedRoute,
+ protected toastService: ToastsService,
+ private viewContainerRef: ViewContainerRef,
@Inject(DOCUMENT) private document: Document
) {}
reloadPage() {
this.document.defaultView?.location.reload();
- }
+ }
ngOnInit() {
- this.userService.getCurrentUserSubject().subscribe(r => {
- this.currentUser$?.next(r
- ? "Logged in as " + r.username
- : "Logged out."
- )
- })
+ this.toastService.setRootViewContainerRef(this.viewContainerRef)
+ this.currentUser = this.authService.getCurrentUserSubject()
+ let data = localStorage.getItem("credential");
+ if (data) {
+ let dataParsed = JSON.parse(data)
+ this.authService.restoreLogin(dataParsed.username, dataParsed.key)
+ console.log("Key found", dataParsed.key)
+ }
+ }
+
+ login() {
+ this.router.navigate(['/login'], {queryParams: {redir: this.router.url}});
}
+ logout() {
+ localStorage.removeItem("credential")
+ location.reload()
+ }
}
diff --git a/ufund-ui/src/app/app.module.ts b/ufund-ui/src/app/app.module.ts
index 9f525fe..16455be 100644
--- a/ufund-ui/src/app/app.module.ts
+++ b/ufund-ui/src/app/app.module.ts
@@ -14,6 +14,10 @@ import {RouterLink, RouterLinkActive, RouterOutlet} from '@angular/router';
import {DashboardComponent} from './components/dashboard/dashboard.component';
import {CommonModule} from '@angular/common';
import {LoginComponent} from './components/login/login.component';
+import { MiniNeedListComponent } from './components/mini-need-list/mini-need-list.component';
+import { SignupComponent } from './components/signup/signup.component';
+import { ToastComponent } from './components/toast/toast.component';
+import { NeedEditComponent } from './components/need-edit/need-edit.component';
@NgModule({
declarations: [
@@ -25,6 +29,10 @@ import {LoginComponent} from './components/login/login.component';
NeedListComponent,
DashboardComponent,
LoginComponent,
+ SignupComponent,
+ MiniNeedListComponent,
+ ToastComponent,
+ NeedEditComponent,
],
imports: [
BrowserModule,
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css
index fe4971a..e45d929 100644
--- a/ufund-ui/src/app/components/cupboard/cupboard.component.css
+++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css
@@ -1,21 +1,54 @@
:host {
- display: block;
- border: 2px solid #000;
- border-radius: 5px;
- padding: 10px 20px;
+ display: flex;
+ justify-content: center;
}
-#menu, #create-form, #delete-form, #update-form {
- background-color: #d9d9d9;
+#box {
+ width: 800px;
+ display: flex;
+ flex-direction: column;
+}
+
+#menu {
+ display: flex;
+
+ margin: 10px;
+
+}
+
+.tab, .selected-tab {
+ background-color: lightgray;
+ border: 3px solid #000;
+ border-top-left-radius: 5px;
+ border-top-right-radius: 5px;
+ margin-right: 5px;
+ border-bottom: 0;
+}
+
+.selected-tab {
+ background-color: white;
+}
+
+#create-form, #delete-form, #update-form {
+ background-color: #3a3a3a;
padding: 10px 20px 20px 20px;
border: 2px solid #000;
- border-radius: 5px;
- width: 20%;
+ border-radius: 5px;
visibility: visible;
-
+ /*position: absolute;*/
}
-#create-button {
- padding: 10px 20px;
-
-} \ No newline at end of file
+#header {
+ display: flex;
+ gap: 20px;
+ align-items: center;
+
+ h1 {
+ display: inline;
+ width: min-content;
+ }
+
+ button {
+ margin-top: 3px;
+ }
+}
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html
index 0d64475..37954bb 100644
--- a/ufund-ui/src/app/components/cupboard/cupboard.component.html
+++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html
@@ -1,50 +1,38 @@
-<h1> Cupboard </h1>
-<h2 *ngIf="isManager()" > Admin View </h2>
-<div id="menu" *ngIf="isManager()">
- <button (click)="opencreate()">Create new Need</button>
- <button (click)="openupdate()">Update existing Need</button>
+<div id="box">
+ <div id="header">
+ <h1> Cupboard </h1>
+ <button *ngIf="isManager()" class="button2" (click)="this.selectForm('create')"><span class="icon">add</span>Create Need</button>
+ </div>
+ <app-need-list (currentNeed) = populateForm($event) #needList></app-need-list>
</div>
-<div id="create-form">
- <h1> Create a new need </h1>
- <form #cupboardForm="ngForm" (ngSubmit)="submit(cupboardForm.value)">
- <label>Name:</label><br>
- <input type="text" name="name" ngModel><br>
- <label>Max Goal:</label><br>
- <input type="number" name="maxGoal" ngModel><br>
- <label>Type</label><br>
- <input type="radio" name="type" value="MONETARY" ngModel>
- <label>Monetary</label><br>
- <input type="radio" name="type" value="PHYSICAL" ngModel>
- <label>Physical</label><br>
- <input type="submit" value="Submit">
- </form>
- <button (click)="back()">Close</button>
- <span *ngIf="statusText">‼️{{statusText | async}}</span>
+<ng-template [ngIf]="isManager()" >
+<div>
+ <app-need-edit *ngIf="selectedForm === 'update'" [selectedNeed]="selectedNeed" (refreshNeedList)="needList.refresh()"></app-need-edit>
+ <div>
+ <div id="create-form" *ngIf="selectedForm === 'create'">
+ <h1> Create Need </h1>
+ <form #cupboardForm="ngForm" (ngSubmit)="submit(cupboardForm.value)">
+ <label>Name:</label><br>
+ <input type="text" name="name" ngModel><br>
+ <label>Image:</label><br>
+ <input type="text" name="image" ngModel><br>
+ <label>Location:</label><br>
+ <input type="text" name="location" ngModel><br>
+ <label>Max Goal:</label><br>
+ <input type="number" name="maxGoal" ngModel><br>
+ <label>Type</label><br>
+ <input type="radio" name="type" value="MONETARY" ngModel>
+ <label>Monetary</label><br>
+ <input type="radio" name="type" value="PHYSICAL" ngModel>
+ <label>Physical</label><br>
+ <input type="checkbox" name="urgent" value="false" ngModel>
+ <label>Urgent</label><br>
+ <label>Description</label><br>
+ <textarea name="description"></textarea><br>
+ <input type="submit" value="Submit">
+ </form>
+ </div>
+ </div>
</div>
-<div id="update-form">
- <h1> Update a need </h1>
- <label>Needs:</label><br>
- <form #updateForm="ngForm" (ngSubmit)="update(updateForm.value)">
- <div *ngFor="let need of needs">
-
- <input type="radio" name="id" [value]=need.id [(ngModel)]="selectedNeedId" (change)="populateForm(need)">
- <label name="template">{{need.name}}</label><br>
- </div>
- <label>Name:</label><br>
- <input type="text" name="name" [(ngModel)]="selectedNeed.name"><br>
- <label>Max Goal:</label><br>
- <input type="number" name="maxGoal" [(ngModel)]="selectedNeed.maxGoal"><br>
- <label>Type</label><br>
- <input type="radio" name="type" value="MONETARY" [(ngModel)]="selectedNeed.type">
- <label>Monetary</label><br>
- <input type="radio" name="type" value="PHYSICAL" [(ngModel)]="selectedNeed.type">
- <label>Physical</label><br>
- <input type="submit" value="Submit">
- </form>
- <button (click)="back()">Close</button>
- <span *ngIf="statusText">{{statusText | async}}</span>
-
-</div>
-<hr>
-<app-need-list #needList></app-need-list>
+</ng-template>
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
index 24b3e2d..2230cd3 100644
--- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts
+++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
@@ -1,10 +1,11 @@
-import { Component, OnInit, ViewChild } from '@angular/core';
+import {Component, OnInit, ViewChild} from '@angular/core';
import { CupboardService } from '../../services/cupboard.service';
-import { UsersService } from '../../services/users.service';
import { Need, GoalType } from '../../models/Need';
import { userType } from '../../models/User';
-import { BehaviorSubject, catchError, of } from 'rxjs';
+import { catchError, of } from 'rxjs';
import { NeedListComponent } from '../need-list/need-list.component';
+import {AuthService} from '../../services/auth.service';
+import {ToastsService, ToastType} from '../../services/toasts.service';
@Component({
selector: 'app-cupboard',
@@ -15,18 +16,18 @@ import { NeedListComponent } from '../need-list/need-list.component';
export class CupboardComponent implements OnInit {
- protected statusText = new BehaviorSubject("")
-
+ selectedForm?: string = undefined;
needs: any;
@ViewChild("needList") needList?: NeedListComponent
- constructor(private cupboardService: CupboardService, private usersService: UsersService) { }
+ constructor(
+ private cupboardService: CupboardService,
+ private authService: AuthService,
+ private toastService: ToastsService
+ ) {}
ngOnInit(): void {
this.cupboardService.getNeeds().subscribe(n => this.needs = n);
- this.close();
- this.openmenu();
-
if (this.isManager()) {
console.log("Admin view of Cupboard");
} else {
@@ -36,117 +37,74 @@ export class CupboardComponent implements OnInit {
selectedNeed: any = {
name: '',
+ location:'',
id: null,
maxGoal: null,
- type: ''
+ type: '',
+ urgent: false
};
selectedNeedId: number | null = null;
+ searchResults: any[] = [];
- private hideElement(element: any) {
- if (element) {
- element.style.visibility = 'hidden';
- element.style.position = 'absolute';
+ selectForm(name: string) {
+ //get search results from the need list
+ if (this.needList) {
+ this.searchResults = this.needList.searchResults;
}
- }
+ console.log(this.searchResults)
+ this.selectedForm = name;
+ if (name == 'update') {
+ if (this.searchResults) {
+ this.searchResults.forEach((element: any) => {
+ console.log(element)
+ });
+ }
- private showElement(element: any) {
- if (element) {
- element.style.visibility = 'visible';
- element.style.position = 'relative';
}
}
- openmenu() {
- const menuElement = document.getElementById('menu');
- this.showElement(menuElement);
- }
-
- opencreate() {
- this.close();
- this.showElement(document.getElementById('create-form'));
- }
-
- openupdate() {
- this.close();
- this.showElement(document.getElementById('update-form'));
- }
-
- back() {
- 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'));
+ async updateSearchResults() {
+ if (this.needList) {
+ while (this.selectedForm == 'update') {
+ this.searchResults = this.needList.searchResults
+ await new Promise(resolve => setTimeout(resolve, 100));
+ }
+ }
}
populateForm(need: any): void {
+ this.selectForm('update');
this.selectedNeed = { ...need };
}
isManager() {
- const type = this.usersService.getCurrentUser()?.type;
+ const type = this.authService.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) => {
- 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,
+ image: form.image,
+ location: form.location,
id: 0,
maxGoal: form.maxGoal,
type: form.type,
+ urgent: form.urgent ? true : false,
filterAttributes: [],
- current: 0
+ current: 0,
+ description: form.description
};
console.log("need:", need);
console.log("form submitted. creating need: ", need);
this.cupboardService.createNeed(need)
- .pipe(catchError((ex, r) => {
+ .pipe(catchError((ex, _) => {
if (ex.status == 500) {
- this.statusText.next("Fields cannot be blank");
+ this.toastService.sendToast(ToastType.ERROR, "Fields cannot be blank");
} else if (ex.status == 400) {
- this.statusText.next("Goal must be greater than 0");
+ this.toastService.sendToast(ToastType.ERROR, ex.error);
} else {
- this.statusText.next("Error on creating need");
+ this.toastService.sendToast(ToastType.ERROR, "Error on creating need");
}
return of()
}))
@@ -167,48 +125,3 @@ export class CupboardComponent implements OnInit {
}
}
-
-let friendlyHttpStatus: { [key: number]: string } = {
- 200: 'OK',
- 201: 'Created',
- 202: 'Accepted',
- 203: 'Non-Authoritative Information',
- 204: 'No Content',
- 205: 'Reset Content',
- 206: 'Partial Content',
- 300: 'Multiple Choices',
- 301: 'Moved Permanently',
- 302: 'Found',
- 303: 'See Other',
- 304: 'Not Modified',
- 305: 'Use Proxy',
- 306: 'Unused',
- 307: 'Temporary Redirect',
- 400: 'Bad Request',
- 401: 'Unauthorized',
- 402: 'Payment Required',
- 403: 'Forbidden',
- 404: 'Not Found',
- 405: 'Method Not Allowed',
- 406: 'Not Acceptable',
- 407: 'Proxy Authentication Required',
- 408: 'Request Timeout',
- 409: 'Conflict',
- 410: 'Gone',
- 411: 'Length Required',
- 412: 'Precondition Required',
- 413: 'Request Entry Too Large',
- 414: 'Request-URI Too Long',
- 415: 'Unsupported Media Type',
- 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',
- 502: 'Bad Gateway',
- 503: 'Service Unavailable',
- 504: 'Gateway Timeout',
- 505: 'HTTP Version Not Supported',
-};
diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.css b/ufund-ui/src/app/components/dashboard/dashboard.component.css
index e69de29..78a69ba 100644
--- a/ufund-ui/src/app/components/dashboard/dashboard.component.css
+++ b/ufund-ui/src/app/components/dashboard/dashboard.component.css
@@ -0,0 +1,7 @@
+:host {
+ display: flex;
+ flex-direction: column;
+ width: 1000px;
+ align-self: center;
+ gap: 20px
+}
diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.html b/ufund-ui/src/app/components/dashboard/dashboard.component.html
index a1151b7..6a95ecd 100644
--- a/ufund-ui/src/app/components/dashboard/dashboard.component.html
+++ b/ufund-ui/src/app/components/dashboard/dashboard.component.html
@@ -1,4 +1,5 @@
-<h1>Dashboard</h1>
-<app-cupboard></app-cupboard>
-<app-funding-basket *ngIf="!isManager()"></app-funding-basket> \ No newline at end of file
+<h1>Your Dashboard</h1>
+<app-mini-need-list [needList]="topNeeds" jtitle="Top needs" url="/cupboard"/>
+<app-mini-need-list [needList]="almostThere" jtitle="Almost there" url="/cupboard"/>
+<app-mini-need-list [needList]="inBasket" jtitle="In your basket" url="/basket"/>
diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.ts b/ufund-ui/src/app/components/dashboard/dashboard.component.ts
index b9faefa..c94b5c6 100644
--- a/ufund-ui/src/app/components/dashboard/dashboard.component.ts
+++ b/ufund-ui/src/app/components/dashboard/dashboard.component.ts
@@ -1,21 +1,45 @@
-import { Component } from '@angular/core';
-import { UsersService } from '../../services/users.service';
-import { userType } from '../../models/User';
+import {Component, OnInit} from '@angular/core';
+import {AuthService} from '../../services/auth.service';
+import {Router} from '@angular/router';
+import {Need} from '../../models/Need';
+import {CupboardService} from '../../services/cupboard.service';
+import {firstValueFrom} from 'rxjs';
+import {UsersService} from '../../services/users.service';
@Component({
- selector: 'app-dashboard',
- standalone: false,
- templateUrl: './dashboard.component.html',
- styleUrl: './dashboard.component.css'
+ selector: 'app-dashboard',
+ standalone: false,
+ templateUrl: './dashboard.component.html',
+ styleUrl: './dashboard.component.css'
})
-export class DashboardComponent {
+export class DashboardComponent implements OnInit{
+
+ topNeeds?: Need[]
+ almostThere?: Need[]
+ inBasket?: Need[]
+
constructor(
- protected usersService: UsersService,
+ protected authService: AuthService,
+ protected router: Router,
+ protected cupboardService: CupboardService,
+ protected userService: UsersService
) {}
- isManager() {
- const type = this.usersService.getCurrentUser()?.type;
- return type === ("MANAGER" as unknown as userType);
- }
+ ngOnInit() {
+ let user = this.authService.getCurrentUser()
+ if(!localStorage.getItem("credential") && !user) {
+ this.router.navigate(['/login'])
+ return
+ }
+
+ firstValueFrom(this.cupboardService.getNeeds()).then(r => {
+ this.topNeeds = r.sort((a, b) => b.current - a.current)
+ this.almostThere = r.sort((a, b) => a.current/a.maxGoal - b.current/b.maxGoal)
+ })
+
+ this.userService.getBasket().subscribe(r => {
+ this.inBasket = r;
+ })
+ }
}
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 3dec496..c46ef57 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
@@ -1,7 +1,82 @@
-td, p {
- border: 2px solid #000;
+:host {
+ display: flex;
+ justify-content: center;
+}
+
+#box {
+ display: flex;
+ width: 800px;
+ flex-direction: column;
+ gap: 10px;
+}
+
+.needEntry {
+ background-color: #2e2e2e;
+ display: flex;
+ flex-direction: column;
border-radius: 5px;
- padding: 5px;
- margin: 5px;
+}
+
+#needList {
+ display: flex;
+ flex-direction: column;
+ gap: 15px;
+ max-width: 1000px;
+}
+
+.needName {
+ font-weight: bold;
+}
+
+.needType {
+ text-transform: uppercase;
+ font-size: 10pt;
+}
+
+.split {
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+
+
+ .left {
+ display: flex;
+ flex-direction: column;
+ }
-} \ No newline at end of file
+ .right {
+ display: flex;
+ flex-direction: column;
+ align-items: end;
+ }
+}
+
+.urgent {
+ font-size: 11pt;
+ background-color: rgba(255, 165, 0, 0.27);
+ color: rgba(255, 165, 0, 1);
+ padding: 2px;
+ border-radius: 5px;
+}
+
+.prog {
+ display: flex;
+ flex-direction: column;
+}
+
+.clickable {
+ padding: 10px;
+ background-color: #3a3a3a;
+ border-radius: 5px;
+ cursor: pointer;
+}
+
+.clickable:hover {
+ background-color: #444444;
+}
+
+.actionArea {
+ display: flex;
+ padding: 5px;
+ gap: 5px;
+}
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 504e694..52b35c1 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
@@ -1,39 +1,81 @@
-<h1>Funding Basket</h1>
-<div id="needCount">
- <label for="needCount">Needs in Basket:</label>
- <span>{{ this.usersService.getBasket().getValue().length }}</span>
-</div>
+<!--<div id="needCount">-->
+<!-- <label for="needCount">Needs in Basket:</label>-->
+<!-- <span>{{ this.usersService.getBasket().getValue().length }}</span>-->
+<!--</div>-->
-<div *ngIf="this.usersService.getBasket().getValue().length == 0">
- <h2>There are no needs in the basket</h2>
-</div>
+<!--<div *ngIf="this.usersService.getBasket().getValue().length == 0">-->
+<!-- <h2>There are no needs in the basket</h2>-->
+<!--</div>-->
+
+<!--<table class="needs" id="funding-basket" *ngIf="this.usersService.getBasket().getValue().length != 0">-->
+<!-- <thead>-->
+<!-- <tr>-->
+<!-- <th class="need"></th>-->
+<!-- </tr>-->
+<!-- </thead>-->
+<!-- <tbody>-->
+<!-- <tr *ngFor="let need of usersService.getBasket().getValue()">-->
+<!-- <td>-->
+<!-- <a routerLink="/need/{{need.id}}">{{need.name}}</a>-->
+<!-- <p>Goal: {{need.maxGoal}}</p>-->
+<!-- <p>Current: {{(need.current).toFixed(2)}}</p>-->
+<!-- <p>How much to Contribute: <input type="number" placeholder="insert value" min="1" 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>-->
+<!-- </div>-->
+<!-- </td>-->
+<!-- </tr>-->
+<!-- </tbody>-->
+<!--</table>-->
+<!--<br>-->
+<div id="box">
+ <h1>Funding Basket</h1>
+ <ng-template [ngIf]="usersService.getBasket().getValue().length">
+ <div id="needList">
+ <div *ngFor="let need of usersService.getBasket().getValue()" class="needEntry">
+ <div [routerLink]="'/need/' + need.id" class="clickable">
+ <div class="split">
+ <div class="left">
+ <span class="needName">{{need.name}}</span>
+ <span class="needType">{{need.type}}</span>
+ </div>
+
+ <div class="right">
+ <span *ngIf="need.urgent" class="urgent">URGENT</span>
+ <span *ngIf="need.location"><span class="icon">location_on</span>{{need.location}}</span>
+ </div>
+ </div>
+
+ <br>
-<table class="needs" id="funding-basket" *ngIf="this.usersService.getBasket().getValue().length != 0">
- <thead>
- <tr>
- <th class="need"></th>
- </tr>
- </thead>
- <tbody>
- <tr *ngFor="let need of usersService.getBasket().getValue()">
- <td>
- <a routerLink="/need/{{need.id}}">{{need.name}}</a>
- <p>Goal: {{need.maxGoal}}</p>
- <p>Current: {{(need.current).toFixed(2)}}</p>
- <p>How much to Contribute: <input type="number" placeholder="insert value" min="1" 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>
+ <div class="prog">
+ <span id="hover-status-label-{{need.id}}"> </span>
+ <span>{{need.current}}/{{need.maxGoal}} ({{((need.current / need.maxGoal) * 100).toFixed(0)}}%)</span>
+ <progress [value]="need.current" [max]="need.maxGoal"></progress>
+ </div>
+
+ <!-- <div class="description">-->
+ <!-- {{need.description}}-->
+ <!-- </div>-->
+ </div>
+
+ <div class="actionArea">
+ <input type="number" placeholder="Quantity" min="1" id={{need.id}} class="contribution">
+ <button class="removeNeed" title="delete need" (click)="this.usersService.removeNeed(need.id)">
+ <span class="icon">delete</span> Remove from Basket
+ </button>
</div>
- </td>
- </tr>
- </tbody>
-</table>
-<br>
-<div>
- <p *ngIf="!isValid">Invalid input in funding basket!</p>
- <button type="submit" class="checkout" title="checkout" (click)="checkout()">Checkout</button>
- <span *ngIf="statusText">{{statusText | async}}</span>
-</div> \ No newline at end of file
+ </div>
+ </div>
+ <br>
+ <div id="footer">
+ <button class="button2" title="checkout" (click)="checkout()">Checkout</button>
+ </div>
+ </ng-template>
+ <div *ngIf="!usersService.getBasket().getValue().length">
+ <span>There are no needs in your basket! </span><a routerLink="/cupboard">Browse the cupboard</a>
+ </div>
+</div>
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 e654711..dcacca1 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,11 +1,10 @@
import {Component, Input, OnInit, ViewChild} from '@angular/core';
-import {User} from '../../models/User';
-import { UsersService } from '../../services/users.service';
-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, catchError, firstValueFrom, Observable } from 'rxjs';
+import {UsersService} from '../../services/users.service';
+import {Router} from '@angular/router';
+import {CupboardService} from '../../services/cupboard.service';
+import {catchError, firstValueFrom, Observable} from 'rxjs';
+import {AuthService} from '../../services/auth.service';
+import {ToastsService, ToastType} from '../../services/toasts.service';
@Component({
selector: 'app-funding-basket',
@@ -14,67 +13,82 @@ import { BehaviorSubject, catchError, firstValueFrom, Observable } from 'rxjs';
styleUrl: './funding-basket.component.css'
})
export class FundingBasketComponent implements OnInit {
- statusText: any;
- constructor(
- private router: Router,
- protected cupboardService: CupboardService,
- protected usersService: UsersService
- ) {}
+ constructor(
+ private router: Router,
+ protected cupboardService: CupboardService,
+ protected usersService: UsersService,
+ private authService: AuthService,
+ private toastService: ToastsService
+ ) {}
- @ViewChild("contribution") contribution?: Input;
- @Input() isValid: boolean = true;
+ @ViewChild("contribution") contribution?: Input;
+ @Input() isValid: boolean = true;
- // this is for login rerouting
- ngOnInit(): void {
- if (!this.usersService.getCurrentUser()) {
- this.router.navigate(['/login'], {queryParams: {redir: this.router.url}});
- return;
+ // this is for login rerouting
+ ngOnInit(): void {
+ if (!this.authService.getCurrentUser()) {
+ this.router.navigate(['/login'], {queryParams: {redir: this.router.url}});
+ return;
+ }
+
+ this.usersService.refreshBasket();
+ // this.usersService.removeNeed(); <- call this to remove
}
- this.usersService.refreshBasket();
- // this.usersService.removeNeed(); <- call this to remove
- }
+ async checkout() {
+ this.isValid = true;
+ for (let c of document.querySelectorAll('.contribution')!) {
+ let contribution = c as HTMLInputElement;
+ contribution.setAttribute("style", "");
+ if (contribution.value == '' || contribution.valueAsNumber <= 0) {
+ this.isValid = false;
- async checkout() {
- this.isValid = true;
- for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) {
- let contribution = c as HTMLInputElement;
- 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')!) {
- let contribution = c as HTMLInputElement;
- let need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id));
- need.current +=+ contribution.value;
- this.usersService.removeNeed(+need.id);
- 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 new Observable<string>();
- }))
- .subscribe((result) => {
- if (result) {
- console.log('need updated successfully');
- //this.needList?.refresh()
- } else {
- console.log('need update failed');
- }
- });
- }
- }
- }
+ contribution.setAttribute("style", "border-color: #ff0000");
+ this.toastService.sendToast(ToastType.ERROR, "Invalid input in funding basket!")
+ setTimeout(() => {
+ contribution.setAttribute("style", "border-color: #ffffff");
+ }, 3000);
+ }
+ }
+ // if (this.usersService.getBasket().value != await firstValueFrom(this.usersService.getUser(1))
+ // for (let c of this.usersService.getBasket().value) {
+ // if (c == null) {
+ // this.isValid = false;
+ // this.statusText.next("One or more needs have been deleted")
+ // } else {
+ // this.statusText.next("test")
+ // }
+ // }
+ if (this.isValid) {
+ for (let c of document.querySelectorAll('.contribution')!) {
+ let contribution = c as HTMLInputElement;
+ let need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id));
+ need.current += +contribution.value;
+ this.usersService.removeNeed(+need.id);
+ this.cupboardService.checkoutNeed(need.id, +contribution.value)
+ .pipe(catchError((ex, _) => {
+ if (ex.status == 500) {
+ this.toastService.sendToast(ToastType.INFO, 'Fields cannot be blank');
+ } else if (ex.status == 400) {
+ this.toastService.sendToast(ToastType.INFO, 'Goal must be greater than 0');
+ } else {
+ this.toastService.sendToast(ToastType.INFO, 'Error on creating need');
+ }
+ return new Observable<string>();
+ }))
+ .subscribe((result) => {
+ if (result) {
+ //this.needList?.refresh()
+ } else {
+ console.log('need update failed');
+ }
+ this.toastService.sendToast(ToastType.INFO, "Checkout successful");
+ });
+ }
+ }
+ }
}
diff --git a/ufund-ui/src/app/components/home-page/home-page.component.css b/ufund-ui/src/app/components/home-page/home-page.component.css
index e69de29..a10377f 100644
--- a/ufund-ui/src/app/components/home-page/home-page.component.css
+++ b/ufund-ui/src/app/components/home-page/home-page.component.css
@@ -0,0 +1,38 @@
+:host {
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ overflow: clip;
+}
+
+#hero {
+ display: flex;
+ /*flex-direction: column;*/
+ /*align-items: start;*/
+ /*justify-content: center;*/
+}
+
+h1 {
+ font-size: 50px;
+ max-width: 1200px;
+}
+
+#jf {
+ /*position: absolute;*/
+}
+
+#right {
+ max-width: 500px;
+ max-height: 500px;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ /*z-index: -0.5;*/
+}
+
+#left {
+ max-width: 500px;
+ z-index: 1;
+}
diff --git a/ufund-ui/src/app/components/home-page/home-page.component.html b/ufund-ui/src/app/components/home-page/home-page.component.html
index d41e670..7a7ff96 100644
--- a/ufund-ui/src/app/components/home-page/home-page.component.html
+++ b/ufund-ui/src/app/components/home-page/home-page.component.html
@@ -1,3 +1,10 @@
-<a routerLink="/login">
- Login/Sign Up
-</a> \ No newline at end of file
+<div id="hero">
+ <div id="left">
+ <h1>Helping fund coral reef and marine life conservation</h1>
+ <p>View our online cupboard holding all needs related to sea life preservation</p>
+ <button class="button2" routerLink="/cupboard">View needs</button>
+ </div>
+ <div id="right">
+ <img id="jf" src="jf.png" height="1024" width="1024"/>
+ </div>
+</div>
diff --git a/ufund-ui/src/app/components/home-page/home-page.component.ts b/ufund-ui/src/app/components/home-page/home-page.component.ts
index 5b2277c..95e8962 100644
--- a/ufund-ui/src/app/components/home-page/home-page.component.ts
+++ b/ufund-ui/src/app/components/home-page/home-page.component.ts
@@ -1,10 +1,10 @@
-import { Component } from '@angular/core';
+import {Component} from '@angular/core';
@Component({
- selector: 'app-home-page',
- standalone: false,
- templateUrl: './home-page.component.html',
- styleUrl: './home-page.component.css'
+ selector: 'app-home-page',
+ standalone: false,
+ templateUrl: './home-page.component.html',
+ styleUrl: './home-page.component.css'
})
export class HomePageComponent {
diff --git a/ufund-ui/src/app/components/login/login.component.css b/ufund-ui/src/app/components/login/login.component.css
index 435cc87..b56b4eb 100644
--- a/ufund-ui/src/app/components/login/login.component.css
+++ b/ufund-ui/src/app/components/login/login.component.css
@@ -1,8 +1,28 @@
-:host, .border {
- display: flex;
- flex-direction: column;
- max-width: 300px;
- gap: 5px
+:host {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ height: 100%;
+ /*background-image: url("https://www.fineshare.com/background/jellyfish-under-fluorescent-illumination.jpg");*/
+ background: rgba(0, 0, 0, .65) url("https://4kwallpapers.com/images/wallpapers/blue-jellyfish-aquarium-underwater-glowing-marine-life-1920x1080-3546.jpg");
+ background-blend-mode: darken;
+ margin-top: -66px
+
+}
+
+#box {
+ display: flex;
+ flex-direction: column;
+ max-width: 350px;
+ gap: 10px;
+ backdrop-filter: blur(10px);
+ background-color: rgba(0, 0, 0, 0.1);
+ padding: 30px;
+ color: white;
+ border-radius: 5px;
+ border-style: solid;
+ border-width: 1px;
+ border-color: rgb(140, 140, 255);
}
.border {
diff --git a/ufund-ui/src/app/components/login/login.component.html b/ufund-ui/src/app/components/login/login.component.html
index 2cdb6d0..c67b903 100644
--- a/ufund-ui/src/app/components/login/login.component.html
+++ b/ufund-ui/src/app/components/login/login.component.html
@@ -1,7 +1,9 @@
-<span *ngIf="next" style="color: red">You must be logged in to view this page</span>
-<p>Login:</p>
-<input placeholder="Username" type="text" #username>
-<input placeholder="Password" type="password" #password>
-<button type="button" (click)="login(username.value, password.value)">Login</button>
-<button type="button" (click)="signup(username.value, password.value)">Create Account</button>
-<span *ngIf="statusText">{{statusText | async}}</span>
+<div id="box">
+ <h1>Login</h1>
+ <input placeholder="Username" type="text" #username>
+ <input placeholder="Password" type="password" #password>
+ <button type="button" (click)="login(username.value, password.value)">Login</button>
+ <div>
+ New? <a routerLink="/signup">Create an account</a>
+ </div>
+</div>
diff --git a/ufund-ui/src/app/components/login/login.component.ts b/ufund-ui/src/app/components/login/login.component.ts
index 9d806f5..0177f67 100644
--- a/ufund-ui/src/app/components/login/login.component.ts
+++ b/ufund-ui/src/app/components/login/login.component.ts
@@ -1,23 +1,25 @@
import {Component, OnInit} from '@angular/core'
import {UsersService} from '../../services/users.service';
import {ActivatedRoute, Router} from '@angular/router';
-import {BehaviorSubject} from 'rxjs';
+import {AuthService} from '../../services/auth.service';
+import {ToastsService, ToastType} from '../../services/toasts.service';
@Component({
- selector: 'app-login',
- standalone: false,
- templateUrl: './login.component.html',
- styleUrl: './login.component.css'
+ selector: 'app-login',
+ standalone: false,
+ templateUrl: './login.component.html',
+ styleUrl: './login.component.css'
})
export class LoginComponent implements OnInit {
protected next?: string | null;
- protected statusText = new BehaviorSubject("")
constructor(
protected usersService: UsersService,
protected router: Router,
- private route: ActivatedRoute
+ private route: ActivatedRoute,
+ private authService: AuthService,
+ private toastService: ToastsService
) {}
ngOnInit() {
@@ -31,10 +33,12 @@ export class LoginComponent implements OnInit {
return;
}
- this.usersService.login(username, password).then(() => {
+ this.authService.login(username, password).then(() => {
this.router.navigate([next]);
+ let key = this.authService.getApiKey()
+ localStorage.setItem("credential", JSON.stringify({username: username, key: key}))
}).catch(ex => {
- this.statusText.next("Unable to login: " + friendlyHttpStatus[ex.status])
+ this.toastService.sendToast(ToastType.ERROR, "Unable to login: " + friendlyHttpStatus[ex.status])
console.log(ex)
})
}
@@ -46,9 +50,9 @@ export class LoginComponent implements OnInit {
}
this.usersService.createUser(username, password).then(() => {
- this.statusText.next("Account created, click login.")
+ this.toastService.sendToast(ToastType.INFO, "Account created, click login.")
}).catch(ex => {
- this.statusText.next("Unable to create account: " + friendlyHttpStatus[ex.status])
+ this.toastService.sendToast(ToastType.ERROR, "Unable to create account: " + friendlyHttpStatus[ex.status])
console.log(ex)
})
}
diff --git a/ufund-ui/src/app/components/mini-need-list/mini-need-list.component.css b/ufund-ui/src/app/components/mini-need-list/mini-need-list.component.css
new file mode 100644
index 0000000..ac456ab
--- /dev/null
+++ b/ufund-ui/src/app/components/mini-need-list/mini-need-list.component.css
@@ -0,0 +1,56 @@
+:host {
+ display: flex;
+ flex-direction: column;
+ border: solid rgba(255, 255, 255, 0.5) 1px;
+ border-radius: 5px;
+}
+
+#header {
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+ border-bottom: solid rgba(255, 255, 255, 0.5) 1px;
+ padding: 10px;
+
+ a {
+ display: flex;
+ }
+}
+
+#needList {
+ display: flex;
+ flex-direction: row;
+ padding: 10px;
+ gap: 10px;
+ justify-content: start;
+ overflow: clip;
+}
+
+.needEntry {
+ padding: 10px;
+ display: flex;
+ flex-direction: column;
+ background-color: #3a3a3a;
+ border-radius: 5px;
+ height: 175px;
+ width: 200px;
+ justify-content: space-between;
+
+ div {
+ display: flex;
+ flex-direction: column;
+ }
+
+ user-select: none;
+ cursor: pointer;
+}
+
+.needName {
+ font-weight: bold;
+}
+
+.needType {
+ text-transform: uppercase;
+ /*font-weight: 300;*/
+ font-size: 10pt;
+}
diff --git a/ufund-ui/src/app/components/mini-need-list/mini-need-list.component.html b/ufund-ui/src/app/components/mini-need-list/mini-need-list.component.html
new file mode 100644
index 0000000..a2de9e5
--- /dev/null
+++ b/ufund-ui/src/app/components/mini-need-list/mini-need-list.component.html
@@ -0,0 +1,17 @@
+<div id="header">
+ <span>{{jtitle}}</span>
+ <a [routerLink]="url">Show All<span class="icon">arrow_forward_ios</span></a>
+</div>
+
+<div id="needList">
+ <div class="needEntry" *ngFor="let need of needList" [routerLink]="'/need/'+need.id">
+ <div>
+ <span class="needName">{{need.name}}</span>
+ <span class="needType">{{need.type}}</span>
+ </div>
+ <div>
+ <span>{{need.current}}/{{need.maxGoal}}</span>
+ <progress [max]="need.maxGoal" [value]="need.current"></progress>
+ </div>
+ </div>
+</div>
diff --git a/ufund-ui/src/app/components/mini-need-list/mini-need-list.component.ts b/ufund-ui/src/app/components/mini-need-list/mini-need-list.component.ts
new file mode 100644
index 0000000..c909ae6
--- /dev/null
+++ b/ufund-ui/src/app/components/mini-need-list/mini-need-list.component.ts
@@ -0,0 +1,19 @@
+import {Component, Input} from '@angular/core';
+import {Need} from '../../models/Need';
+
+@Component({
+ selector: 'app-mini-need-list',
+ standalone: false,
+ templateUrl: './mini-need-list.component.html',
+ styleUrl: './mini-need-list.component.css'
+})
+export class MiniNeedListComponent {
+
+ @Input() needList?: Need[]
+ @Input() jtitle?: string
+ @Input() url?: string
+
+ constructor(
+
+ ) {}
+}
diff --git a/ufund-ui/src/app/components/need-edit/need-edit.component.css b/ufund-ui/src/app/components/need-edit/need-edit.component.css
new file mode 100644
index 0000000..17605c2
--- /dev/null
+++ b/ufund-ui/src/app/components/need-edit/need-edit.component.css
@@ -0,0 +1,21 @@
+:host {
+ /*position: absolute;*/
+ /*background-color: rgba(0, 0, 0, 0.5);*/
+ /*display: flex;*/
+ /*height: 100%;*/
+ /*top: 0;*/
+ /*left: 0;*/
+ /*right: 0;*/
+ /*z-index: 5;*/
+ /*justify-content: center;*/
+}
+
+#create-form, #delete-form, #update-form {
+ margin-top: 50px;
+ background-color: #3a3a3a;
+ padding: 10px 20px 20px 20px;
+ border: 2px solid #000;
+ border-radius: 5px;
+ /*visibility: visible;*/
+ /*position: absolute;*/
+}
diff --git a/ufund-ui/src/app/components/need-edit/need-edit.component.html b/ufund-ui/src/app/components/need-edit/need-edit.component.html
new file mode 100644
index 0000000..e776415
--- /dev/null
+++ b/ufund-ui/src/app/components/need-edit/need-edit.component.html
@@ -0,0 +1,24 @@
+<div id="update-form">
+ <h1> Update Need </h1>
+ <form #updateForm="ngForm" (ngSubmit)="update(updateForm.value)">
+ <label>Name:</label><br>
+ <input type="text" name="name" [(ngModel)]="selectedNeed.name"><br>
+ <label>Image:</label><br>
+ <input type="text" name="image" [(ngModel)]="selectedNeed.image"><br>
+ <label>Location:</label><br>
+ <input type="text" name="location" [(ngModel)]="selectedNeed.location"><br>
+ <label>Max Goal:</label><br>
+ <input type="number" name="maxGoal" [(ngModel)]="selectedNeed.maxGoal"><br>
+ <label>Type</label><br>
+ <input type="radio" name="type" value="MONETARY" [(ngModel)]="selectedNeed.type">
+ <label>Monetary</label><br>
+ <input type="radio" name="type" value="PHYSICAL" [(ngModel)]="selectedNeed.type">
+ <label>Physical</label><br>
+ <input type="checkbox" name="urgent" [(ngModel)]="selectedNeed.urgent">
+ <label>Urgent</label> <br>
+ <label>Description</label> <br>
+ <textarea name="description" [(ngModel)]="selectedNeed.description"></textarea><br>
+ <input type="submit" value="Submit">
+
+ </form>
+</div>
diff --git a/ufund-ui/src/app/components/need-edit/need-edit.component.ts b/ufund-ui/src/app/components/need-edit/need-edit.component.ts
new file mode 100644
index 0000000..2462534
--- /dev/null
+++ b/ufund-ui/src/app/components/need-edit/need-edit.component.ts
@@ -0,0 +1,61 @@
+import { Component, Input, Output, EventEmitter } from '@angular/core';
+import { Need, GoalType } from '../../models/Need';
+import { CupboardService } from '../../services/cupboard.service';
+import { catchError, of } from 'rxjs';
+import { ToastsService, ToastType } from '../../services/toasts.service';
+
+@Component({
+ selector: 'app-need-edit',
+ standalone: false,
+ templateUrl: './need-edit.component.html',
+ styleUrl: './need-edit.component.css'
+})
+export class NeedEditComponent {
+ constructor(
+ private cupboardService: CupboardService,
+ private toastService: ToastsService
+
+ ) {}
+
+ @Input() selectedNeed!: Need;
+ @Output() refreshNeedList = new EventEmitter<void>();
+
+ update(form: any) {
+ console.log(form);
+ const need: Need = {
+ name: form.name,
+ image: form.image,
+ location: form.location,
+ id: this.selectedNeed.id, //system will control this
+ maxGoal: form.maxGoal,
+ type: GoalType[form.type as keyof typeof GoalType],
+ urgent: form.urgent,
+ filterAttributes: [],
+ current: 0,
+ description: form.description
+ };
+
+ this.cupboardService.updateNeed(need.id, need)
+ .pipe(catchError((ex, _) => {
+ if (ex.status == 500) {
+ this.toastService.sendToast(ToastType.ERROR, 'Fields cannot be blank');
+ } else if (ex.status == 400) {
+ this.toastService.sendToast(ToastType.ERROR, ex.error);
+ } else {
+ this.toastService.sendToast(ToastType.ERROR, "Error on creating need");
+ }
+ return of()
+ }))
+ .subscribe(
+ (result) => {
+ if (result) {
+ console.log("need updated successfully");
+ this.refreshNeedList.emit();
+ } else {
+ console.log("need update failed");
+ }
+ }
+
+ );
+ }
+} \ No newline at end of file
diff --git a/ufund-ui/src/app/components/need-list/need-list.component.css b/ufund-ui/src/app/components/need-list/need-list.component.css
index bbc3f2c..5f2e5e1 100644
--- a/ufund-ui/src/app/components/need-list/need-list.component.css
+++ b/ufund-ui/src/app/components/need-list/need-list.component.css
@@ -1,24 +1,110 @@
-:host {
- list-style-type:circle;
- border: 2px solid #000;
- display: block;
- width: 30%;
- border-radius: 5px;
-
+#header {
+ display: flex;
+ flex-direction: column;
+ gap: 10px
}
-li, div {
- border: 2px solid #000;
+.needEntry {
+ background-color: #2e2e2e;
+ display: flex;
+ flex-direction: column;
border-radius: 5px;
+}
+
+#needList {
+ display: flex;
+ flex-direction: column;
+ gap: 15px
+}
+
+select {
+ font-size: 14pt;
padding: 5px;
- margin: 5px;
+}
+
+#searchArea {
+ display: flex;
+ form {
+ display: flex;
+ width: 100%;
+ gap: 10px;
+ }
+
+ input[type=text] {
+ display: flex;
+ width: 100%;
+ }
}
-#search-form {
- background-color: #d9d9d9;
- padding: 10px 20px 20px 20px;
- border: 2px solid #000;
- border-radius: 5px;
- visibility: visible;
- } \ No newline at end of file
+#sortArea {
+ display: flex;
+ flex-direction: row;
+ gap: 10px;
+ align-items: center;
+}
+
+.needName {
+ font-weight: bold;
+}
+
+.needType {
+ text-transform: uppercase;
+ font-size: 10pt;
+}
+
+.split {
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+
+
+ .left {
+ display: flex;
+ flex-direction: column;
+ }
+
+ .right {
+ display: flex;
+ flex-direction: column;
+ align-items: end;
+ }
+}
+
+.urgent {
+ font-size: 11pt;
+ background-color: rgba(255, 165, 0, 0.27);
+ color: rgba(255, 165, 0, 1);
+ padding: 2px;
+ border-radius: 5px;
+}
+
+.prog {
+ display: flex;
+ flex-direction: column;
+}
+
+.clickable {
+ padding: 10px;
+ background-color: #3a3a3a;
+ border-radius: 5px;
+ cursor: pointer;
+}
+
+.clickable:hover {
+ background-color: #444444;
+}
+
+.actionArea {
+ display: flex;
+ padding: 5px;
+ gap: 5px;
+}
+
+#page-selector {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ padding: 10px;
+ gap: 10px
+}
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 36c12d0..c0501ba 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
@@ -1,28 +1,71 @@
-<h1>Needs List</h1>
-<input id="search-button" type="button" value="Search" (click)="open()">
-<div id="search-form">
- <form #searchForm="ngForm">
- <label>Search:</label><br>
- <input type="text" name="search" (input)="search(searchForm.value)" ngModel>
- <input type="button" value="Clear" (click)="searchForm.reset()"> <br>
- </form>
- <button (click)="close()">Close</button>
- <div>
- <h2 id="search-status">Search Results:</h2>
- <div *ngFor="let need of searchResults">
- <a routerLink="/need/{{need.id}}">
- {{need.name}}
- </a>
- <button (click)="delete(need.id)" *ngIf="isManager()">Delete</button>
- <!-- <button (click)="add(need)" *ngIf="isHelper()">Add To Basket</button> -->
+<div id="header">
+ <div id="searchArea">
+ <form id="search-form" #searchForm="ngForm">
+ <input type="text" name="search" class="wide-input" placeholder="Search in {{needs.length}} needs..." (input)="search(searchForm.value)" ngModel>
+ <input type="reset" value="Clear" (click)="search(null)"> <br>
+ </form>
+ </div>
+ <div id="sortArea">
+ <label for="sort">Sort by: </label>
+ <select id='sort' [(ngModel)] = "sortSelection" class="wide-input" (change)="search(searchForm.value)" [value]="sortSelection">
+ <option *ngFor="let algorithm of SortingAlgoArrays" value="{{algorithm.name}}">
+ {{algorithm.display[sortMode === 'Ascending' ? 0 : 1]}}
+ </option>
+ </select>
+ <button (click)="changeSortMode(searchForm.value)">
+ <span class="icon">{{sortMode === 'Ascending' ? 'arrow_upward': 'arrow_downward'}}</span>
+ </button>
+ <label>Needs per page: </label>
+ <input type ="number" [(ngModel)]="itemsPerPage" (change)="resetVisibleNeeds()" min="1" max="{{searchResults.length}}">
+ </div>
+ <!--<button (click)="close()">Close</button>-->
+</div>
+
+<!-- display for when results are present and filtered-->
+<h2 *ngIf="searchResults.length < needs.length && searchResults.length != 0"> Search Results({{needs.length - searchResults.length}} needs filtered): </h2>
+<h2 *ngIf="searchResults.length == needs.length"> All Needs </h2>
+<h2 *ngIf="searchResults.length == 0"> No Results Found </h2>
+<div id="needList">
+ <div *ngFor="let need of visibleNeeds" class="needEntry">
+ <div [routerLink]="'/need/' + need.id" class="clickable">
+ <div class="split">
+ <div class="left">
+ <span class="needName">{{need.name}}</span>
+ <span class="needType">{{need.type}}</span>
+ </div>
+
+ <div class="right">
+ <span *ngIf="need.urgent" class="urgent">URGENT</span>
+ <span *ngIf="need.location"><span class="icon">location_on</span>{{need.location}}</span>
+ </div>
+ </div>
+
+ <br>
+
+ <div class="prog">
+ <span id="hover-status-label-{{need.id}}"> </span>
+ <span>{{need.current}}/{{need.maxGoal}} ({{((need.current / need.maxGoal) * 100).toFixed(0)}}%)</span>
+ <progress [value]="need.current" [max]="need.maxGoal"></progress>
+ </div>
+
+ </div>
+
+ <div class="actionArea">
+ <button *ngIf="isHelper()" (click)="add(need)">
+ <span class="icon">add</span>Add To Basket
+ </button>
+ <button *ngIf="isManager()" (click)="select(need)">
+ <span class="icon">edit</span>Edit Need
+ </button>
+ <button *ngIf="isManager()" (click)="delete(need.id)" >
+ <span class="icon">delete</span>Delete Need
+ </button>
</div>
</div>
</div>
-<li *ngFor="let need of needs">
- <a routerLink="/need/{{need.id}}">
- {{need.name}}
- </a>
- <button (click)="delete(need.id)" *ngIf="isManager()">Delete</button>
- <button (click)="add(need)" *ngIf="isHelper()">Add To Basket</button>
-</li>
+<div id="page-selector">
+ <button *ngIf="currentPage > 0" (click)="decrementPage()"><span class="icon">arrow_back_ios</span></button>
+ <span>Page {{currentPage + 1}} of {{totalPages}}</span>
+ <button *ngIf="currentPage < totalPages - 1" (click)="incrementPage()"><span class="icon">arrow_forward_ios</span></button>
+</div>
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 25f05d6..cd3d9bd 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
@@ -1,8 +1,61 @@
-import { Component } from '@angular/core';
+import {Component, EventEmitter, Output} from '@angular/core';
import {Need} from '../../models/Need';
import {CupboardService} from '../../services/cupboard.service';
-import { UsersService } from '../../services/users.service';
-import { userType } from '../../models/User';
+import {UsersService} from '../../services/users.service';
+import {userType} from '../../models/User';
+import {AuthService} from '../../services/auth.service';
+import {catchError, of} from 'rxjs';
+import {ToastsService, ToastType} from '../../services/toasts.service';
+
+interface sortAlgo {
+ (a: Need,b: Need): number;
+}
+
+// sort functions
+const sortByName: sortAlgo = (a: Need, b: Need): number => {
+ if(a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
+ return -1;
+ }
+ return 1;
+}
+
+const sortByGoal: sortAlgo = (a: Need, b: Need): number => {
+ if(a.maxGoal == b.maxGoal) {
+ return sortByName(a,b);
+ }
+ else if(a.maxGoal > b.maxGoal) {
+ return -1;
+ }
+ return 1;
+}
+
+const sortByCompletion: sortAlgo = (a: Need, b: Need): number => {
+ if(a.current == b.current) {
+ return sortByGoal(a,b);
+ }
+ else if(a.current > b.current) {
+ return -1;
+ }
+ return 1;
+}
+
+const sortByPriority: sortAlgo = (a: Need, b: Need): number => {
+ if(a.urgent == b.urgent) {
+ return sortByGoal(a,b);
+ }
+ else if(a.urgent && !b.urgent) {
+ return -1;
+ }
+ return 1;
+}
+
+const sortByLocation: sortAlgo = (a: Need, b: Need): number => {
+ if(a.location.toLocaleLowerCase() < b.location.toLocaleLowerCase()) {
+ return -1;
+ }
+ return 1;
+}
+
@Component({
selector: 'app-need-list',
standalone: false,
@@ -10,54 +63,88 @@ import { userType } from '../../models/User';
styleUrl: './need-list.component.css'
})
export class NeedListComponent {
+ selectedNeed: Need | null = null;
needs: Need[] = [];
searchResults: Need[] = [];
+ visibleNeeds: Need[] = [];
+ sortMode: 'Ascending' | 'Descending' = 'Ascending'
+ currentPage: number = 0;
+ itemsPerPage: number = 5;
+ totalPages: number = Math.ceil(this.needs.length / this.itemsPerPage);
+
+ decrementPage() {
+ this.currentPage--;
+ this.updateVisibleNeeds();
+ }
+
+ incrementPage() {
+ this.currentPage++;
+ this.updateVisibleNeeds();
+ }
+
+ editNeedsPerPage(amount: number) {
+ this.itemsPerPage = amount;
+ this.updateVisibleNeeds();
+ }
+
+ updateVisibleNeeds() {
+ this.totalPages = Math.ceil(this.searchResults.length / this.itemsPerPage);
+ this.visibleNeeds = this.searchResults.slice(this.currentPage * this.itemsPerPage, (this.currentPage + 1) * this.itemsPerPage);
+ }
+
+ resetVisibleNeeds() {
+ this.currentPage = 0;
+ this.updateVisibleNeeds();
+ }
+
+ currentSortAlgo: sortAlgo = sortByPriority;
+ sortSelection: string = 'sortByPriority';
+
+ SortingAlgoArrays: {func:sortAlgo,name:string, display:string[]}[] = [
+ {func:sortByPriority,name:"sortByPriority", display:["Highest Priority", "Lowest Priority"]},
+ {func:sortByName,name:"sortByName", display:["Name (A to Z)", "Name (Z to A)"]},
+ {func:sortByLocation,name:"sortByLocation", display:["Location (A to Z)", "Location (Z to A)"]},
+ {func:sortByCompletion,name:"sortByCompletion", display:["Most Completed", "Least Completed"]},
+ {func:sortByGoal,name:"sortByGoal", display:["Largest Maximum Goal", "Smallest Maximum Goal"]},
+ ];
+
+ @Output() currentNeed = new EventEmitter<Need>();
constructor(
private cupboardService: CupboardService,
- private usersService: UsersService
+ private usersService: UsersService,
+ private authService: AuthService,
+ private toastService: ToastsService
) {}
refresh() {
- this.cupboardService.getNeeds().subscribe(n => this.needs = n)
+ this.cupboardService.getNeeds().subscribe(n => {
+ if (this.sortMode == 'Ascending') {
+ this.needs = n.sort(this.currentSortAlgo);
+ } else {
+ this.needs = n.sort(this.currentSortAlgo).reverse();
+ }
+ this.searchResults = this.needs;
+ this.updateVisibleNeeds();
+ });
+
+ const form = document.getElementById('search-form') as HTMLFormElement;
+ form.reset();
+ this.search(null);
}
ngOnInit(): void {
this.refresh()
- this.close();
- }
-
- private showElement(element: any) {
- if (element){
- element.style.visibility = 'visible';
- element.style.position = 'relative';
- }
- }
-
- private hideElement(element: any) {
- if (element){
- element.style.visibility = 'hidden';
- element.style.position = 'absolute';
- }
}
- private updateSearchStatus(text: string) {
- let element = document.getElementById('search-status');
- if (element) {
- element.innerHTML = text;
+ changeSortMode(form : any) {
+ if (this.sortMode == 'Ascending'){
+ this.sortMode = 'Descending'
+ } else {
+ this.sortMode = 'Ascending'
}
- }
-
- open() {
- this.hideElement(document.getElementById('search-button'));
- this.showElement(document.getElementById('search-form'));
- }
-
- close() {
- this.hideElement(document.getElementById('search-form'));
- this.showElement(document.getElementById('search-button'));
- this.hideElement(document.getElementById('search-status'));
+ this.search(form)
}
private searchDelay: any;
@@ -69,64 +156,120 @@ export class NeedListComponent {
if (this.searchDelay) {
clearTimeout(this.searchDelay);
}
+ if (form) {
+ this.searchDelay = setTimeout(() => {
- this.searchDelay = setTimeout(() => {
- const currentSearchValue = form.search; //latest value of the search
- this.cupboardService.searchNeeds(currentSearchValue).subscribe((n) => {
- this.searchResults = n;
- console.log(currentSearchValue, this.searchResults);
- this.showElement(document.getElementById('search-results'));
- this.showElement(document.getElementById('search-status'));
- if (this.searchResults.length === this.needs.length) {
- this.updateSearchStatus("Please refine your search");
- this.searchResults = [];
- } else if (this.searchResults.length === 0) {
- this.updateSearchStatus("No results found");
- } else {
- this.updateSearchStatus("Search results:");
- }
- });
- }, 250);
+ if (form) {
+ //sorting based on algo selected
+ this.SortingAlgoArrays.forEach(algo => {
+ if(algo.name === this.sortSelection) {
+ this.currentSortAlgo = algo.func;
+ console.log("changed sorting algorithm to: ", algo.name + this.sortMode)
+ return
+ }
+ });
+
+ const currentSearchValue = form.search; //latest value of the search
+ this.cupboardService.searchNeeds(currentSearchValue).subscribe((n) => {
+ if (this.sortMode == 'Ascending') {
+ this.searchResults = n.sort(this.currentSortAlgo);
+ } else {
+ this.searchResults = n.sort(this.currentSortAlgo).reverse();
+ }
+ this.updateVisibleNeeds();
+ });
+ }
+ }, 250);
+ } else {
+ //user has cleared the search bar, we can skip the timeout for a 1/4 second faster response
+ //clear timeout to stop pending search
+ clearTimeout(this.searchDelay);
+ this.searchResults = this.needs;
+ }
}
delete(id : number) {
this.cupboardService.deleteNeed(id).subscribe(() => {
+ this.toastService.sendToast(ToastType.INFO, "Need deleted.")
this.needs = this.needs.filter(n => n.id !== id)
})
+ this.refresh();
}
isManager() {
- const type = this.usersService.getCurrentUser()?.type;
+ const type = this.authService.getCurrentUser()?.type;
return type === ("MANAGER" as unknown as userType);
}
isHelper() {
- const type = this.usersService.getCurrentUser()?.type;
+ const type = this.authService.getCurrentUser()?.type;
return type === ("HELPER" as unknown as userType);
}
+ changeText(id : number, text : string) {
+ const span = document.getElementById('hover-status-label-' + id);
+ if (span) {
+ span.innerHTML = ' ' + text;
+ }
+ }
+
add(need: Need) {
- const currentUser = this.usersService.getCurrentUser();
+ const currentUser = this.authService.getCurrentUser();
//console.log("get current user in angular:", currentUser)
if (currentUser) {
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);
- }
- });
+ this.usersService.updateUser(currentUser)
+ .pipe(catchError((err, _) => {
+ console.error(err);
+ return of();
+ }))
+ .subscribe(() => {
+ this.usersService.refreshBasket();
+ });
} else {
- window.alert("This need is already in your basket!")
+ this.toastService.sendToast(ToastType.ERROR, "This need is already in your basket!")
}
-
-
}
-
}
back() {
- this.searchResults = [];
+ this.searchResults = this.needs;
+ }
+
+ select(need : Need) {
+ //emit value
+ this.currentNeed.emit(need);
+ if (this.selectedNeed) {
+ //revert already selected need to previous style
+ console.log(need.id);
+ let button = document.getElementById('need-button-' + this.selectedNeed.id);
+ if (button) {
+ console.log(button)
+ button.style.background = 'lightgray';
+ button.style.marginLeft = '0%';
+ button.style.width = '98%';
+ }
+ button = document.getElementById('need-edit-button-' + this.selectedNeed.id);
+ if (button) {
+ button.style.visibility = 'visible';
+ }
+ }
+ //change selected need to selected style
+ this.selectedNeed = need;
+ let button = document.getElementById('need-button-' + need.id);
+ if (button) {
+ button.style.background = 'white';
+ button.style.marginLeft = '4%';
+ button.style.width = '100%';
+ }
+ button = document.getElementById('need-edit-button-' + need.id);
+ if (button) {
+ button.style.visibility = 'hidden';
+ }
}
}
+function not(location: string) {
+ throw new Error('Function not implemented.');
+}
+
diff --git a/ufund-ui/src/app/components/need-page/need-page.component.css b/ufund-ui/src/app/components/need-page/need-page.component.css
index e69de29..844410f 100644
--- a/ufund-ui/src/app/components/need-page/need-page.component.css
+++ b/ufund-ui/src/app/components/need-page/need-page.component.css
@@ -0,0 +1,73 @@
+:host {
+ display: flex;
+ justify-content: center;
+}
+
+#box {
+ display: flex;
+ flex-direction: column;
+ width: 800px;
+ justify-content: start;
+ gap: 10px;
+}
+
+.needName {
+ font-weight: bold;
+}
+
+.needType {
+ text-transform: uppercase;
+ /*font-size: 10pt;*/
+ margin-top: -20px;
+ /*margin-bottom: 20px;*/
+}
+
+.split {
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+
+
+ .left {
+ display: flex;
+ flex-direction: column;
+ }
+
+ .right {
+ display: flex;
+ flex-direction: column;
+ align-items: end;
+ }
+}
+
+.urgent {
+ font-size: 11pt;
+ background-color: rgba(255, 165, 0, 0.27);
+ color: rgba(255, 165, 0, 1);
+ padding: 2px;
+ border-radius: 5px;
+}
+
+.prog {
+ display: flex;
+ flex-direction: column;
+ margin-bottom: 15px;
+}
+
+.actionArea {
+ display: flex;
+ padding: 5px;
+ gap: 5px;
+ margin-top: 10px;
+}
+
+/*#editor {*/
+/* position: absolute;*/
+/* background-color: #4a4a4a;*/
+/* display: flex;*/
+/* flex-direction: column;*/
+/* justify-self: center;*/
+/* align-self: center;*/
+/* padding: 20px;*/
+/* box-shadow: 0 0 100px black;*/
+/*}*/
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 e9c23bd..958dfa6 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,21 +1,45 @@
-<input type="button" value="Back" (click)="back()">
-<h1>Viewing Need: {{need?.name}}</h1>
-<div style="display: flex; column-gap: 6px;">
- <h3>Looking for</h3>
- <h3><u>{{need?.type}}</u></h3>
- <h3>Donations.</h3>
-</div>
-<div *ngIf="need?.filterAttributes != null">
- <p>Tags:</p>
- <ul style="display: flex; column-gap: 24px;">
- <li *ngFor="let tag of need?.filterAttributes">
- <p>{{tag}}</p>
- </li>
- </ul>
-</div>
+<div id="box">
+ <h1>{{need?.name}}</h1>
+ <span class="needType">{{need?.type}} GOAL</span>
+
+ <img *ngIf="need.image" alt="Need image" [src]="need?.image"/>
+
+ <p>{{need?.description}}</p>
+ <div class="prog">
+<!-- <span>{{need?.current}} / {{need?.maxGoal}}</span>-->
+ <progress [value]="need?.current" [max]="need?.maxGoal"></progress>
+ <span>This goal is <strong>{{(((need?.current ?? 0)*100) / (need?.maxGoal ?? 0)).toFixed(0)}}%</strong> complete!</span>
+ </div>
+
+ <span><strong>Target Goal:</strong> {{need.maxGoal}}</span>
-<hr>
+ <span><strong>Amount Currently Collected:</strong> {{need.current}}</span>
-<p>Goal: {{need?.maxGoal}}</p>
-<p>Current: {{need?.current}}</p>
-<p>This goal is <strong>{{(((need?.current ?? 0)*100) / (need?.maxGoal ?? 0)).toFixed(0)}}%</strong> complete!</p> \ No newline at end of file
+ <span><strong>Location:</strong> {{need.location}}</span>
+
+ <span><strong>Urgency: </strong>
+ <span *ngIf="!need.urgent">Not urgent</span>
+ <span *ngIf="need.urgent" class="urgent">URGENT</span>
+ </span>
+
+ <div *ngIf="need.filterAttributes.length > 0">
+ <strong>Tags:</strong>
+ <ul style="display: flex; column-gap: 24px;">
+ <li *ngFor="let tag of need?.filterAttributes">
+ <p>{{tag}}</p>
+ </li>
+ </ul>
+ </div>
+
+ <div class="actionArea">
+ <button *ngIf="isHelper()" (click)="add(need!)">
+ <span class="icon">add</span>Add To Basket
+ </button>
+<!-- <button *ngIf="isManager()" (click)="edit(need!)">-->
+<!-- <span class="icon">edit</span>Edit Need-->
+<!-- </button>-->
+ <button *ngIf="isManager()" (click)="delete(need!.id)" >
+ <span class="icon">delete</span>Delete Need
+ </button>
+ </div>
+</div>
diff --git a/ufund-ui/src/app/components/need-page/need-page.component.ts b/ufund-ui/src/app/components/need-page/need-page.component.ts
index 597d0e0..ad4cacf 100644
--- a/ufund-ui/src/app/components/need-page/need-page.component.ts
+++ b/ufund-ui/src/app/components/need-page/need-page.component.ts
@@ -1,31 +1,87 @@
import {Component, Input} from '@angular/core';
import {GoalType, Need} from '../../models/Need';
-import {ActivatedRoute} from "@angular/router";
+import {ActivatedRoute, Router} from "@angular/router";
import {CupboardService} from "../../services/cupboard.service";
-import { NgFor } from '@angular/common';
+import {userType} from '../../models/User';
+import {AuthService} from '../../services/auth.service';
+import {catchError, of} from 'rxjs';
+import {ToastsService, ToastType} from '../../services/toasts.service';
+import {UsersService} from '../../services/users.service';
@Component({
- selector: 'app-need-page',
- standalone: false,
- templateUrl: './need-page.component.html',
- styleUrl: './need-page.component.css'
+ selector: 'app-need-page',
+ standalone: false,
+ templateUrl: './need-page.component.html',
+ styleUrl: './need-page.component.css'
})
export class NeedPageComponent {
- constructor(
- private route: ActivatedRoute,
- private cupboardService: CupboardService,
- ) {}
+ constructor(
+ private route: ActivatedRoute,
+ private cupboardService: CupboardService,
+ private authService: AuthService,
+ private usersService: UsersService,
+ private toastService: ToastsService,
+ private router: Router
+ ) {}
- public GoalType = GoalType;
+ public GoalType = GoalType;
- @Input() need?: Need;
+ @Input() need!: Need;
- ngOnInit(): void {
- const id = Number(this.route.snapshot.paramMap.get('id'));
- this.cupboardService.getNeed(id).subscribe(n => this.need = n);
- }
+ ngOnInit(): void {
+ const id = Number(this.route.snapshot.paramMap.get('id'));
+ this.cupboardService.getNeed(id).subscribe(n => this.need = n);
+ }
- back() {
- window.history.back();
- }
-} \ No newline at end of file
+ back() {
+ window.history.back();
+ }
+
+ isManager() {
+ const type = this.authService.getCurrentUser()?.type;
+ return type === ("MANAGER" as unknown as userType);
+ }
+
+ isHelper() {
+ const type = this.authService.getCurrentUser()?.type;
+ return type === ("HELPER" as unknown as userType);
+ }
+
+ add(need: Need) {
+ const currentUser = this.authService.getCurrentUser();
+ //console.log("get current user in angular:", currentUser)
+ if (currentUser) {
+ if (!currentUser.basket.includes(need.id)) {
+ currentUser.basket.push(need.id);
+ this.usersService.updateUser(currentUser)
+ .pipe(catchError((err, _) => {
+ console.error(err);
+ return of();
+ }))
+ .subscribe(() => {
+ this.usersService.refreshBasket();
+ });
+ } else {
+ this.toastService.sendToast(ToastType.ERROR, "This need is already in your basket!")
+ }
+ }
+ }
+
+ delete(id : number) {
+ this.cupboardService.deleteNeed(id)
+ .pipe(catchError((ex, r) => {
+ this.toastService.sendToast(ToastType.ERROR, ex.error)
+ return of()
+ }))
+ .subscribe(() => {
+ // this.needs = this.needs.filter(n => n.id !== id)
+ this.toastService.sendToast(ToastType.INFO, "Need deleted")
+ this.router.navigate(['/'])
+ })
+ // this.refresh();
+ }
+
+ edit(need: Need) {
+
+ }
+}
diff --git a/ufund-ui/src/app/components/signup/signup.component.css b/ufund-ui/src/app/components/signup/signup.component.css
new file mode 100644
index 0000000..429bc42
--- /dev/null
+++ b/ufund-ui/src/app/components/signup/signup.component.css
@@ -0,0 +1,73 @@
+:host {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ height: 100%;
+ margin-top: -66px
+
+}
+
+#box {
+ display: flex;
+ flex-direction: column;
+ /*max-width: 300px;*/
+ gap: 10px;
+
+ & > div {
+ display: flex;
+ flex-direction: column;
+ }
+}
+
+.border {
+ border-style: solid;
+ border-width: 1px;
+ padding: 10px;
+ margin: 10px;
+ position: absolute;
+ background-color: white;
+ box-shadow: 0 0 10px 10px black;
+}
+
+#bar {
+ height: 5px;
+ width: 100%;
+ appearance: none;
+ overflow: hidden;
+ /*margin-top: -5px;*/
+}
+
+#bar::-webkit-progress-bar {
+ background-color: lightgray;
+ transition: width 0.5s ease-in-out, background-color 0.5s ease-in-out;
+}
+
+.color0::-webkit-progress-value { background: rgba(255, 0 ,0, 1); transition: background-color 0.5s ease-in-out, width 0.5s ease-in-out; }
+.color1::-webkit-progress-value { background: rgba(255, 0 ,0, 1); transition: background-color 0.5s ease-in-out, width 0.5s ease-in-out; }
+.color2::-webkit-progress-value { background: rgba(255, 165, 0, 1); transition: background-color 0.5s ease-in-out, width 0.5s ease-in-out; }
+.color3::-webkit-progress-value { background: rgba(255, 255, 0, 1); transition: background-color 0.5s ease-in-out, width 0.5s ease-in-out; }
+.color4::-webkit-progress-value { background: rgba(173, 255, 47, 1); transition: background-color 0.5s ease-in-out, width 0.5s ease-in-out; }
+.color5::-webkit-progress-value { background: rgba(50, 205, 50, 1); transition: background-color 0.5s ease-in-out, width 0.5s ease-in-out; }
+.color6::-webkit-progress-value { background: rgba(0, 128, 0, 1); transition: background-color 0.5s ease-in-out, width 0.5s ease-in-out; }
+
+#requirement2, #statusText, #passwordStatusText, #usernameStatusText {
+ color: red;
+}
+
+#passReq {
+ display: flex;
+ flex-direction: column;
+}
+
+#box > div {
+ display: flex;
+ flex-direction: row;
+ align-items: start;
+ gap: 20px;
+
+ div {
+ display: flex;
+ flex-direction: column;
+ }
+}
+
diff --git a/ufund-ui/src/app/components/signup/signup.component.html b/ufund-ui/src/app/components/signup/signup.component.html
new file mode 100644
index 0000000..bc3aaf0
--- /dev/null
+++ b/ufund-ui/src/app/components/signup/signup.component.html
@@ -0,0 +1,31 @@
+<div id="box">
+ <h1>Create an account</h1>
+ <div>
+ <input placeholder="Username" type="text" (input)="validate(username.value, confirmPass.value, password.value)" #username>
+ <span *ngIf="usernameStatusText">{{usernameStatusText | async}}</span>
+ </div>
+
+ <div>
+ <div>
+ <input placeholder="Password" type="password" (input)="validate(username.value, confirmPass.value, password.value)" #password>
+ <progress [ngClass]="'color' + strength.getValue()" id="bar" [value]="strength | async" max="6"> </progress>
+ <span *ngIf="passwordStatusText">{{passwordStatusText | async}}</span>
+ </div>
+
+ <div id="passReq">
+ <span *ngFor="let requirement of Object.values(passwordRequirements)" [style.color]="requirement.value ? 'green' : 'red'"><span class="icon">{{requirement.value?"check":"close"}}</span> {{requirement.title}}</span>
+ </div>
+ </div>
+
+ <div>
+ <input placeholder="Confirm password" type="password" (input)="validate(username.value, confirmPass.value, password.value)" #confirmPass>
+ <span [style.color]="(passwordsMatch|async) ? 'green' : 'red'" *ngIf="passwordsMatch"><span class="icon">{{(passwordsMatch|async)?"check":"close"}}</span> Passwords match</span>
+ </div>
+
+ <div>
+ <button [disabled]="!(ableToCreateAccount | async)" (click)="signup(username.value, password.value)">Create Account</button>
+ <span *ngIf="showSuccessMessage | async">Account created <a routerLink="/login">Proceed to login</a></span>
+ <span *ngIf="statusText | async">{{statusText | async}}</span>
+ </div>
+ <span>Already have an account? <a routerLink="/login">Log in</a></span>
+</div>
diff --git a/ufund-ui/src/app/components/signup/signup.component.ts b/ufund-ui/src/app/components/signup/signup.component.ts
new file mode 100644
index 0000000..a20d828
--- /dev/null
+++ b/ufund-ui/src/app/components/signup/signup.component.ts
@@ -0,0 +1,167 @@
+import {Component} from '@angular/core';
+import {UsersService} from '../../services/users.service';
+import {Router} from '@angular/router';
+import {BehaviorSubject} from 'rxjs';
+import {ToastsService, ToastType} from '../../services/toasts.service';
+
+class PasswordRequirements {
+ sixLong: {title: string, value: boolean} = {title: 'Is 6 characters or longer' , value: false}
+ twelveLong: {title: string, value: boolean} = {title: 'Is 12 characters or longer', value: false}
+ lowercase: {title: string, value: boolean} = {title: 'Includes lowercase letter' , value: false}
+ uppercase: {title: string, value: boolean} = {title: 'Includes uppercase letter' , value: false}
+ number: {title: string, value: boolean} = {title: 'Includes number' , value: false}
+ symbol: {title: string, value: boolean} = {title: 'Includes symbol' , value: false}
+}
+
+@Component({
+ selector: 'app-signup',
+ standalone: false,
+ templateUrl: './signup.component.html',
+ styleUrl: './signup.component.css'
+})
+
+export class SignupComponent {
+
+ protected passwordStatusText = new BehaviorSubject("")
+ protected passwordsMatch = new BehaviorSubject(false)
+ protected usernameStatusText = new BehaviorSubject("")
+ protected showSuccessMessage = new BehaviorSubject(false)
+ protected passwordStrongEnough = new BehaviorSubject(false)
+ protected ableToCreateAccount = new BehaviorSubject(false)
+ protected passwordRequirements: PasswordRequirements = new PasswordRequirements()
+ protected strength = new BehaviorSubject(0)
+ protected statusText = new BehaviorSubject("");
+
+ constructor(
+ protected usersService: UsersService,
+ protected router: Router,
+ protected toastService: ToastsService
+ ) {}
+
+ signup(username: string | null, password: string | null) {
+ console.log(`attempting to sign up with ${username} ${password}`)
+ if (!username || !password) {
+ return;
+ }
+
+ this.usersService.createUser(username, password).then(() => {
+ this.showSuccessMessage.next(true);
+ }).catch(ex => {
+ this.toastService.sendToast(ToastType.ERROR, "Unable to create account: " + friendlyHttpStatus[ex.status])
+ console.log(ex)
+ })
+ }
+
+ validate(username: string, passConfirm:string, password: string) {
+ this.passwordsMatch.next(false)
+ this.usernameStatusText.next("")
+ this.checkPasswordStrength(password);
+
+ if (username === "") {
+ this.usernameStatusText.next("Username field can't be blank")
+ }
+
+ if (passConfirm && password === passConfirm) {
+ this.passwordsMatch.next(true)
+ }
+ this.ableToCreateAccount.next(this.passwordStrongEnough.getValue() && password === passConfirm && !!username)
+ }
+
+ checkPasswordStrength(password: string) {
+ this.strength.next(0)
+ this.passwordRequirements = new PasswordRequirements()
+ this.passwordStrongEnough.next(false)
+
+ if (password.match(/[^!-~]/g)) {
+ this.passwordStatusText.next("Invalid characters")
+
+ return
+ }
+
+ if (password.length > 6) {
+ this.passwordRequirements.sixLong.value = true
+ }
+ if (password.length > 12) {
+ this.passwordRequirements.twelveLong.value = true
+ }
+ if (password.match(/[a-z]/g)) {
+ this.passwordRequirements.lowercase.value = true
+ }
+ if (password.match(/[A-Z]/g)) {
+ this.passwordRequirements.uppercase.value = true
+ }
+ if (password.match(/[0-9]/g)) {
+ this.passwordRequirements.number.value = true
+ }
+ if (password.match(/[^A-Za-z0-9]/g)) {
+ this.passwordRequirements.symbol.value = true
+ }
+
+ let strength = 0
+ Object.values(this.passwordRequirements).forEach(k => {
+ k.value && strength++
+ })
+
+ if (strength >= 5) {
+ this.passwordStrongEnough.next(true)
+ this.passwordStatusText.next("")
+ } else if (strength == 0) {
+ this.passwordStatusText.next("")
+ } else {
+ this.passwordStatusText.next("5/6 checks required")
+ }
+
+ this.strength.next(strength)
+ }
+
+ getColor() {
+ return `rgba(${(this.strength.getValue()/7) * 255}, ${255 - (this.strength.getValue()/7) * 255}, 0)`
+ }
+
+ protected readonly length = length;
+ protected readonly Object = Object;
+}
+
+let friendlyHttpStatus: {[key: number]: string} = {
+ 200: 'OK',
+ 201: 'Created',
+ 202: 'Accepted',
+ 203: 'Non-Authoritative Information',
+ 204: 'No Content',
+ 205: 'Reset Content',
+ 206: 'Partial Content',
+ 300: 'Multiple Choices',
+ 301: 'Moved Permanently',
+ 302: 'Found',
+ 303: 'See Other',
+ 304: 'Not Modified',
+ 305: 'Use Proxy',
+ 306: 'Unused',
+ 307: 'Temporary Redirect',
+ 400: 'Bad Request',
+ 401: 'Unauthorized',
+ 402: 'Payment Required',
+ 403: 'Forbidden',
+ 404: 'Not Found',
+ 405: 'Method Not Allowed',
+ 406: 'Not Acceptable',
+ 407: 'Proxy Authentication Required',
+ 408: 'Request Timeout',
+ 409: 'Conflict',
+ 410: 'Gone',
+ 411: 'Length Required',
+ 412: 'Precondition Required',
+ 413: 'Request Entry Too Large',
+ 414: 'Request-URI Too Long',
+ 415: 'Unsupported Media Type',
+ 416: 'Requested Range Not Satisfiable',
+ 417: 'Expectation Failed',
+ 418: 'I\'m a teapot',
+ 429: 'Too Many Requests',
+ 500: 'Internal Server Error',
+ 501: 'Not Implemented',
+ 502: 'Bad Gateway',
+ 503: 'Service Unavailable',
+ 504: 'Gateway Timeout',
+ 505: 'HTTP Version Not Supported',
+};
diff --git a/ufund-ui/src/app/components/toast/toast.component.css b/ufund-ui/src/app/components/toast/toast.component.css
new file mode 100644
index 0000000..4cd81fe
--- /dev/null
+++ b/ufund-ui/src/app/components/toast/toast.component.css
@@ -0,0 +1,57 @@
+:host {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+}
+
+@keyframes slideDown {
+ from {transform: translateY(-90px);}
+ to {transform: translateY(0);}
+}
+
+.toast {
+ /*transform: translateY(-90px);*/
+ animation: slideDown .5s ease-in-out;
+ transition: transform .5s;
+ align-self: center;
+ z-index: 3;
+ position: absolute;
+ top: 15px;
+ display: flex;
+ flex-direction: row;
+ padding: 3px 15px;
+ background-color: #3a3a3a;
+ border-radius: 100000px;
+ gap: 10px;
+ align-items: center;
+
+ button {
+ aspect-ratio: 1/1;
+ margin-right: -11px;
+ padding: 8px;
+ display: flex;
+ align-items: center;
+ background-color: transparent;
+ }
+
+ button:hover {
+ background-color: rgba(255, 255, 255, 0.1);
+ }
+}
+
+.toast.hide {
+ transform: translateY(-90px);
+}
+
+.toast.warning {
+ background-color: #ffc500;
+ color: black;
+
+ button {
+ color: black;
+ }
+}
+
+.toast.error {
+ background-color: #d81a1a;
+}
diff --git a/ufund-ui/src/app/components/toast/toast.component.html b/ufund-ui/src/app/components/toast/toast.component.html
new file mode 100644
index 0000000..dccf869
--- /dev/null
+++ b/ufund-ui/src/app/components/toast/toast.component.html
@@ -0,0 +1,7 @@
+<div class="toast" [ngClass]="ToastType[type].toLowerCase()" #toastDiv>
+ <span>{{this.message}}</span>
+ <a *ngIf="this.action" (click)="this.action.onAction()">{{this.action.label}}</a>
+ <button (click)="hide()">
+ <span class="icon">close</span>
+ </button>
+</div>
diff --git a/ufund-ui/src/app/components/toast/toast.component.ts b/ufund-ui/src/app/components/toast/toast.component.ts
new file mode 100644
index 0000000..47fd7ff
--- /dev/null
+++ b/ufund-ui/src/app/components/toast/toast.component.ts
@@ -0,0 +1,37 @@
+import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
+import {ToastType} from '../../services/toasts.service';
+
+@Component({
+ selector: 'app-toast',
+ standalone: false,
+ templateUrl: './toast.component.html',
+ styleUrl: './toast.component.css'
+})
+export class ToastComponent implements OnInit{
+ @Input() type!: ToastType
+ @Input() message!: string
+ @Input() action?: {label: string, onAction: () => void}
+
+ @ViewChild("toastDiv") toastDiv!: ElementRef<HTMLDivElement>
+
+ ngOnInit() {
+ setTimeout(() => {
+ this.hide();
+ }, 3000)
+ }
+
+ hide() {
+ console.log(this.toastDiv, typeof this.toastDiv)
+ this.toastDiv.nativeElement.classList.add('hide')
+ }
+
+ getColor() {
+ switch (this.type) {
+ case ToastType.ERROR: return "red";
+ case ToastType.INFO: return "";
+ case ToastType.WARNING: return "yellow";
+ }
+ }
+
+ protected readonly ToastType = ToastType;
+}
diff --git a/ufund-ui/src/app/models/Need.ts b/ufund-ui/src/app/models/Need.ts
index 9e97fd4..6cf7e76 100644
--- a/ufund-ui/src/app/models/Need.ts
+++ b/ufund-ui/src/app/models/Need.ts
@@ -1,13 +1,17 @@
export interface Need {
- name: string,
- id: number,
- filterAttributes: string[],
- type: GoalType;
- maxGoal: number;
- current: number;
+ name: string,
+ image: string,
+ id: number,
+ filterAttributes: string[],
+ location: string;
+ type: GoalType;
+ maxGoal: number;
+ current: number;
+ urgent: boolean;
+ description: string;
}
export enum GoalType {
- MONETARY,
- PHYSICAL
+ MONETARY,
+ PHYSICAL
}
diff --git a/ufund-ui/src/app/models/User.ts b/ufund-ui/src/app/models/User.ts
index f4396f6..e6848fa 100644
--- a/ufund-ui/src/app/models/User.ts
+++ b/ufund-ui/src/app/models/User.ts
@@ -1,5 +1,3 @@
-import {Need} from './Need';
-
export enum userType {
HELPER,
MANAGER
diff --git a/ufund-ui/src/app/services/auth.service.ts b/ufund-ui/src/app/services/auth.service.ts
new file mode 100644
index 0000000..b75c931
--- /dev/null
+++ b/ufund-ui/src/app/services/auth.service.ts
@@ -0,0 +1,67 @@
+import {Injectable, Injector} from '@angular/core';
+import {BehaviorSubject, firstValueFrom} from 'rxjs';
+import {User} from '../models/User';
+import {HttpClient, HttpHeaders} from '@angular/common/http';
+import {UsersService} from './users.service';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class AuthService {
+
+ private authUrl = "http://localhost:8080/auth"
+ private userUrl = "http://localhost:8080/users"
+
+ private currentUser : BehaviorSubject<User | null> = new BehaviorSubject<User | null>(null);
+ private apiKey: string = "";
+
+ httpOptions2 = () => ({
+ headers: new HttpHeaders({
+ 'Content-Type': 'application/json',
+ "jelly-api-key": this.apiKey
+ }),
+ responseType: "text" as "json" // don't ask me how or why this works, bc i have no clue...
+ // see the relevant angular bug report https://github.com/angular/angular/issues/18586
+ });
+
+ constructor(
+ private http: HttpClient,
+ // private userService: UsersService
+ private injector: Injector
+ ) {}
+
+ async login(username: string, password: string) {
+ let res = this.http.post<string>(this.authUrl, {username: username, password: password}, this.httpOptions2());
+ this.apiKey = await firstValueFrom(res);
+ console.log("apikey: "+this.apiKey)
+ let res2 = this.http.get<User>(`${this.userUrl}/${username}`, {
+ headers: new HttpHeaders({
+ 'Content-Type': 'application/json',
+ "jelly-api-key": this.apiKey
+ })
+ })
+ let currentU = await firstValueFrom(res2);
+ this.currentUser.next(currentU);
+ // this.currentUser.subscribe(r => console.log("currentUser: "+r.username))
+ }
+
+ async restoreLogin(username: string, key: string) {
+
+ const userService = this.injector.get(UsersService);
+ this.apiKey = key;
+ this.currentUser.next(await firstValueFrom(userService.getUser(username)))
+ }
+
+ getCurrentUserSubject() {
+ return this.currentUser;
+ }
+
+ getCurrentUser() {
+ return this.currentUser.getValue()
+ }
+
+ getApiKey() {
+ return this.apiKey;
+ }
+
+}
diff --git a/ufund-ui/src/app/services/cupboard.service.ts b/ufund-ui/src/app/services/cupboard.service.ts
index 9e14106..9232c0c 100644
--- a/ufund-ui/src/app/services/cupboard.service.ts
+++ b/ufund-ui/src/app/services/cupboard.service.ts
@@ -2,6 +2,7 @@ import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Need} from '../models/Need';
import {Observable} from 'rxjs';
+import {AuthService} from './auth.service';
@Injectable({
providedIn: 'root'
@@ -9,35 +10,44 @@ import {Observable} from 'rxjs';
export class CupboardService {
private url = "http://localhost:8080/cupboard"
- private httpOptions = {
- headers: new HttpHeaders({'Content-Type': 'application/json'})
- };
+
+ httpOptions = () => ({
+ headers: new HttpHeaders({
+ 'Content-Type': 'application/json',
+ "jelly-api-key": this.authService.getApiKey()
+ })
+ });
constructor(
- private http: HttpClient
+ private http: HttpClient,
+ private authService: AuthService
) {}
createNeed(need: Need): Observable<boolean> {
- return this.http.post<boolean>(this.url, need, this.httpOptions)
+ return this.http.post<boolean>(this.url, need, this.httpOptions())
}
getNeeds(): Observable<Need[]> {
- return this.http.get<Need[]>(this.url, this.httpOptions)
+ return this.http.get<Need[]>(this.url, this.httpOptions())
}
searchNeeds(name: String): Observable<Need[]> {
- return this.http.get<Need[]>(`${this.url}/?name=${name}`, this.httpOptions)
+ return this.http.get<Need[]>(`${this.url}/?name=${name}`, this.httpOptions())
}
getNeed(id: number): Observable<Need> {
- return this.http.get<Need>(`${this.url}/${id}`, this.httpOptions)
+ return this.http.get<Need>(`${this.url}/${id}`, this.httpOptions())
}
updateNeed(id: number, data: Need): Observable<boolean> {
- return this.http.put<boolean>(`${this.url}/${id}`, data, this.httpOptions)
+ return this.http.put<boolean>(`${this.url}/${id}`, data, this.httpOptions())
}
deleteNeed(id: number): Observable<boolean> {
- return this.http.delete<boolean>(`${this.url}/${id}`, this.httpOptions)
+ return this.http.delete<boolean>(`${this.url}/${id}`, this.httpOptions())
+ }
+
+ checkoutNeed(id: number, quantity: number) {
+ return this.http.put(`${this.url}/checkout`, {needID: id, amount: quantity}, this.httpOptions())
}
}
diff --git a/ufund-ui/src/app/services/toasts.service.ts b/ufund-ui/src/app/services/toasts.service.ts
new file mode 100644
index 0000000..4fd024e
--- /dev/null
+++ b/ufund-ui/src/app/services/toasts.service.ts
@@ -0,0 +1,27 @@
+import {Injectable, ViewContainerRef} from '@angular/core';
+import {ToastComponent} from '../components/toast/toast.component';
+
+export enum ToastType {
+ INFO,
+ WARNING,
+ ERROR
+}
+
+@Injectable({
+ providedIn: 'root'
+})
+export class ToastsService {
+
+ private vcr?: ViewContainerRef
+
+ sendToast(type: ToastType, message: string, action?: {label: string, onAction: () => void}) {
+ let compRef = this.vcr?.createComponent(ToastComponent)!
+ compRef.setInput("message", message)
+ compRef.setInput("type", type)
+ compRef.setInput("action", action)
+ }
+
+ setRootViewContainerRef(vcr: ViewContainerRef) {
+ this.vcr = vcr
+ }
+}
diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts
index dba8185..4080ebf 100644
--- a/ufund-ui/src/app/services/users.service.ts
+++ b/ufund-ui/src/app/services/users.service.ts
@@ -1,96 +1,69 @@
import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
-import {BehaviorSubject, firstValueFrom, Observable} from 'rxjs';
+import {BehaviorSubject, catchError, firstValueFrom, Observable, of} from 'rxjs';
import {User} from '../models/User';
import { Need } from '../models/Need';
import { CupboardService } from './cupboard.service';
+import {AuthService} from './auth.service';
@Injectable({
providedIn: 'root'
})
export class UsersService {
- private currentUser : BehaviorSubject<User | null> = new BehaviorSubject<User | null>(null);
- private apiKey: string = "";
private basket = new BehaviorSubject<Need[]>([]);
-
private url = "http://localhost:8080/users"
- private authUrl = "http://localhost:8080/auth"
- private httpOptions = {
+
+ httpOptions = () => ({
headers: new HttpHeaders({
'Content-Type': 'application/json',
- "jelly-api-key": this.apiKey
+ "jelly-api-key": this.authService.getApiKey()
})
- };
- private httpOptions2 = {
- headers: new HttpHeaders({
- 'Content-Type': 'application/json',
- "jelly-api-key": this.apiKey
- }),
- responseType: "text" as "json" // don't ask me how or why this works, bc i have no clue...
- // see the relevant angular bug report https://github.com/angular/angular/issues/18586
- };
+ });
constructor(
private http: HttpClient,
private cupboardService: CupboardService,
+ private authService: AuthService
) {}
async createUser(username:string, password:string) {
- await firstValueFrom(this.http.post<User>(this.url, {username: username, password: password}, this.httpOptions))
+ await firstValueFrom(this.http.post<User>(this.url, {username: username, password: password}, this.httpOptions()))
}
getUser(id: string): Observable<User> {
- return this.http.get<User>(`${this.url}/${id}`, this.httpOptions)
+ return this.http.get<User>(`${this.url}/${id}`, this.httpOptions())
}
updateUser(user: User): Observable<User> {
- return this.http.put<User>(`${this.url}/${user.username}`,user, this.httpOptions2)
+ console.log(`${this.url}/${user.username}`, user, this.httpOptions)
+ return this.http.put<User>(`${this.url}/${user.username}`, user, this.httpOptions())
}
deleteUser(id: number): Observable<boolean> {
- return this.http.delete<boolean>(`${this.url}/${id}`, this.httpOptions)
- }
-
- getCurrentUserSubject() {
- return this.currentUser;
- }
-
- getCurrentUser() {
- return this.currentUser.getValue()
- }
-
- async login(username: string, password: string) {
- let res = this.http.post<string>(this.authUrl, {username: username, password: password}, this.httpOptions2);
- this.apiKey = await firstValueFrom(res);
- console.log("apikey: "+this.apiKey)
- let res2 = this.http.get<User>(`${this.url}/${username}`, {
- headers: new HttpHeaders({
- 'Content-Type': 'application/json',
- "jelly-api-key": this.apiKey
- })
- })
- let currentU = await firstValueFrom(res2);
- this.currentUser.next(currentU);
- // this.currentUser.subscribe(r => console.log("currentUser: "+r.username))
+ return this.http.delete<boolean>(`${this.url}/${id}`, this.httpOptions())
}
refreshBasket() {
- let promiseArr = this.getCurrentUser()!.basket.map(async needID => {
+ let promiseArr = this.authService.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()!).subscribe(() => {
+ this.authService.getCurrentUser()!.basket = newArr.map(need => need.id);
+ this.updateUser(this.authService.getCurrentUser()!)
+ .pipe(
+ catchError((err: any, _) => {
+ console.error(err);
+ return of();
+ })
+ )
+ .subscribe(() => {
this.refreshBasket();
- error: (err: any) => {
- console.error(err);
- }
});
}
diff --git a/ufund-ui/src/index.html b/ufund-ui/src/index.html
index 0517d5e..b6ae1a2 100644
--- a/ufund-ui/src/index.html
+++ b/ufund-ui/src/index.html
@@ -1,13 +1,17 @@
<!doctype html>
<html lang="en">
<head>
- <meta charset="utf-8">
- <title>UfundUi</title>
- <base href="/">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="icon" type="image/x-icon" href="favicon.ico">
+ <meta charset="utf-8">
+ <title>UfundUi</title>
+ <base href="/">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="icon" type="image/x-icon" href="favicon.ico">
+ <link rel="preconnect" href="https://fonts.googleapis.com">
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
+ <link href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap" rel="stylesheet">
+ <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" rel="stylesheet" />
</head>
<body>
- <app-root></app-root>
+<app-root></app-root>
</body>
</html>
diff --git a/ufund-ui/src/styles.css b/ufund-ui/src/styles.css
index 90d4ee0..75d6b36 100644
--- a/ufund-ui/src/styles.css
+++ b/ufund-ui/src/styles.css
@@ -1 +1,71 @@
/* You can add global styles to this file, and also import other style files */
+
+:root {
+ color-scheme: /*light*/ dark;
+}
+
+* {
+ box-sizing: border-box;
+}
+
+html, body {
+ margin: 0;
+ height: 100%;
+ background-color: light-dark(white, #000715);
+}
+
+body {
+ font-family: Inter, sans-serif;
+ font-optical-sizing: auto;
+}
+
+input {
+ font-size: 14pt;
+ padding: 5px;
+ border-radius: 5px;
+ border-style: solid;
+ border-width: 1px;
+ background-color: light-dark(#ebebeb, #3a3a3a);
+
+ &:hover {
+ background-color: light-dark(#e1e1e1, #444444);
+ }
+}
+
+button, input[type=button], input[type=reset], input[type=submit], .button {
+ font-size: 14pt;
+ padding: 6px 16px;
+ border-radius: 9999px;
+ border-style: none;
+ background-color: light-dark(#ebebeb, #3a3a3a);
+ display: flex;
+ gap: 5px;
+ text-align: center;
+ justify-content: center;
+
+ &:hover {
+ background-color: light-dark(#e1e1e1, #444444);
+ }
+}
+
+.button2 {
+ text-transform: uppercase;
+ border: 1px solid #5cdbff;
+ padding: 10px 25px;
+ font-size: 12pt;
+ font-weight: 600;
+ background-color: transparent;
+ text-shadow: #5cdbff 0 0 50px;
+}
+
+.icon {
+ font-family: 'Material Symbols Outlined'
+}
+
+h1 {
+ font-size: 40px;
+}
+
+progress {
+ min-width: 100%;
+}