From 8ec987f46b4ef3ff1ce23d9942662a74e162689d Mon Sep 17 00:00:00 2001 From: benal01 Date: Thu, 20 Mar 2025 09:58:32 -0400 Subject: need-list search embedded in normal display with better feedback --- .../components/need-list/need-list.component.css | 2 +- .../components/need-list/need-list.component.html | 23 ++++----- .../components/need-list/need-list.component.ts | 60 +++++++++++----------- 3 files changed, 41 insertions(+), 44 deletions(-) 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..88bdfbe 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 @@ -15,7 +15,7 @@ li, div { } -#search-form { +#search-container { background-color: #d9d9d9; padding: 10px 20px 20px 20px; border: 2px solid #000; 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..504deb9 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,25 +1,20 @@

Needs List

-
-
+
+
-
+
-
-

Search Results:

-
- - {{need.name}} - - - -
-
-
  • + +

    Search Results({{needs.length - searchResults.length}} needs filtered):

    +

    All Needs

    +

    No Results Found

    + +
  • {{need.name}} diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index 25f05d6..f5d7855 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,4 +1,5 @@ import { Component } from '@angular/core'; +import { NgForm } from '@angular/forms'; import {Need} from '../../models/Need'; import {CupboardService} from '../../services/cupboard.service'; import { UsersService } from '../../services/users.service'; @@ -19,12 +20,16 @@ export class NeedListComponent { ) {} refresh() { - this.cupboardService.getNeeds().subscribe(n => this.needs = n) + this.cupboardService.getNeeds().subscribe(n => { + this.needs = n; + this.searchResults = this.needs; + }); + + console.log(this.searchResults); } ngOnInit(): void { this.refresh() - this.close(); } @@ -42,20 +47,13 @@ export class NeedListComponent { } } - private updateSearchStatus(text: string) { - let element = document.getElementById('search-status'); - if (element) { - element.innerHTML = text; - } - } - open() { this.hideElement(document.getElementById('search-button')); - this.showElement(document.getElementById('search-form')); + this.showElement(document.getElementById('search-container')); } close() { - this.hideElement(document.getElementById('search-form')); + this.hideElement(document.getElementById('search-container')); this.showElement(document.getElementById('search-button')); this.hideElement(document.getElementById('search-status')); } @@ -69,24 +67,28 @@ export class NeedListComponent { if (this.searchDelay) { clearTimeout(this.searchDelay); } + if (form) { + this.searchDelay = setTimeout(() => { + + if (form) { + 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')); + }); + } + }, 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; + } + - 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); + } delete(id : number) { @@ -127,6 +129,6 @@ export class NeedListComponent { } back() { - this.searchResults = []; + this.searchResults = this.needs; } } -- cgit v1.2.3 From 237b9197c08c46a11fe45347e2d41428a558f75b Mon Sep 17 00:00:00 2001 From: benal01 Date: Thu, 20 Mar 2025 10:18:43 -0400 Subject: component style refactor for simpler display --- .../app/components/cupboard/cupboard.component.css | 20 +++- .../components/cupboard/cupboard.component.html | 101 +++++++++++---------- .../app/components/cupboard/cupboard.component.ts | 2 - 3 files changed, 69 insertions(+), 54 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index fe4971a..4c6ac4b 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -1,18 +1,30 @@ :host { - display: block; + display: flex; + justify-content: left; border: 2px solid #000; border-radius: 5px; padding: 10px 20px; } +#menu { + display: flex; + justify-content: space-between; + margin: 10px; + * { + border: 3px solid #000; + + border-top-left-radius: 5px; + border-top-right-radius: 5px; + margin-right: 5px; + border-bottom: 0px; + } +} -#menu, #create-form, #delete-form, #update-form { +#create-form, #delete-form, #update-form { background-color: #d9d9d9; padding: 10px 20px 20px 20px; border: 2px solid #000; border-radius: 5px; - width: 20%; visibility: visible; - } #create-button { diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 0d64475..4577844 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -1,50 +1,55 @@ -

    Cupboard

    -

    Admin View

    -
  • -- cgit v1.2.3 From 5eef7755f799d0f4fffad88dd05f18459c206253 Mon Sep 17 00:00:00 2001 From: benal01 Date: Fri, 21 Mar 2025 10:18:32 -0400 Subject: gitignore --- ufund-api/.gitignore | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 -- cgit v1.2.3 From 0ba69e502b89ed2d8fe51b3b8b40eb8fba5830e1 Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 21 Mar 2025 23:11:37 -0400 Subject: start making some css --- ufund-ui/src/app/app.component.css | 19 +++++++++++++++++++ ufund-ui/src/app/app.component.html | 19 +++++++++++++++---- ufund-ui/src/styles.css | 12 ++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/ufund-ui/src/app/app.component.css b/ufund-ui/src/app/app.component.css index e69de29..b2dfb87 100644 --- a/ufund-ui/src/app/app.component.css +++ b/ufund-ui/src/app/app.component.css @@ -0,0 +1,19 @@ +#header { + display: flex; + flex-direction: row; + justify-content: space-between; + border-bottom: black solid 1px; + padding: 0 10px; + background-color: #d9d9d9; + + h1 { + padding: 0; + margin: 0; + } + + div { + display: flex; + align-items: center; + gap: 10px; + } +} diff --git a/ufund-ui/src/app/app.component.html b/ufund-ui/src/app/app.component.html index a490237..3058117 100644 --- a/ufund-ui/src/app/app.component.html +++ b/ufund-ui/src/app/app.component.html @@ -1,6 +1,17 @@ - -

    jelly solutions

    -{{currentUser$ | async}}
    -
    + diff --git a/ufund-ui/src/styles.css b/ufund-ui/src/styles.css index 90d4ee0..471f272 100644 --- a/ufund-ui/src/styles.css +++ b/ufund-ui/src/styles.css @@ -1 +1,13 @@ /* You can add global styles to this file, and also import other style files */ + +* { + box-sizing: border-box; +} + +html, body { + margin: 0; +} + +body { + font-family: sans-serif; +} -- cgit v1.2.3 From 0be2b5868bdda04146a22ec81596dbbb81922360 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sat, 22 Mar 2025 00:04:40 -0400 Subject: improve login page --- ufund-ui/src/app/app.component.css | 7 ++++++- .../src/app/components/login/login.component.css | 22 +++++++++++++++++----- .../src/app/components/login/login.component.html | 16 +++++++++------- ufund-ui/src/styles.css | 9 +++++++++ 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/ufund-ui/src/app/app.component.css b/ufund-ui/src/app/app.component.css index b2dfb87..63608c0 100644 --- a/ufund-ui/src/app/app.component.css +++ b/ufund-ui/src/app/app.component.css @@ -1,10 +1,15 @@ +:host { + display: flex; + flex-direction: column; + height: 100%; +} + #header { display: flex; flex-direction: row; justify-content: space-between; border-bottom: black solid 1px; padding: 0 10px; - background-color: #d9d9d9; h1 { padding: 0; diff --git a/ufund-ui/src/app/components/login/login.component.css b/ufund-ui/src/app/components/login/login.component.css index 435cc87..cae0992 100644 --- a/ufund-ui/src/app/components/login/login.component.css +++ b/ufund-ui/src/app/components/login/login.component.css @@ -1,8 +1,20 @@ -: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"); +} + +#box { + display: flex; + flex-direction: column; + max-width: 330px; + gap: 5px; + backdrop-filter: blur(10px); + background-color: rgba(0, 0, 0, 0.1); + padding: 30px; + color: white; } .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..aff108f 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 @@ -You must be logged in to view this page -

    Login:

    - - - - -{{statusText | async}} +
    + You must be logged in to view this page +

    Login:

    + + + + + {{statusText | async}} +
    diff --git a/ufund-ui/src/styles.css b/ufund-ui/src/styles.css index 471f272..fdf67c7 100644 --- a/ufund-ui/src/styles.css +++ b/ufund-ui/src/styles.css @@ -6,8 +6,17 @@ html, body { margin: 0; + height: 100%; } body { font-family: sans-serif; } + +input { + font-size: 14pt; +} + +button, .button { + font-size: 14pt; +} -- cgit v1.2.3 From 69e79cc423110ea7df3d960f95e612934d256dd8 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sat, 22 Mar 2025 00:24:09 -0400 Subject: Create basic home page --- ufund-ui/src/app/app-routing.module.ts | 12 ++++++------ .../src/app/components/home-page/home-page.component.css | 7 +++++++ .../src/app/components/home-page/home-page.component.html | 5 ++--- .../src/app/components/need-page/need-page.component.html | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ufund-ui/src/app/app-routing.module.ts b/ufund-ui/src/app/app-routing.module.ts index 4b76654..c83db8a 100644 --- a/ufund-ui/src/app/app-routing.module.ts +++ b/ufund-ui/src/app/app-routing.module.ts @@ -8,12 +8,12 @@ import {FundingBasketComponent} from './components/funding-basket/funding-basket import {NeedPageComponent} from './components/need-page/need-page.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" } ]; @NgModule({ 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..5f65225 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,7 @@ +:host { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} 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..b2eed0b 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,2 @@ - - Login/Sign Up - \ No newline at end of file +

    Helping fund coral reef and marine life conservation

    + 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 90fd459..b2579c9 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,4 +1,4 @@ - +

    Viewing Need: {{need?.name}}

    internal id: {{need?.id}}
    @@ -19,4 +19,4 @@

    Goal: {{need?.maxGoal}}

    Current: {{need?.current}}

    -

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

    \ No newline at end of file +

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

    -- cgit v1.2.3 From 2b67bd14828c8c0bffe461a66542a2dba6c19f93 Mon Sep 17 00:00:00 2001 From: benal01 Date: Sat, 22 Mar 2025 11:21:30 -0400 Subject: API creation bug fix- the max goal would not be casted properly --- .../com/ufund/api/ufundapi/controller/CupboardController.java | 3 ++- ufund-ui/src/app/components/cupboard/cupboard.component.css | 9 ++++++--- ufund-ui/src/app/components/need-list/need-list.component.css | 1 - 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java index 36ae341..55cf88d 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java @@ -50,7 +50,8 @@ public class CupboardController { public ResponseEntity createNeed(@RequestBody Map params) { System.out.println(params); String name = (String) params.get("name"); - double maxGoal = (double) params.get("maxGoal"); + System.out.println("attemtping cast maxgoual"); + double maxGoal = ((Number) params.get("maxGoal")).doubleValue(); Need.GoalType goalType = GoalType.valueOf((String) params.get("type")); try { diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index 4c6ac4b..434b136 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -1,17 +1,21 @@ :host { display: flex; - justify-content: left; + justify-content: space-evenly; border: 2px solid #000; border-radius: 5px; padding: 10px 20px; + > div { + width: 40%; + } } + + #menu { display: flex; justify-content: space-between; margin: 10px; * { border: 3px solid #000; - border-top-left-radius: 5px; border-top-right-radius: 5px; margin-right: 5px; @@ -29,5 +33,4 @@ #create-button { padding: 10px 20px; - } \ 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 f8948ee..bf7b982 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 @@ -4,7 +4,6 @@ display: block; border-radius: 5px; } - li, div { border: 2px solid #000; border-radius: 5px; -- cgit v1.2.3 From 2abd4b4ba9171821ac545f8dcb67be1e7d722e01 Mon Sep 17 00:00:00 2001 From: benal01 Date: Sat, 22 Mar 2025 11:58:39 -0400 Subject: replaced unneccicary methods for form selection with ngIf --- ufund-ui/src/app/components/cupboard/cupboard.component.css | 2 +- ufund-ui/src/app/components/cupboard/cupboard.component.html | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index 434b136..6c2e5c6 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -12,7 +12,7 @@ #menu { display: flex; - justify-content: space-between; + margin: 10px; * { border: 3px solid #000; diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 4577844..41bb4a7 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -5,10 +5,10 @@

    Admin View

    -
    +

    Create a new need


    @@ -22,11 +22,10 @@
    - - ‼️{{statusText | async}} + {{statusText | async}}
    -
    +

    Update a need


    @@ -46,7 +45,6 @@
    - {{statusText | async}}
    -- cgit v1.2.3 From e9564ba2514f32c63d2ce4ecfc9eeb9f3269f3dd Mon Sep 17 00:00:00 2001 From: benal01 Date: Sat, 22 Mar 2025 12:14:00 -0400 Subject: [ngClass] tab styling --- .../app/components/cupboard/cupboard.component.css | 21 ++++++---- .../components/cupboard/cupboard.component.html | 4 +- .../app/components/cupboard/cupboard.component.ts | 46 ++-------------------- 3 files changed, 20 insertions(+), 51 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index 6c2e5c6..6e70951 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -14,13 +14,20 @@ display: flex; margin: 10px; - * { - border: 3px solid #000; - border-top-left-radius: 5px; - border-top-right-radius: 5px; - margin-right: 5px; - border-bottom: 0px; - } + +} + +.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: 0px; +} + +.selected-tab { + background-color: white; } #create-form, #delete-form, #update-form { diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 41bb4a7..9b74b2a 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -5,8 +5,8 @@

    Admin View

    Create a new need

    diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index f8023c3..646c4ff 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -16,7 +16,7 @@ import { NeedListComponent } from '../need-list/need-list.component'; export class CupboardComponent implements OnInit { protected statusText = new BehaviorSubject("") - + selectedForm = "create" needs: any; @ViewChild("needList") needList?: NeedListComponent @@ -24,9 +24,6 @@ export class CupboardComponent implements OnInit { ngOnInit(): void { this.cupboardService.getNeeds().subscribe(n => this.needs = n); - this.close(); - this.openmenu(); - if (this.isManager()) { console.log("Admin view of Cupboard"); } else { @@ -41,44 +38,9 @@ export class CupboardComponent implements OnInit { type: '' }; selectedNeedId: number | null = null; - - private hideElement(element: any) { - if (element) { - element.style.visibility = 'hidden'; - element.style.position = 'absolute'; - } - } - - 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('update-form')); + + selectForm(name: string) { + this.selectedForm = name; } populateForm(need: any): void { -- cgit v1.2.3 From d8b9c0da32383630f0831fdf6a7f13c96174ee4c Mon Sep 17 00:00:00 2001 From: benal01 Date: Sat, 22 Mar 2025 12:17:50 -0400 Subject: removing unneccicary functions for element visiblity in need list --- .../components/need-list/need-list.component.css | 3 +-- .../components/need-list/need-list.component.ts | 29 ---------------------- 2 files changed, 1 insertion(+), 31 deletions(-) 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 bf7b982..29a9626 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 @@ -26,6 +26,5 @@ li { background-color: #d9d9d9; padding: 10px 20px 20px 20px; border: 2px solid #000; - border-radius: 5px; - visibility: visible; + border-radius: 5px; } \ No newline at end of file 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 f5d7855..3f77df4 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 @@ -24,38 +24,11 @@ export class NeedListComponent { this.needs = n; this.searchResults = this.needs; }); - console.log(this.searchResults); } 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'; - } - } - - open() { - this.hideElement(document.getElementById('search-button')); - this.showElement(document.getElementById('search-container')); - } - - close() { - this.hideElement(document.getElementById('search-container')); - this.showElement(document.getElementById('search-button')); - this.hideElement(document.getElementById('search-status')); } private searchDelay: any; @@ -75,8 +48,6 @@ export class NeedListComponent { 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')); }); } }, 250); -- cgit v1.2.3 From 2ae7c1036b7ce398e2b18928215f74d57bb3cec6 Mon Sep 17 00:00:00 2001 From: benal01 Date: Sat, 22 Mar 2025 12:28:36 -0400 Subject: search reformatting --- ufund-ui/src/app/components/need-list/need-list.component.css | 1 - ufund-ui/src/app/components/need-list/need-list.component.html | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) 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 29a9626..2e4a31b 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 @@ -24,7 +24,6 @@ li { #search-container { background-color: #d9d9d9; - padding: 10px 20px 20px 20px; border: 2px solid #000; border-radius: 5px; } \ No newline at end of file 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 9f22633..0345519 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,8 +1,7 @@

    Needs List

    -
    - +
    -- cgit v1.2.3 From b725948521e81965a18991e7dd59a2bc84dbd460 Mon Sep 17 00:00:00 2001 From: benal01 Date: Sat, 22 Mar 2025 12:56:28 -0400 Subject: need list uses button instead of link --- .../app/components/need-list/need-list.component.css | 15 ++++++++++++--- .../components/need-list/need-list.component.html | 20 +++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) 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 2e4a31b..8f017cd 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,17 +1,26 @@ :host { - list-style-type:circle; + list-style-type: none; border: 2px solid #000; display: block; border-radius: 5px; } -li, div { + +div, li > button { border: 2px solid #000; border-radius: 5px; padding: 5px; margin: 5px; } -li { +ul { + list-style-type: none; + padding-inline-start: 0px; +} + +li > button { + width: 98%; + padding: 1%; + margin: 1%; display: flex; justify-content: space-between; align-items: center; 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 0345519..fef22d7 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 @@ -12,12 +12,14 @@

    All Needs

    No Results Found

    -
  • - - {{need.name}} - - - -
  • +
      +
    • + + + +
    • +
    \ No newline at end of file -- cgit v1.2.3 From 381e57d62f01056d823af74d186f6de87df9fcee Mon Sep 17 00:00:00 2001 From: sowgro Date: Sat, 22 Mar 2025 16:35:10 -0400 Subject: Dark mode! --- ufund-ui/src/app/app.component.css | 8 +++++++- .../app/components/cupboard/cupboard.component.css | 8 ++++---- .../src/app/components/login/login.component.css | 3 ++- .../src/app/components/login/login.component.html | 2 +- .../components/need-list/need-list.component.css | 8 ++++---- ufund-ui/src/styles.css | 21 +++++++++++++++++++++ 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/ufund-ui/src/app/app.component.css b/ufund-ui/src/app/app.component.css index 63608c0..17bbed7 100644 --- a/ufund-ui/src/app/app.component.css +++ b/ufund-ui/src/app/app.component.css @@ -8,12 +8,14 @@ display: flex; flex-direction: row; justify-content: space-between; - border-bottom: black solid 1px; + border-bottom: light-dark(#d3d3d3, black) solid 1px; padding: 0 10px; + background-color: light-dark(#f5f5f5, #2e2e2e); h1 { padding: 0; margin: 0; + } div { @@ -21,4 +23,8 @@ align-items: center; gap: 10px; } + + a { + color: light-dark(black, white); + } } diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index fe4971a..c8add60 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -1,6 +1,6 @@ :host { display: block; - border: 2px solid #000; + /*border: 2px solid #000;*/ border-radius: 5px; padding: 10px 20px; } @@ -9,7 +9,7 @@ background-color: #d9d9d9; padding: 10px 20px 20px 20px; border: 2px solid #000; - border-radius: 5px; + border-radius: 5px; width: 20%; visibility: visible; @@ -17,5 +17,5 @@ #create-button { padding: 10px 20px; - -} \ No newline at end of file + +} diff --git a/ufund-ui/src/app/components/login/login.component.css b/ufund-ui/src/app/components/login/login.component.css index cae0992..c752de3 100644 --- a/ufund-ui/src/app/components/login/login.component.css +++ b/ufund-ui/src/app/components/login/login.component.css @@ -10,11 +10,12 @@ display: flex; flex-direction: column; max-width: 330px; - gap: 5px; + gap: 7px; backdrop-filter: blur(10px); background-color: rgba(0, 0, 0, 0.1); padding: 30px; color: white; + border-radius: 5px; } .border { diff --git a/ufund-ui/src/app/components/login/login.component.html b/ufund-ui/src/app/components/login/login.component.html index aff108f..516b07b 100644 --- a/ufund-ui/src/app/components/login/login.component.html +++ b/ufund-ui/src/app/components/login/login.component.html @@ -1,6 +1,6 @@
    You must be logged in to view this page -

    Login:

    +

    Login

    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..fa3ed4f 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 @@ -4,7 +4,7 @@ display: block; width: 30%; border-radius: 5px; - + } li, div { @@ -16,9 +16,9 @@ li, div { } #search-form { - background-color: #d9d9d9; + background-color: light-dark(#d9d9d9, #1b1b1b); padding: 10px 20px 20px 20px; border: 2px solid #000; - border-radius: 5px; + border-radius: 5px; visibility: visible; - } \ No newline at end of file + } diff --git a/ufund-ui/src/styles.css b/ufund-ui/src/styles.css index fdf67c7..dc7dcea 100644 --- a/ufund-ui/src/styles.css +++ b/ufund-ui/src/styles.css @@ -1,5 +1,9 @@ /* You can add global styles to this file, and also import other style files */ +:root { + color-scheme: light dark; +} + * { box-sizing: border-box; } @@ -7,6 +11,7 @@ html, body { margin: 0; height: 100%; + background-color: light-dark(white, #242424); } body { @@ -15,8 +20,24 @@ body { input { font-size: 14pt; + padding: 5px; + border-radius: 5px; + border-style: none; + background-color: light-dark(#ebebeb, #3a3a3a); + + &:hover { + background-color: light-dark(#e1e1e1, #444444); + } } button, .button { font-size: 14pt; + padding: 5px 10px; + border-radius: 5px; + border-style: none; + background-color: light-dark(#ebebeb, #3a3a3a); + + &:hover { + background-color: light-dark(#e1e1e1, #444444); + } } -- cgit v1.2.3 From a05f6f0ab8dead76f937a2d7196fa005af0367fe Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 24 Mar 2025 10:27:31 -0400 Subject: hover feedback for need list's button --- ufund-ui/src/app/components/need-list/need-list.component.css | 6 ++++++ ufund-ui/src/app/components/need-list/need-list.component.html | 4 ++-- ufund-ui/src/app/components/need-list/need-list.component.ts | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) 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 8f017cd..c2b8b90 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 @@ -24,8 +24,14 @@ li > button { display: flex; justify-content: space-between; align-items: center; + transition: all 0.3s ease; } +li > button:hover p { + font-weight: bold; +} + + .icon { width: 15px; margin: 3px -3px -1px -3px; 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 fef22d7..fc2daa5 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 @@ -13,9 +13,9 @@

    No Results Found

      -
    • +
    • 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 3f77df4..8ae7370 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 @@ -78,6 +78,13 @@ export class NeedListComponent { return type === ("HELPER" as unknown as userType); } + changeText(id : number, text : string) { + const label = document.getElementById('need-label-' + id); + if (label) { + label.innerHTML = text; + } + } + add(need: Need) { const currentUser = this.usersService.getCurrentUser(); //console.log("get current user in angular:", currentUser) -- cgit v1.2.3 From 1c1d3922e7eea35764ebab39b18172ed2c8c82d9 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 24 Mar 2025 10:38:40 -0400 Subject: better feedback using a --- ufund-ui/src/app/components/need-list/need-list.component.css | 8 +++++++- ufund-ui/src/app/components/need-list/need-list.component.html | 4 ++-- ufund-ui/src/app/components/need-list/need-list.component.ts | 8 ++++---- 3 files changed, 13 insertions(+), 7 deletions(-) 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 c2b8b90..c42dfda 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 @@ -25,10 +25,16 @@ li > button { justify-content: space-between; align-items: center; transition: all 0.3s ease; + font-weight: bold; +} + +li > button span { + font-style: italic; + font-weight: normal; } li > button:hover p { - font-weight: bold; + text-decoration: underline; } 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 fc2daa5..741b899 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 @@ -13,9 +13,9 @@

      No Results Found

        -
      • +
      • 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 8ae7370..0f86921 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 @@ -79,10 +79,10 @@ export class NeedListComponent { } changeText(id : number, text : string) { - const label = document.getElementById('need-label-' + id); - if (label) { - label.innerHTML = text; - } + const span = document.getElementById('hover-status-label-' + id); + if (span) { + span.innerHTML = ' ' + text; + } } add(need: Need) { -- cgit v1.2.3 From cb3b7710b9e32df408b3a38383aca049fa98214e Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 24 Mar 2025 21:17:33 -0400 Subject: Fixed various bugs and began fixing auth system. Also started implementing checkout method in cupboardService --- .../ufundapi/controller/CupboardController.java | 29 ++++++++ .../api/ufundapi/controller/UserController.java | 7 +- .../java/com/ufund/api/ufundapi/model/Need.java | 8 ++- .../java/com/ufund/api/ufundapi/model/User.java | 17 +++++ .../com/ufund/api/ufundapi/model/UserAuth.java | 7 +- .../api/ufundapi/persistence/CupboardFileDAO.java | 11 +-- .../api/ufundapi/persistence/UserAuthFIleDAO.java | 16 +++-- .../ufund/api/ufundapi/service/AuthService.java | 26 ++++--- .../api/ufundapi/service/CupboardService.java | 22 +++++- .../ufund/api/ufundapi/service/UserService.java | 6 +- .../ufundapi/persistence/CupboardFileDAOTest.java | 79 ++++++++++++++-------- .../api/ufundapi/persistence/UserFileDAOTest.java | 18 +++++ .../api/ufundapi/service/CupboardServiceTest.java | 4 +- ufund-ui/src/app/services/users.service.ts | 2 +- 14 files changed, 191 insertions(+), 61 deletions(-) diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java index 36ae341..664b53b 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; @@ -161,6 +162,34 @@ public class CupboardController { } } + /** + * Checks out a need by checkoutAmount + * + * @param data JSON object with paramters needID and amount + * @param key Key used to authenticate user + * @return OK if successful, other statuses if failure + * @throws IllegalAccessException + */ + @PutMapping("/checkout") + public ResponseEntity checkoutNeeds(@RequestBody Map data, @RequestHeader("jelly-api-key") String key) throws IllegalAccessException { + int needID = data.get("needID"); + int checkoutAmount = data.get("amount"); + LOG.log(Level.INFO, "Checking out need with ID: " + needID + " by " + checkoutAmount); + try { + cupboardService.checkoutNeed(needID, checkoutAmount, key); + return new ResponseEntity<>(HttpStatus.OK); + } catch (IllegalArgumentException ex) { + ex.printStackTrace(); + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + } catch (IllegalAccessException ex) { + ex.printStackTrace(); + return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + } catch (IOException ex) { + ex.printStackTrace(); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + /** * Deletes a single need from the cupboard using the Need's id * 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..b0dbd1d 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 @@ -99,12 +99,13 @@ public class UserController { * @param key The authentication key of the user * @return OK response and the user if it was successful, or * INTERNAL_SERVER_ERROR if there was an issue + * @throws IllegalAccessException */ @PutMapping("/{username}") - public ResponseEntity updateUser(@RequestBody User user, @PathVariable String username, @RequestHeader("jelly-api-key") String key) { - LOG.log(Level.INFO,"PUT: " + user + " " + username + " " + key.toString()); + public ResponseEntity updateUser(@RequestHeader("jelly-api-key") String key, @RequestBody User user, @PathVariable String username) throws IllegalAccessException { + LOG.log(Level.INFO,"PUT: " + user + " " + username + " " + key); try { - //authService.authenticate(username, key); + authService.authenticate(username, key); user = userService.updateUser(user, username); if (user != null) { return new ResponseEntity<>(user, HttpStatus.OK); 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..22e86e3 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 @@ -17,14 +17,14 @@ public class Need { @JsonProperty("current") private double current; /** - * Create a new need + * Create a new need, used by the controller * * @param name The name 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) */ - public Need(@JsonProperty("name") String name, @JsonProperty("id") int id, @JsonProperty("maxGoal") double maxGoal, GoalType type) { + public Need(@JsonProperty("name") String name, @JsonProperty("id") int id, @JsonProperty("maxGoal") double maxGoal, @JsonProperty("type") GoalType type) { this.id = id; this.name = name; this.maxGoal = maxGoal; @@ -86,6 +86,10 @@ public class Need { 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..2871916 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 @@ -43,10 +43,21 @@ public class User { 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()); } @@ -59,6 +70,11 @@ public class User { return 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 +87,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..4d11554 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 { 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..9023b42 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().compareTo(LocalDateTime.now()) > -1) { // Someone else double check the logic is correct. Checks if auth is valid and adds if so + userAuthMap.put(userAuth.getKey(), userAuth); + } } } 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..71b8f41 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 { @@ -30,12 +31,19 @@ public class AuthService { if (userAuth == null) { throw new IllegalAccessException("Unauthenticated"); } -// -// var username = userAuth.getUsername(); -// var userType = userService.getUser(username).getType(); -// if (!username.equals(targetUsername) && userType != User.UserType.MANAGER) { -// throw new IllegalAccessException("Unauthorized"); -// } + + var username = userAuth.getUsername(); + var userType = userService.getUser(username).getType(); + if (!username.equals(targetUsername) && userType != User.UserType.MANAGER) { + throw new IllegalAccessException("Unauthorized"); + } + } + + public void authenticate(String key) throws IOException, IllegalAccessException { + var userAuth = userAuthDAO.getUserAuth(key); + if (userAuth == null) { + throw new IllegalAccessException("Unauthenticated"); + } } /** 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..8713882 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; } @@ -96,6 +99,23 @@ public class CupboardService { 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 + * @throws IllegalAccessException + */ + public void checkoutNeed(int id, double checkoutAmount, String key) throws IOException, IllegalAccessException { + if (checkoutAmount <= 0) { + throw new IllegalArgumentException("Amount must be greather than 0"); + } + authService.authenticate(key); + Need need = cupboardDAO.getNeed(id); + need.incrementCurrent(checkoutAmount); + } + /** * Delete a need from the cupboard * 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..aaa2f06 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java @@ -2,6 +2,7 @@ package com.ufund.api.ufundapi.service; import java.io.IOException; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import com.ufund.api.ufundapi.DuplicateKeyException; @@ -12,7 +13,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,6 +45,9 @@ public class UserService { */ public User getUser(String username) throws IOException { User user = userDAO.getUser(username); + if (user == null) { + return null; + } for (int needId : user.getNeeds()) { if (cupboardService.getNeed(needId) == null) { user.removeBasketNeed(needId); diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java index f786a8c..0ebbeca 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,43 @@ import com.ufund.api.ufundapi.model.Need.GoalType; @Tag("Persistence-tier") public class CupboardFileDAOTest { - private CupboardFileDAO cupboardFileDao; - private Need[] testNeeds; - private ObjectMapper mockObjectMapper; - - @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) + private CupboardFileDAO cupboardFileDao; + private Need[] testNeeds; + private ObjectMapper mockObjectMapper; + + @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) }; - // 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 actualNeed = cupboardFileDao.addNeed(newNeed); @@ -78,6 +78,15 @@ public class CupboardFileDAOTest { assertNull(deletedNeed); } + @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(); @@ -91,4 +100,16 @@ public class CupboardFileDAOTest { 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", 20, 100, GoalType.PHYSICAL); + + Need actualNeed = cupboardFileDao.updateNeed(updatedNeed); + assertNull(actualNeed); + } + } 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/CupboardServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java index 99ca23c..59f5b1b 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 @@ -23,11 +23,13 @@ public class CupboardServiceTest { private CupboardDAO mockCupboardDAO; private CupboardService cupboardService; + private AuthService mockAuthService; @BeforeEach public void setupCupboardService() { mockCupboardDAO = mock(CupboardDAO.class); - cupboardService = new CupboardService(mockCupboardDAO); + mockAuthService = mock(AuthService.class); + cupboardService = new CupboardService(mockAuthService, mockCupboardDAO); } diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index dba8185..6709192 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -45,7 +45,7 @@ export class UsersService { } updateUser(user: User): Observable { - return this.http.put(`${this.url}/${user.username}`,user, this.httpOptions2) + return this.http.put(`${this.url}/${user.username}`, user, this.httpOptions2) } deleteUser(id: number): Observable { -- cgit v1.2.3 From 12551843966b285ce3113fe0243626cc961a7715 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 24 Mar 2025 21:18:25 -0400 Subject: Added comment --- ufund-ui/src/app/services/users.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 6709192..8515073 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -45,7 +45,7 @@ export class UsersService { } updateUser(user: User): Observable { - return this.http.put(`${this.url}/${user.username}`, user, this.httpOptions2) + return this.http.put(`${this.url}/${user.username}`, user, this.httpOptions2) // This line is causing issues as the key is not properly being passed } deleteUser(id: number): Observable { -- cgit v1.2.3 From 96f833352eff7b9428daf2add988ecd0a2b41d92 Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 24 Mar 2025 21:21:32 -0400 Subject: Tweak style --- ufund-ui/src/app/components/login/login.component.css | 7 +++++-- ufund-ui/src/app/components/login/login.component.html | 5 ++++- ufund-ui/src/styles.css | 5 +++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ufund-ui/src/app/components/login/login.component.css b/ufund-ui/src/app/components/login/login.component.css index c752de3..4bfcbb8 100644 --- a/ufund-ui/src/app/components/login/login.component.css +++ b/ufund-ui/src/app/components/login/login.component.css @@ -9,13 +9,16 @@ #box { display: flex; flex-direction: column; - max-width: 330px; - gap: 7px; + 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: white; } .border { diff --git a/ufund-ui/src/app/components/login/login.component.html b/ufund-ui/src/app/components/login/login.component.html index 516b07b..e04ec23 100644 --- a/ufund-ui/src/app/components/login/login.component.html +++ b/ufund-ui/src/app/components/login/login.component.html @@ -4,6 +4,9 @@ - + + {{statusText | async}} diff --git a/ufund-ui/src/styles.css b/ufund-ui/src/styles.css index dc7dcea..bad2232 100644 --- a/ufund-ui/src/styles.css +++ b/ufund-ui/src/styles.css @@ -22,7 +22,8 @@ input { font-size: 14pt; padding: 5px; border-radius: 5px; - border-style: none; + border-style: solid; + border-width: 1px; background-color: light-dark(#ebebeb, #3a3a3a); &:hover { @@ -32,7 +33,7 @@ input { button, .button { font-size: 14pt; - padding: 5px 10px; + padding: 6px 10px; border-radius: 5px; border-style: none; background-color: light-dark(#ebebeb, #3a3a3a); -- cgit v1.2.3 From a8175ba69669fddadfbe143e11972cc21821ed5f Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 24 Mar 2025 22:02:07 -0400 Subject: Fix authentication bug --- ufund-ui/src/app/services/users.service.ts | 35 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/ufund-ui/src/app/services/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 8515073..6671440 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -1,6 +1,6 @@ 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'; @@ -16,20 +16,20 @@ export class UsersService { private url = "http://localhost:8080/users" private authUrl = "http://localhost:8080/auth" - private httpOptions = { + private httpOptions = () => ({ headers: new HttpHeaders({ 'Content-Type': 'application/json', "jelly-api-key": this.apiKey }) - }; - private httpOptions2 = { + }); + 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, @@ -37,19 +37,20 @@ export class UsersService { ) {} async createUser(username:string, password:string) { - await firstValueFrom(this.http.post(this.url, {username: username, password: password}, this.httpOptions)) + await firstValueFrom(this.http.post(this.url, {username: username, password: password}, this.httpOptions())) } getUser(id: string): Observable { - return this.http.get(`${this.url}/${id}`, this.httpOptions) + return this.http.get(`${this.url}/${id}`, this.httpOptions()) } updateUser(user: User): Observable { - return this.http.put(`${this.url}/${user.username}`, user, this.httpOptions2) // This line is causing issues as the key is not properly being passed + console.log(`${this.url}/${user.username}`, user, this.httpOptions) + return this.http.put(`${this.url}/${user.username}`, user, this.httpOptions2()) // This line is causing issues as the key is not properly being passed } deleteUser(id: number): Observable { - return this.http.delete(`${this.url}/${id}`, this.httpOptions) + return this.http.delete(`${this.url}/${id}`, this.httpOptions()) } getCurrentUserSubject() { @@ -61,7 +62,7 @@ export class UsersService { } async login(username: string, password: string) { - let res = this.http.post(this.authUrl, {username: username, password: password}, this.httpOptions2); + let res = this.http.post(this.authUrl, {username: username, password: password}, this.httpOptions2()); this.apiKey = await firstValueFrom(res); console.log("apikey: "+this.apiKey) let res2 = this.http.get(`${this.url}/${username}`, { @@ -81,16 +82,20 @@ export class UsersService { }) 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.updateUser(this.getCurrentUser()!) + .pipe( + catchError((err: any, ob) => { + console.error(err); + return of(); + }) + ) + .subscribe(() => { this.refreshBasket(); - error: (err: any) => { - console.error(err); - } }); } -- cgit v1.2.3 From f0ac1eda74367afc375112a7269c085a511ce490 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 24 Mar 2025 22:23:36 -0400 Subject: viewing search results inside cupboard component --- .../components/cupboard/cupboard.component.html | 11 +++------ .../app/components/cupboard/cupboard.component.ts | 28 +++++++++++++++++++--- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 9b74b2a..3ed06fb 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -9,7 +9,7 @@
        -

        Create a new need

        +

        Create Need



        @@ -26,15 +26,10 @@
        -

        Update a need

        +

        Update Need


        -
        - - -
        -
        -
        +



        diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 646c4ff..e38f8c0 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -16,10 +16,9 @@ import { NeedListComponent } from '../need-list/need-list.component'; export class CupboardComponent implements OnInit { protected statusText = new BehaviorSubject("") - selectedForm = "create" + selectedForm = "create"; needs: any; - @ViewChild("needList") needList?: NeedListComponent - + @ViewChild("needList") needList?: NeedListComponent; constructor(private cupboardService: CupboardService, private usersService: UsersService) { } ngOnInit(): void { @@ -38,9 +37,32 @@ export class CupboardComponent implements OnInit { type: '' }; selectedNeedId: number | null = null; + searchResults: any[] = []; 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) + }); + } + + } + } + + 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 { -- cgit v1.2.3 From c15aa3daab0cf9a640945d4e634d1327fb55d2db Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 25 Mar 2025 00:03:45 -0400 Subject: Greatly improve logging and other backend clean up --- .../api/ufundapi/controller/AuthController.java | 12 ++++- .../ufundapi/controller/CupboardController.java | 57 +++++++++++++--------- .../api/ufundapi/controller/UserController.java | 38 +++++++++------ .../java/com/ufund/api/ufundapi/model/Need.java | 2 +- .../api/ufundapi/persistence/CupboardFileDAO.java | 13 +---- .../api/ufundapi/persistence/UserFileDAO.java | 9 ++-- .../ufund/api/ufundapi/service/AuthService.java | 8 +-- .../api/ufundapi/service/CupboardService.java | 6 +-- 8 files changed, 81 insertions(+), 64 deletions(-) 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..6ba6160 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,14 +35,17 @@ public class AuthController { */ @PostMapping("") public ResponseEntity login(@RequestBody Map 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) { + } catch (IllegalAccessException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); } catch (IOException ex) { + LOG.log(Level.SEVERE, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -52,10 +58,12 @@ public class AuthController { */ @DeleteMapping("") public ResponseEntity 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) { + } catch (IOException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(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 664b53b..8db8901 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 @@ -23,6 +23,8 @@ import com.ufund.api.ufundapi.model.Need; import com.ufund.api.ufundapi.model.Need.GoalType; import com.ufund.api.ufundapi.service.CupboardService; +import static java.util.List.of; + @RestController @RequestMapping("cupboard") public class CupboardController { @@ -49,7 +51,8 @@ public class CupboardController { */ @PostMapping("") public ResponseEntity createNeed(@RequestBody Map params) { - System.out.println(params); + LOG.log(Level.INFO, "POST /cupboard body: {0}", params); + String name = (String) params.get("name"); double maxGoal = (double) params.get("maxGoal"); Need.GoalType goalType = GoalType.valueOf((String) params.get("type")); @@ -58,10 +61,13 @@ public class CupboardController { Need need = cupboardService.createNeed(name, maxGoal, goalType); return new ResponseEntity<>(need, HttpStatus.OK); } catch (DuplicateKeyException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.CONFLICT); } catch (IllegalArgumentException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } catch (IOException ex) { + LOG.log(Level.SEVERE, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -76,7 +82,7 @@ public class CupboardController { */ @GetMapping("") public ResponseEntity getNeeds() { - LOG.info("GET /needs"); + LOG.info("GET /cupboard"); try { Need[] needs = cupboardService.getNeeds(); @@ -88,19 +94,21 @@ public class CupboardController { } /** - * 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
        - * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise - *

        - */ + * 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} + * + * @deprecated Searching should now be done client side in the future + * + * @return ResponseEntity with array of {@link Need need} objects (may be empty) and + * HTTP status of OK
        + * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise + *

        + */ @GetMapping("/") public ResponseEntity searchNeeds(@RequestParam String name) { - LOG.info("GET /need/?name="+name); + LOG.info("GET /cupboard/?name="+name); try { Need[] needs = cupboardService.searchNeeds(name); @@ -121,7 +129,7 @@ public class CupboardController { */ @GetMapping("/{id}") public ResponseEntity getNeed(@PathVariable int id) { - LOG.log(Level.INFO, "GET /need/{0}", id); + LOG.log(Level.INFO, "GET /cupboard/{0}", id); try { Need need = cupboardService.getNeed(id); @@ -145,7 +153,7 @@ public class CupboardController { */ @PutMapping("/{id}") public ResponseEntity updateNeed(@RequestBody Need need, @PathVariable int id) { - LOG.log(Level.INFO, "Updating need: " + need); + LOG.log(Level.INFO, "PUT /cupboard/{0} body: {1}", of(id, need)); try { Need updatedNeed = cupboardService.updateNeed(need, id); if (updatedNeed != null) { @@ -154,10 +162,10 @@ public class CupboardController { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } catch (IllegalArgumentException ex) { - ex.printStackTrace(); + LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } catch (IOException ex) { - ex.printStackTrace(); + LOG.log(Level.SEVERE, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -168,24 +176,23 @@ public class CupboardController { * @param data JSON object with paramters needID and amount * @param key Key used to authenticate user * @return OK if successful, other statuses if failure - * @throws IllegalAccessException */ @PutMapping("/checkout") - public ResponseEntity checkoutNeeds(@RequestBody Map data, @RequestHeader("jelly-api-key") String key) throws IllegalAccessException { + public ResponseEntity checkoutNeeds(@RequestBody Map data, @RequestHeader("jelly-api-key") String key) { int needID = data.get("needID"); int checkoutAmount = data.get("amount"); - LOG.log(Level.INFO, "Checking out need with ID: " + needID + " by " + checkoutAmount); + LOG.log(Level.INFO, "PUT /need/checkout body: {0}", data); try { cupboardService.checkoutNeed(needID, checkoutAmount, key); return new ResponseEntity<>(HttpStatus.OK); } catch (IllegalArgumentException ex) { - ex.printStackTrace(); + LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } catch (IllegalAccessException ex) { - ex.printStackTrace(); + LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); } catch (IOException ex) { - ex.printStackTrace(); + LOG.log(Level.SEVERE, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -198,6 +205,7 @@ public class CupboardController { */ @DeleteMapping("/{id}") public ResponseEntity deleteNeed(@PathVariable int id) { + LOG.log(Level.INFO, "DELETE /cupboard/{0}", id); try { Need need = cupboardService.getNeed(id); if (cupboardService.deleteNeed(id)) { @@ -205,7 +213,8 @@ public class CupboardController { } else { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - } catch (IOException e) { + } catch (IOException ex) { + LOG.log(Level.SEVERE, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } 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 b0dbd1d..cd340ef 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 @@ -23,6 +23,8 @@ import com.ufund.api.ufundapi.model.User; import com.ufund.api.ufundapi.service.AuthService; import com.ufund.api.ufundapi.service.UserService; +import static java.util.List.of; + @RestController @RequestMapping("users") public class UserController { @@ -43,6 +45,7 @@ public class UserController { */ @PostMapping("") public ResponseEntity createUser(@RequestBody Map params) { + LOG.log(Level.INFO, "POST /users body: {0}", params); String username = params.get("username"); String password = params.get("password"); @@ -54,8 +57,10 @@ public class UserController { return new ResponseEntity<>(HttpStatus.CONFLICT); } } catch (DuplicateKeyException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.CONFLICT); } catch (IOException ex) { + LOG.log(Level.SEVERE, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -72,7 +77,7 @@ public class UserController { */ @GetMapping("/{username}") public ResponseEntity getUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) { - LOG.log(Level.INFO, "GET /user/{0}", username); + LOG.log(Level.INFO, "GET /user/{0} key: {1}", of(username, key)); try { authService.authenticate(username, key); @@ -83,9 +88,10 @@ public class UserController { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } catch (IllegalAccessException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); - } catch (IOException e) { - LOG.log(Level.SEVERE, e.getLocalizedMessage()); + } catch (IOException ex) { + LOG.log(Level.SEVERE, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } @@ -99,11 +105,10 @@ public class UserController { * @param key The authentication key of the user * @return OK response and the user if it was successful, or * INTERNAL_SERVER_ERROR if there was an issue - * @throws IllegalAccessException */ @PutMapping("/{username}") - public ResponseEntity updateUser(@RequestHeader("jelly-api-key") String key, @RequestBody User user, @PathVariable String username) throws IllegalAccessException { - LOG.log(Level.INFO,"PUT: " + user + " " + username + " " + key); + public ResponseEntity 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(user, username, key)); try { authService.authenticate(username, key); user = userService.updateUser(user, username); @@ -113,13 +118,15 @@ public class UserController { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } catch (InvalidParameterException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); - } catch (IOException e) { + } catch (IllegalAccessException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); + return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + } catch (IOException ex) { + LOG.log(Level.SEVERE, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); - } - // catch (IllegalAccessException e) { - // return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); - // } + } } /** @@ -132,6 +139,7 @@ public class UserController { */ @DeleteMapping("/{username}") public ResponseEntity 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); @@ -140,10 +148,12 @@ public class UserController { } else { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - } catch (IOException e) { - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); - } catch (IllegalAccessException e) { + } catch (IllegalAccessException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + } catch (IOException ex) { + LOG.log(Level.SEVERE, ex.getLocalizedMessage()); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } 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 22e86e3..786b104 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 @@ -38,7 +38,7 @@ public class Need { * @param maxGoal The maximum goal for this need * @param type The type of need (monetary, physical) */ - public Need(String name, GoalType type, double maxGoal) { + public Need(String name, GoalType type, double maxGoal) { // TODO why is this needed this.name = name; this.type = type; this.maxGoal = maxGoal; 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 4d11554..3115204 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 @@ -52,15 +52,6 @@ public class CupboardFileDAO implements CupboardDAO { nextId++; } - /** - * 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 * @@ -68,7 +59,7 @@ public class CupboardFileDAO implements CupboardDAO { * @throws IOException If there was an IO issue saving the file */ private boolean save() throws IOException { - Need[] needArray = getNeedsArray(); + Need[] needArray = needs.values().toArray(Need[]::new); objectMapper.writeValue(new File(filename), needArray); return true; @@ -77,7 +68,7 @@ public class CupboardFileDAO implements CupboardDAO { @Override public Need[] getNeeds() { synchronized (needs) { - return getNeedsArray(); + return needs.values().toArray(Need[]::new); } } 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..1b888cd 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 @@ -5,6 +5,7 @@ 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; @@ -82,16 +83,14 @@ 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) { + if (user.getNeeds() == null || user.getType() == null) { // TODO clean this up -tyler User oldData = users.get(user.getUsername()); - User crutch = new User(oldData.getUsername(), 0, new ArrayList(), oldData.getType()); + User crutch = new User(oldData.getUsername(), 0, new ArrayList<>(), oldData.getType()); crutch.copyPassword(oldData); users.put(user.getUsername(), crutch); } else { var old = users.put(user.getUsername(), user); - user.copyPassword(old); + user.copyPassword(Objects.requireNonNull(old)); } save(); return user; 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 71b8f41..4e5ebce 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 @@ -29,20 +29,20 @@ public class AuthService { public void authenticate(String targetUsername, String key) throws IllegalAccessException, IOException { 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 (!username.equals(targetUsername) && userType != User.UserType.MANAGER) { - throw new IllegalAccessException("Unauthorized"); + throw new IllegalAccessException("Provided key does not grant access to perform the requested operation"); } } public void authenticate(String key) throws IOException, IllegalAccessException { var userAuth = userAuthDAO.getUserAuth(key); if (userAuth == null) { - throw new IllegalAccessException("Unauthenticated"); + throw new IllegalAccessException("Invalid authentication key"); } } @@ -58,7 +58,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 8713882..91e3ba5 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 @@ -104,12 +104,12 @@ public class CupboardService { * * @param id The ID of the need to update * @param checkoutAmount The amount to update the need by - * @throws IOException - * @throws IllegalAccessException + * @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 greather than 0"); + throw new IllegalArgumentException("Amount must be greater than 0"); } authService.authenticate(key); Need need = cupboardDAO.getNeed(id); -- cgit v1.2.3 From d31c1aec7f615646553a227c8e235d4ae2679c68 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 25 Mar 2025 08:20:31 -0400 Subject: Rename user getNeeds to getBasket --- .../java/com/ufund/api/ufundapi/model/User.java | 27 +++++++++++++--------- .../api/ufundapi/persistence/UserFileDAO.java | 2 +- .../ufund/api/ufundapi/service/UserService.java | 6 ++--- .../com/ufund/api/ufundapi/model/UserTest.java | 4 ++-- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java index 2871916..d04d8b7 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 basket; - @JsonProperty("type") private final UserType type; + @JsonProperty("username") + private final String username; + @JsonProperty("passwordHash") + private int passwordHash; + @JsonProperty("basket") + private final List 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 basket, @JsonProperty("type") UserType userType) { + public User(@JsonProperty("username") String username, @JsonProperty("passwordHash") int passwordHash, + @JsonProperty("basket") List basket, @JsonProperty("type") UserType userType) { this.username = username; this.basket = basket; this.passwordHash = passwordHash; @@ -35,8 +40,7 @@ public class User { username, password.hashCode(), new ArrayList<>(), - UserType.HELPER - ); + UserType.HELPER); } public String getUsername() { @@ -44,7 +48,8 @@ public class User { } /** - * Verifies if the provided password's hash is the same as the user's actual hash + * 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 @@ -62,7 +67,7 @@ public class User { basket.add(need.getId()); } - public Integer[] getNeeds() { + public Integer[] getBasket() { return basket.toArray(Integer[]::new); } 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..16560e7 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 @@ -84,7 +84,7 @@ public class UserFileDAO implements UserDAO { if (users.containsKey(user.getUsername())) { // var old = users.put(user.getUsername(), user); // user.copyPassword(old); - if (user.getNeeds() == null || user.getType() == null) { + if (user.getBasket() == null || user.getType() == null) { User oldData = users.get(user.getUsername()); User crutch = new User(oldData.getUsername(), 0, new ArrayList(), oldData.getType()); crutch.copyPassword(oldData); 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 aaa2f06..51283fc 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 @@ -48,7 +48,7 @@ public class UserService { if (user == null) { return null; } - for (int needId : user.getNeeds()) { + for (int needId : user.getBasket()) { if (cupboardService.getNeed(needId) == null) { user.removeBasketNeed(needId); } @@ -59,7 +59,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 @@ -81,5 +81,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/model/UserTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java index 55b7f07..517a7e2 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java @@ -59,7 +59,7 @@ public class UserTest { user.addToBasket(need); - Need getNeed = cupboardService.getNeed(user.getNeeds()[0]); + Need getNeed = cupboardService.getNeed(user.getBasket()[0]); assertEquals(needs[0], getNeed); @@ -80,7 +80,7 @@ public class UserTest { user.removeBasketNeed(need.getId()); user.addToBasket(need2); - Need getNeed = cupboardService.getNeed(user.getNeeds()[0]); + Need getNeed = cupboardService.getNeed(user.getBasket()[0]); assertEquals(need2, getNeed); -- cgit v1.2.3 From 428992e125d3089aeb34da0190a3df05d0992cf0 Mon Sep 17 00:00:00 2001 From: benal01 Date: Tue, 25 Mar 2025 08:46:05 -0400 Subject: assets for need list search and edit --- ufund-ui/public/edit.png | Bin 0 -> 6649 bytes ufund-ui/public/search.png | Bin 0 -> 12743 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 ufund-ui/public/edit.png create mode 100644 ufund-ui/public/search.png diff --git a/ufund-ui/public/edit.png b/ufund-ui/public/edit.png new file mode 100644 index 0000000..3b6e2d8 Binary files /dev/null and b/ufund-ui/public/edit.png differ diff --git a/ufund-ui/public/search.png b/ufund-ui/public/search.png new file mode 100644 index 0000000..1940ef5 Binary files /dev/null and b/ufund-ui/public/search.png differ -- cgit v1.2.3 From 20458b2ae22466d0b75a2ae60f318e514c0d905f Mon Sep 17 00:00:00 2001 From: benal01 Date: Tue, 25 Mar 2025 08:46:45 -0400 Subject: need list reformatting- button does not span whole list element --- .../app/components/need-list/need-list.component.css | 19 ++++++++++++++----- .../app/components/need-list/need-list.component.html | 14 ++++++++++---- .../app/components/need-list/need-list.component.ts | 7 ++++++- 3 files changed, 30 insertions(+), 10 deletions(-) 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 c42dfda..74dbc34 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 @@ -5,7 +5,7 @@ border-radius: 5px; } -div, li > button { +div { border: 2px solid #000; border-radius: 5px; padding: 5px; @@ -17,17 +17,26 @@ ul { padding-inline-start: 0px; } -li > button { - width: 98%; - padding: 1%; - margin: 1%; +li { display: flex; justify-content: space-between; align-items: center; transition: all 0.3s ease; font-weight: bold; + border: 2px solid #000; + border-radius: 5px; + margin: 5px; + + > button { + width: 90%; + float: left; + transition: all 0.3s ease; + font-weight: bold; + display: flex; + } } + li > button span { font-style: italic; font-weight: normal; 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 741b899..b31ccf0 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 @@ -13,13 +13,19 @@

        No Results Found

          -
        • - + + +
          + - - +
        \ No newline at end of file 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 0f86921..e47929b 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 @@ -11,6 +11,7 @@ import { userType } from '../../models/User'; styleUrl: './need-list.component.css' }) export class NeedListComponent { + selectedNeed: Need | undefined; needs: Need[] = []; searchResults: Need[] = []; @@ -109,4 +110,8 @@ export class NeedListComponent { back() { this.searchResults = this.needs; } -} + + select(need : Need) { + this.selectedNeed = need; + } +} \ No newline at end of file -- cgit v1.2.3 From a2f35f6c35b96e3103d8eb6c2bdefc7c081f72f2 Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 25 Mar 2025 09:05:23 -0400 Subject: Tweak logging --- .../java/com/ufund/api/ufundapi/controller/AuthController.java | 4 ++-- .../com/ufund/api/ufundapi/controller/CupboardController.java | 6 +++--- .../java/com/ufund/api/ufundapi/controller/UserController.java | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) 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 6ba6160..aa99a90 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 @@ -35,7 +35,7 @@ public class AuthController { */ @PostMapping("") public ResponseEntity login(@RequestBody Map params) { - LOG.log(Level.INFO, "POST /auth body: {0}", params); + LOG.log(Level.INFO, "POST /auth body={0}", params); String username = params.get("username"); String password = params.get("password"); try { @@ -58,7 +58,7 @@ public class AuthController { */ @DeleteMapping("") public ResponseEntity logout(@RequestHeader("jelly-api-key") String key) { - LOG.log(Level.INFO, "DELETE /auth key: {0}", key); + LOG.log(Level.INFO, "DELETE /auth key={0}", key); try { authService.logout(key); return new ResponseEntity<>(HttpStatus.OK); 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 8db8901..e62d5ab 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 @@ -51,7 +51,7 @@ public class CupboardController { */ @PostMapping("") public ResponseEntity createNeed(@RequestBody Map params) { - LOG.log(Level.INFO, "POST /cupboard body: {0}", params); + LOG.log(Level.INFO, "POST /cupboard body={0}", params); String name = (String) params.get("name"); double maxGoal = (double) params.get("maxGoal"); @@ -153,7 +153,7 @@ public class CupboardController { */ @PutMapping("/{id}") public ResponseEntity updateNeed(@RequestBody Need need, @PathVariable int id) { - LOG.log(Level.INFO, "PUT /cupboard/{0} body: {1}", of(id, need)); + LOG.log(Level.INFO, "PUT /cupboard/{0} body={1}", of(id, need)); try { Need updatedNeed = cupboardService.updateNeed(need, id); if (updatedNeed != null) { @@ -181,7 +181,7 @@ public class CupboardController { public ResponseEntity checkoutNeeds(@RequestBody Map 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); + LOG.log(Level.INFO, "PUT /need/checkout body={0}", data); try { cupboardService.checkoutNeed(needID, checkoutAmount, key); return new ResponseEntity<>(HttpStatus.OK); 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 cd340ef..d2f3f28 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 @@ -45,7 +45,7 @@ public class UserController { */ @PostMapping("") public ResponseEntity createUser(@RequestBody Map params) { - LOG.log(Level.INFO, "POST /users body: {0}", params); + LOG.log(Level.INFO, "POST /users body={0}", params); String username = params.get("username"); String password = params.get("password"); @@ -77,7 +77,7 @@ public class UserController { */ @GetMapping("/{username}") public ResponseEntity getUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) { - LOG.log(Level.INFO, "GET /user/{0} key: {1}", of(username, key)); + LOG.log(Level.INFO, "GET /user/{0} key={1}", of(username, key)); try { authService.authenticate(username, key); @@ -108,7 +108,7 @@ public class UserController { */ @PutMapping("/{username}") public ResponseEntity 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(user, username, key)); + LOG.log(Level.INFO,"PUT /users/{0} body={1} key={2}", of(username, user, key)); try { authService.authenticate(username, key); user = userService.updateUser(user, username); @@ -139,7 +139,7 @@ public class UserController { */ @DeleteMapping("/{username}") public ResponseEntity deleteUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) { - LOG.log(Level.INFO, "DELETE /users/{0} id: {1}", of(username, key)); + LOG.log(Level.INFO, "DELETE /users/{0} id={1}", of(username, key)); try { authService.authenticate(username, key); -- cgit v1.2.3 From f7cd2d90191c1d81526ed549514d82864c1aebb2 Mon Sep 17 00:00:00 2001 From: benal01 Date: Tue, 25 Mar 2025 09:08:26 -0400 Subject: restyling of need list results --- .../app/components/need-list/need-list.component.css | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 74dbc34..c763105 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,4 +1,5 @@ :host { + --list-background-color: lightgray; list-style-type: none; border: 2px solid #000; display: block; @@ -18,6 +19,7 @@ ul { } li { + background-color: var(--list-background-color); display: flex; justify-content: space-between; align-items: center; @@ -25,17 +27,26 @@ li { font-weight: bold; border: 2px solid #000; border-radius: 5px; - margin: 5px; - + margin: 5px; > button { - width: 90%; + background-color: var(--list-background-color); + width: 88%; float: left; transition: all 0.3s ease; font-weight: bold; display: flex; + border: none; + border-radius: 5px; + } + + > section { + width: 12%; } } +section button{ + margin: 4%; +} li > button span { font-style: italic; @@ -48,7 +59,7 @@ li > button:hover p { .icon { - width: 15px; + width: 18px; margin: 3px -3px -1px -3px; } -- cgit v1.2.3 From 304b867c6fa5c1192e8cdec7fd22affb50e244b3 Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 25 Mar 2025 09:37:49 -0400 Subject: implement sorting algorithms with selection buttons. -ak --- .../components/need-list/need-list.component.html | 7 ++++ .../components/need-list/need-list.component.ts | 46 ++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) 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..c5faf74 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,4 +1,11 @@

        Needs List

        +
        +

        Sort by:

        + +

        +

        +
        +
        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..be444fb 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,28 @@ -import { Component } from '@angular/core'; +import { Component, Input } 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'; + +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 sortByMaxGoal: sortAlgo = (a: Need, b: Need): number => { + if(a.maxGoal >= b.maxGoal) { + return -1; + } + return 1; +} + @Component({ selector: 'app-need-list', standalone: false, @@ -12,6 +32,12 @@ import { userType } from '../../models/User'; export class NeedListComponent { needs: Need[] = []; searchResults: Need[] = []; + currentSortAlgo: sortAlgo = sortByMaxGoal; + + SortingAlgoArrays: {func:sortAlgo,name:string}[] = [ + {func:sortByMaxGoal,name:"sortByMaxGoal"}, + {func:sortByName,name:"sortByName"}, + ]; constructor( private cupboardService: CupboardService, @@ -19,7 +45,7 @@ export class NeedListComponent { ) {} refresh() { - this.cupboardService.getNeeds().subscribe(n => this.needs = n) + this.cupboardService.getNeeds().subscribe(n => this.needs = n.sort(this.currentSortAlgo)) } ngOnInit(): void { @@ -60,6 +86,19 @@ export class NeedListComponent { this.hideElement(document.getElementById('search-status')); } + changeSortAlgo(algoName: string, form: any) { + console.log(algoName); + this.SortingAlgoArrays.forEach(algo => { + if(algo.name === algoName) { + this.currentSortAlgo = algo.func; + console.log("changed sorting algorithm to: ", algo.name) + return + } + }); + this.refresh() + this.search(form); + } + private searchDelay: any; async search(form: any) { @@ -72,8 +111,9 @@ export class NeedListComponent { this.searchDelay = setTimeout(() => { const currentSearchValue = form.search; //latest value of the search + console.log("current search value: ", currentSearchValue) this.cupboardService.searchNeeds(currentSearchValue).subscribe((n) => { - this.searchResults = n; + this.searchResults = n.sort(this.currentSortAlgo); console.log(currentSearchValue, this.searchResults); this.showElement(document.getElementById('search-results')); this.showElement(document.getElementById('search-status')); -- cgit v1.2.3 From 07d191cb1fc8890f66e9af7d19e8276089d18d8b Mon Sep 17 00:00:00 2001 From: Akash Keshav <112591754+domesticchores@users.noreply.github.com> Date: Tue, 25 Mar 2025 09:45:38 -0400 Subject: added more sort options; fix HTML error --- .../src/app/components/need-list/need-list.component.html | 2 ++ .../src/app/components/need-list/need-list.component.ts | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) 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 c5faf74..283cc99 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 @@ -3,7 +3,9 @@

        Sort by:

        +

        +

        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 be444fb..06bb17e 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 @@ -16,13 +16,24 @@ const sortByName: sortAlgo = (a: Need, b: Need): number => { return 1; } +const sortByNameReverse: sortAlgo = (a: Need, b: Need): number => { + return sortByName(a,b)*-1; +} + const sortByMaxGoal: sortAlgo = (a: Need, b: Need): number => { - if(a.maxGoal >= b.maxGoal) { + if(a.maxGoal == b.maxGoal) { + return sortByName(a,b); + } + else if(a.maxGoal > b.maxGoal) { return -1; } return 1; } +const sortByMinGoal: sortAlgo = (a: Need, b: Need): number => { + return sortByMaxGoal(a,b)*-1; +} + @Component({ selector: 'app-need-list', standalone: false, @@ -37,6 +48,8 @@ export class NeedListComponent { SortingAlgoArrays: {func:sortAlgo,name:string}[] = [ {func:sortByMaxGoal,name:"sortByMaxGoal"}, {func:sortByName,name:"sortByName"}, + {func:sortByNameReverse,name:"sortByNameReverse"}, + {func:sortByMinGoal,name:"sortByMinGoal"}, ]; constructor( -- cgit v1.2.3 From 5f03e80712f7a18370b5118fde5327bde1b6fbbf Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 25 Mar 2025 10:17:55 -0400 Subject: Fix tests and more cleanup --- .../api/ufundapi/controller/UserController.java | 3 +-- .../java/com/ufund/api/ufundapi/model/User.java | 4 +-- .../api/ufundapi/persistence/CupboardFileDAO.java | 7 +++--- .../api/ufundapi/persistence/UserFileDAO.java | 11 +++----- .../ufund/api/ufundapi/service/UserService.java | 1 - .../ufundapi/controller/AuthControllerTest.java | 7 +++--- .../ufundapi/controller/UserControllerTest.java | 2 +- .../ufundapi/persistence/CupboardFileDAOTest.java | 5 ++-- .../ufundapi/persistence/UserAuthFileDAOTest.java | 16 ++++++------ .../api/ufundapi/service/AuthServiceTest.java | 29 +++++++++++----------- .../api/ufundapi/service/CupboardServiceTest.java | 27 +++++++++----------- .../api/ufundapi/service/UserServiceTest.java | 13 +++++----- 12 files changed, 56 insertions(+), 69 deletions(-) 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 d2f3f28..c2d9e06 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; @@ -117,7 +116,7 @@ public class UserController { } else { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - } catch (InvalidParameterException ex) { + } catch (IllegalArgumentException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } catch (IllegalAccessException ex) { 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 d04d8b7..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 @@ -71,8 +71,8 @@ public class User { return basket.toArray(Integer[]::new); } - public boolean removeBasketNeed(Integer needID) { - return basket.remove(needID); + public void removeBasketNeed(Integer needID) { + basket.remove(needID); } /** 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 3115204..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 @@ -55,14 +55,12 @@ public class CupboardFileDAO implements CupboardDAO { /** * 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 { Need[] needArray = needs.values().toArray(Need[]::new); objectMapper.writeValue(new File(filename), needArray); - return true; } @Override @@ -109,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/UserFileDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java index 63d864a..0d9b9e4 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 @@ -45,12 +45,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 @@ -83,9 +81,7 @@ 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.getBasket() == null || user.getType() == null) { + if (user.getBasket() == null || user.getType() == null) { // TODO clean this up User oldData = users.get(user.getUsername()); User crutch = new User(oldData.getUsername(), 0, new ArrayList<>(), oldData.getType()); crutch.copyPassword(oldData); @@ -107,7 +103,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/UserService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/UserService.java index 51283fc..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 @@ -2,7 +2,6 @@ package com.ufund.api.ufundapi.service; import java.io.IOException; -import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import com.ufund.api.ufundapi.DuplicateKeyException; 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 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/UserControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java index 5542f49..cc7df40 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 @@ -244,7 +244,7 @@ public class UserControllerTest { ResponseEntity response = userController.updateUser(user, username, key); // Analyze - assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); + assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); } @Test 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 0ebbeca..d83e825 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 @@ -23,11 +23,10 @@ import com.ufund.api.ufundapi.model.Need.GoalType; public class CupboardFileDAOTest { private CupboardFileDAO cupboardFileDao; private Need[] testNeeds; - private ObjectMapper mockObjectMapper; - @BeforeEach + @BeforeEach public void setupCupboardFileDao() throws IOException { - mockObjectMapper = mock(ObjectMapper.class); + ObjectMapper mockObjectMapper = mock(ObjectMapper.class); testNeeds = new Need[] { new Need("one", 0, 100, Need.GoalType.MONETARY), new Need("two", 1, 100, Need.GoalType.MONETARY), 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..5e92deb 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"); } @@ -47,14 +47,14 @@ public class UserAuthFileDAOTest { } @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/service/AuthServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java index 55cf7a9..d3085e5 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; @@ -51,16 +50,16 @@ public class AuthServiceTest { } -// @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 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 testAuthenticateMissingUserAuth() throws IOException { @@ -73,7 +72,7 @@ public class AuthServiceTest { } @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 59f5b1b..05ea2e8 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 @@ -23,12 +23,11 @@ public class CupboardServiceTest { private CupboardDAO mockCupboardDAO; private CupboardService cupboardService; - private AuthService mockAuthService; @BeforeEach public void setupCupboardService() { mockCupboardDAO = mock(CupboardDAO.class); - mockAuthService = mock(AuthService.class); + AuthService mockAuthService = mock(AuthService.class); cupboardService = new CupboardService(mockAuthService, mockCupboardDAO); } @@ -54,7 +53,7 @@ public class CupboardServiceTest { } @Test - public void testCreateNeedBadGoal() throws IOException, DuplicateKeyException { + public void testCreateNeedBadGoal() throws IOException { // Setup String name = "Jellyfish"; double maxGoal = -100.00; @@ -69,13 +68,12 @@ 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, maxGoal, type)); } @Test - public void testCreateNeedDuplicate() throws IOException, DuplicateKeyException { + public void testCreateNeedDuplicate() throws IOException { // Setup String name = "Jellyfish"; double maxGoal = 100.00; @@ -91,13 +89,12 @@ 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, maxGoal, type)); } @Test - public void testSearchNeeds() throws IOException, DuplicateKeyException { + public void testSearchNeeds() throws IOException { // Setup String name = "Jellyfish"; double maxGoal = 100.00; @@ -117,7 +114,7 @@ public class CupboardServiceTest { } @Test - public void testSearchNeedsFail() throws IOException, DuplicateKeyException { + public void testSearchNeedsFail() throws IOException { // Setup String name = "Jellyfish"; double maxGoal = 100.00; @@ -136,7 +133,7 @@ public class CupboardServiceTest { } @Test - public void testGetNeed() throws IOException, DuplicateKeyException { + public void testGetNeed() throws IOException { // Setup String name = "Jellyfish"; double maxGoal = 100.00; @@ -155,7 +152,7 @@ public class CupboardServiceTest { } @Test - public void testUpdateNeed() throws IOException, DuplicateKeyException { + public void testUpdateNeed() throws IOException { // Setup String name = "Jellyfish"; double maxGoal = 100.00; @@ -175,7 +172,7 @@ public class CupboardServiceTest { } @Test - public void testDeleteNeed() throws IOException, DuplicateKeyException { + public void testDeleteNeed() throws IOException { // Setup String name = "Jellyfish"; double maxGoal = 100.00; 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"; -- cgit v1.2.3 From d9eb78521f29ead3a9f70b09e18a6d9560cc849c Mon Sep 17 00:00:00 2001 From: benal01 Date: Tue, 25 Mar 2025 10:43:52 -0400 Subject: fancy selection animation for need list --- .../components/need-list/need-list.component.css | 2 +- .../components/need-list/need-list.component.html | 4 ++-- .../components/need-list/need-list.component.ts | 28 +++++++++++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) 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 c763105..2eb6a8d 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 @@ -29,7 +29,7 @@ li { border-radius: 5px; margin: 5px; > button { - background-color: var(--list-background-color); + background-color: transparent; width: 88%; float: left; transition: all 0.3s ease; 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 b31ccf0..eaa8a6f 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 @@ -13,14 +13,14 @@

        No Results Found

          -
        • +
        • - +{{statusText | async}} +{{strength | async}} +Account created Proceed to login 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..48c6387 --- /dev/null +++ b/ufund-ui/src/app/components/signup/signup.component.ts @@ -0,0 +1,118 @@ +import { Component } from '@angular/core'; +import {UsersService} from '../../services/users.service'; +import {Router} from '@angular/router'; +import {BehaviorSubject} from 'rxjs'; + +@Component({ + selector: 'app-signup', + standalone: false, + templateUrl: './signup.component.html', + styleUrl: './signup.component.css' +}) +export class SignupComponent { + + protected statusText = new BehaviorSubject("") + protected showSuccessMessage = new BehaviorSubject(false) + protected passwordStrength = new BehaviorSubject("") + protected strength = new BehaviorSubject(0) + + constructor( + protected usersService: UsersService, + protected router: Router, + ) {} + + 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.statusText.next("Unable to create account: " + friendlyHttpStatus[ex.status]) + console.log(ex) + }) + } + + checkPasswordStrength(password: string) { + this.statusText.next("") + if (password.match(/[^!-~]/g)) { + this.statusText.next("Invalid characters") + return + } + + let strength = 0; + if (password.length > 6) { + strength++ + console.log("Long") + } + if (password.length > 12) { + strength++ + console.log("Longer") + } + if (password.match(/[a-z]/g)) { + strength++ + console.log("a") + } + if (password.match(/[0-9]/g)) { + strength++ + console.log("0") + } + if (password.match(/[A-Z]/g)) { + strength++ + console.log("A") + } + if (password.match(/[!-/]/g)) { + strength++ + console.log("!") + } + + this.strength.next(strength) + } + +} + +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', +}; -- cgit v1.2.3 From ea13cf6ab3b71ff5e83fca876ec71fec1f7b00ae Mon Sep 17 00:00:00 2001 From: sowgro Date: Wed, 26 Mar 2025 15:38:46 -0400 Subject: Make frontend work with the new backend checkout system --- ufund-ui/src/app/app.component.ts | 8 +- .../app/components/cupboard/cupboard.component.ts | 58 +----- .../components/dashboard/dashboard.component.ts | 20 +- .../funding-basket/funding-basket.component.ts | 122 ++++++------ .../src/app/components/login/login.component.ts | 14 +- .../components/need-list/need-list.component.ts | 212 +++++++++++---------- ufund-ui/src/app/services/auth.service.ts | 57 ++++++ ufund-ui/src/app/services/cupboard.service.ts | 30 ++- ufund-ui/src/app/services/users.service.ts | 52 +---- 9 files changed, 286 insertions(+), 287 deletions(-) create mode 100644 ufund-ui/src/app/services/auth.service.ts diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index 7dc8ffb..86717c4 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -1,7 +1,7 @@ import {Component, OnInit, Inject} from '@angular/core'; -import {UsersService} from './services/users.service'; import {BehaviorSubject} from 'rxjs'; import { DOCUMENT } from '@angular/common'; +import {AuthService} from './services/auth.service'; @Component({ selector: 'app-root', @@ -14,16 +14,16 @@ export class AppComponent implements OnInit { currentUser$: BehaviorSubject = new BehaviorSubject("Logged out."); constructor( - private userService: UsersService, + private authService: AuthService, @Inject(DOCUMENT) private document: Document ) {} reloadPage() { this.document.defaultView?.location.reload(); - } + } ngOnInit() { - this.userService.getCurrentUserSubject().subscribe(r => { + this.authService.getCurrentUserSubject().subscribe(r => { this.currentUser$?.next(r ? "Logged in as " + r.username : "Logged out." diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 24b3e2d..a812baf 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,10 +1,10 @@ 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 { NeedListComponent } from '../need-list/need-list.component'; +import {AuthService} from '../../services/auth.service'; @Component({ selector: 'app-cupboard', @@ -20,7 +20,10 @@ export class CupboardComponent implements OnInit { needs: any; @ViewChild("needList") needList?: NeedListComponent - constructor(private cupboardService: CupboardService, private usersService: UsersService) { } + constructor( + private cupboardService: CupboardService, + private authService: AuthService + ) {} ngOnInit(): void { this.cupboardService.getNeeds().subscribe(n => this.needs = n); @@ -88,7 +91,7 @@ export class CupboardComponent implements OnInit { } isManager() { - const type = this.usersService.getCurrentUser()?.type; + const type = this.authService.getCurrentUser()?.type; return type === ("MANAGER" as unknown as userType); } @@ -105,7 +108,7 @@ export class CupboardComponent implements OnInit { console.log("need:", need); console.log(need.id, need, "need updated"); this.cupboardService.updateNeed(need.id, need) - .pipe(catchError((ex, r) => { + .pipe(catchError((ex, _) => { if (ex.status == 500) { this.statusText.next("Fields cannot be blank"); } else if (ex.status == 400) { @@ -140,7 +143,7 @@ export class CupboardComponent implements OnInit { 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"); } else if (ex.status == 400) { @@ -167,48 +170,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.ts b/ufund-ui/src/app/components/dashboard/dashboard.component.ts index b9faefa..a0ad566 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.ts +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.ts @@ -1,21 +1,21 @@ -import { Component } from '@angular/core'; -import { UsersService } from '../../services/users.service'; -import { userType } from '../../models/User'; +import {Component} from '@angular/core'; +import {userType} from '../../models/User'; +import {AuthService} from '../../services/auth.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 { constructor( - protected usersService: UsersService, + protected authService: AuthService, ) {} isManager() { - const type = this.usersService.getCurrentUser()?.type; + const type = this.authService.getCurrentUser()?.type; return type === ("MANAGER" as unknown as userType); - } + } } 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..faa7e0b 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,9 @@ 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'; @Component({ selector: 'app-funding-basket', @@ -14,67 +12,67 @@ import { BehaviorSubject, catchError, firstValueFrom, Observable } from 'rxjs'; styleUrl: './funding-basket.component.css' }) export class FundingBasketComponent implements OnInit { - statusText: any; + 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 + ) {} - @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.usersService.refreshBasket(); - // this.usersService.removeNeed(); <- call this to remove - } + // this is for login rerouting + ngOnInit(): void { + if (!this.authService.getCurrentUser()) { + this.router.navigate(['/login'], {queryParams: {redir: this.router.url}}); + return; + } - 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"); - } + this.usersService.refreshBasket(); + // this.usersService.removeNeed(); <- call this to remove } - 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(); - })) - .subscribe((result) => { - if (result) { - console.log('need updated successfully'); - //this.needList?.refresh() - } else { - console.log('need update failed'); - } - }); - } - } - } + 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.checkoutNeed(need.id, +contribution.value) + .pipe(catchError((ex, _) => { + if (ex.status == 500) { + this.statusText.next('Fields cannot be blank'); + } else if (ex.status == 400) { + this.statusText.next('Goal must be greater than 0'); + } else { + this.statusText.next('Error on creating need'); + } + return new Observable(); + })) + .subscribe((result) => { + if (result) { + console.log('need updated successfully'); + //this.needList?.refresh() + } else { + console.log('need update failed'); + } + }); + } + } + } } diff --git a/ufund-ui/src/app/components/login/login.component.ts b/ufund-ui/src/app/components/login/login.component.ts index 9d806f5..f6a2996 100644 --- a/ufund-ui/src/app/components/login/login.component.ts +++ b/ufund-ui/src/app/components/login/login.component.ts @@ -2,12 +2,13 @@ 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'; @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 { @@ -17,7 +18,8 @@ export class LoginComponent implements OnInit { constructor( protected usersService: UsersService, protected router: Router, - private route: ActivatedRoute + private route: ActivatedRoute, + private authService: AuthService ) {} ngOnInit() { @@ -31,7 +33,7 @@ export class LoginComponent implements OnInit { return; } - this.usersService.login(username, password).then(() => { + this.authService.login(username, password).then(() => { this.router.navigate([next]); }).catch(ex => { this.statusText.next("Unable to login: " + friendlyHttpStatus[ex.status]) 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..3a89a20 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,132 +1,138 @@ -import { Component } from '@angular/core'; +import {Component} 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 {catchError, of} from 'rxjs'; +import {AuthService} from '../../services/auth.service'; + @Component({ - selector: 'app-need-list', - standalone: false, - templateUrl: './need-list.component.html', - styleUrl: './need-list.component.css' + selector: 'app-need-list', + standalone: false, + templateUrl: './need-list.component.html', + styleUrl: './need-list.component.css' }) export class NeedListComponent { - needs: Need[] = []; - searchResults: Need[] = []; + needs: Need[] = []; + searchResults: Need[] = []; - constructor( - private cupboardService: CupboardService, - private usersService: UsersService - ) {} + constructor( + private cupboardService: CupboardService, + private usersService: UsersService, + private authService: AuthService + ) {} refresh() { this.cupboardService.getNeeds().subscribe(n => this.needs = n) } - ngOnInit(): void { - this.refresh() - - this.close(); - } + ngOnInit(): void { + this.refresh() - private showElement(element: any) { - if (element){ - element.style.visibility = 'visible'; - element.style.position = 'relative'; + this.close(); } - } - private hideElement(element: any) { - if (element){ - element.style.visibility = 'hidden'; - element.style.position = 'absolute'; + private showElement(element: any) { + if (element) { + element.style.visibility = 'visible'; + element.style.position = 'relative'; + } } - } - private updateSearchStatus(text: string) { - let element = document.getElementById('search-status'); - if (element) { - element.innerHTML = text; + private hideElement(element: any) { + if (element) { + element.style.visibility = 'hidden'; + element.style.position = 'absolute'; + } } - } - open() { - this.hideElement(document.getElementById('search-button')); - this.showElement(document.getElementById('search-form')); - } + private updateSearchStatus(text: string) { + let element = document.getElementById('search-status'); + if (element) { + element.innerHTML = text; + } + } - close() { - this.hideElement(document.getElementById('search-form')); - this.showElement(document.getElementById('search-button')); - this.hideElement(document.getElementById('search-status')); - } + open() { + this.hideElement(document.getElementById('search-button')); + this.showElement(document.getElementById('search-form')); + } - private searchDelay: any; + close() { + this.hideElement(document.getElementById('search-form')); + this.showElement(document.getElementById('search-button')); + this.hideElement(document.getElementById('search-status')); + } - async search(form: any) { - //wait .25 seconds before searching but cancel if another search is made during the wait to prevent too many api calls + private searchDelay: any; - //remove previous search if it exists - if (this.searchDelay) { - clearTimeout(this.searchDelay); - } + async search(form: any) { + //wait .25 seconds before searching but cancel if another search is made during the wait to prevent too many api calls - 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:"); + //remove previous search if it exists + if (this.searchDelay) { + clearTimeout(this.searchDelay); } - }); - }, 250); - } - - delete(id : number) { - this.cupboardService.deleteNeed(id).subscribe(() => { - this.needs = this.needs.filter(n => n.id !== id) - }) - } - - isManager() { - const type = this.usersService.getCurrentUser()?.type; - return type === ("MANAGER" as unknown as userType); - } - - isHelper() { - const type = this.usersService.getCurrentUser()?.type; - return type === ("HELPER" as unknown as userType); - } - - add(need: Need) { - const currentUser = this.usersService.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); - } - }); - } else { - window.alert("This need is already in your basket!") - } - + 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); + } + + delete(id: number) { + this.cupboardService.deleteNeed(id).subscribe(() => { + this.needs = this.needs.filter(n => n.id !== id) + }) } - } + 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: any, _) => { + console.error(err); + return of(); + })) + .subscribe(() => { + this.usersService.refreshBasket(); + }); + } else { + window.alert("This need is already in your basket!") + } + - back() { - this.searchResults = []; - } + } + + } + + back() { + this.searchResults = []; + } } 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..6bc7145 --- /dev/null +++ b/ufund-ui/src/app/services/auth.service.ts @@ -0,0 +1,57 @@ +import {Injectable} from '@angular/core'; +import {BehaviorSubject, firstValueFrom} from 'rxjs'; +import {User} from '../models/User'; +import {HttpClient, HttpHeaders} from '@angular/common/http'; + +@Injectable({ + providedIn: 'root' +}) +export class AuthService { + + private authUrl = "http://localhost:8080/auth" + private userUrl = "http://localhost:8080/users" + + private currentUser : BehaviorSubject = new BehaviorSubject(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 + ) {} + + async login(username: string, password: string) { + let res = this.http.post(this.authUrl, {username: username, password: password}, this.httpOptions2()); + this.apiKey = await firstValueFrom(res); + console.log("apikey: "+this.apiKey) + let res2 = this.http.get(`${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)) + } + + 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 { - return this.http.post(this.url, need, this.httpOptions) + return this.http.post(this.url, need, this.httpOptions()) } getNeeds(): Observable { - return this.http.get(this.url, this.httpOptions) + return this.http.get(this.url, this.httpOptions()) } searchNeeds(name: String): Observable { - return this.http.get(`${this.url}/?name=${name}`, this.httpOptions) + return this.http.get(`${this.url}/?name=${name}`, this.httpOptions()) } getNeed(id: number): Observable { - return this.http.get(`${this.url}/${id}`, this.httpOptions) + return this.http.get(`${this.url}/${id}`, this.httpOptions()) } updateNeed(id: number, data: Need): Observable { - return this.http.put(`${this.url}/${id}`, data, this.httpOptions) + return this.http.put(`${this.url}/${id}`, data, this.httpOptions()) } deleteNeed(id: number): Observable { - return this.http.delete(`${this.url}/${id}`, this.httpOptions) + return this.http.delete(`${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/users.service.ts b/ufund-ui/src/app/services/users.service.ts index 6671440..4080ebf 100644 --- a/ufund-ui/src/app/services/users.service.ts +++ b/ufund-ui/src/app/services/users.service.ts @@ -4,36 +4,27 @@ 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 = new BehaviorSubject(null); - private apiKey: string = ""; private basket = new BehaviorSubject([]); - 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) { @@ -46,38 +37,15 @@ export class UsersService { updateUser(user: User): Observable { console.log(`${this.url}/${user.username}`, user, this.httpOptions) - return this.http.put(`${this.url}/${user.username}`, user, this.httpOptions2()) // This line is causing issues as the key is not properly being passed + return this.http.put(`${this.url}/${user.username}`, user, this.httpOptions()) } deleteUser(id: number): Observable { return this.http.delete(`${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(this.authUrl, {username: username, password: password}, this.httpOptions2()); - this.apiKey = await firstValueFrom(res); - console.log("apikey: "+this.apiKey) - let res2 = this.http.get(`${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)) - } - 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)); @@ -86,10 +54,10 @@ export class UsersService { 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()!) + this.authService.getCurrentUser()!.basket = newArr.map(need => need.id); + this.updateUser(this.authService.getCurrentUser()!) .pipe( - catchError((err: any, ob) => { + catchError((err: any, _) => { console.error(err); return of(); }) -- cgit v1.2.3 From ab35efb06b926e8a3aee5cfc8d1fa908aa4a4707 Mon Sep 17 00:00:00 2001 From: sowgro Date: Wed, 26 Mar 2025 18:14:47 -0400 Subject: Fix cupboard access checking and logging --- .../ufundapi/controller/CupboardController.java | 33 ++++++++++++++----- .../api/ufundapi/controller/UserController.java | 12 ++++--- .../ufund/api/ufundapi/service/AuthService.java | 30 +++++++++++++++-- .../api/ufundapi/service/CupboardService.java | 3 +- .../controller/CupboardControllerTest.java | 29 ++++++++++------- .../ufundapi/controller/UserControllerTest.java | 6 ++-- .../api/ufundapi/service/AuthServiceTest.java | 12 +++---- .../components/home-page/home-page.component.ts | 10 +++--- .../components/need-page/need-page.component.ts | 38 +++++++++++----------- ufund-ui/src/app/models/Need.ts | 16 ++++----- ufund-ui/src/app/models/User.ts | 2 -- 11 files changed, 121 insertions(+), 70 deletions(-) diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java index e62d5ab..55ee457 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 @@ -5,6 +5,7 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import com.ufund.api.ufundapi.service.AuthService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; @@ -23,21 +24,21 @@ import com.ufund.api.ufundapi.model.Need; import com.ufund.api.ufundapi.model.Need.GoalType; import com.ufund.api.ufundapi.service.CupboardService; -import static java.util.List.of; - @RestController @RequestMapping("cupboard") 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; } /** @@ -50,14 +51,15 @@ public class CupboardController { * INTERNAL_SERVER_ERROR otherwise */ @PostMapping("") - public ResponseEntity createNeed(@RequestBody Map params) { + public ResponseEntity createNeed(@RequestBody Map 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"); + double maxGoal = ((Number) params.get("maxGoal")).doubleValue(); Need.GoalType goalType = GoalType.valueOf((String) params.get("type")); try { + authService.keyHasAccessToCupboard(key); Need need = cupboardService.createNeed(name, maxGoal, goalType); return new ResponseEntity<>(need, HttpStatus.OK); } catch (DuplicateKeyException ex) { @@ -66,6 +68,9 @@ public class CupboardController { } catch (IllegalArgumentException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + } catch (IllegalAccessException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); + return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); @@ -152,9 +157,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 updateNeed(@RequestBody Need need, @PathVariable int id) { + public ResponseEntity 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); @@ -164,6 +170,9 @@ public class CupboardController { } catch (IllegalArgumentException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + } catch (IllegalAccessException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); + return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); @@ -204,19 +213,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 deleteNeed(@PathVariable int id) { + public ResponseEntity 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 (IllegalAccessException ex) { + LOG.log(Level.WARNING, ex.getLocalizedMessage()); + return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage()); return new ResponseEntity<>(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 c2d9e06..33d2e4f 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 @@ -22,8 +22,6 @@ import com.ufund.api.ufundapi.model.User; import com.ufund.api.ufundapi.service.AuthService; import com.ufund.api.ufundapi.service.UserService; -import static java.util.List.of; - @RestController @RequestMapping("users") public class UserController { @@ -79,7 +77,7 @@ public class UserController { 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); @@ -109,7 +107,7 @@ public class UserController { public ResponseEntity 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); @@ -141,7 +139,7 @@ public class UserController { 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 { @@ -156,4 +154,8 @@ public class UserController { } } + private Object[] of(Object ...params) { + return params; + } + } 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 4e5ebce..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 @@ -25,8 +25,9 @@ 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 authenticate(String targetUsername, String key) throws IllegalAccessException, IOException { + public void keyHasAccessToUser(String targetUsername, String key) throws IllegalAccessException, IOException { var userAuth = userAuthDAO.getUserAuth(key); if (userAuth == null) { throw new IllegalAccessException("Invalid authentication key"); @@ -39,11 +40,36 @@ public class AuthService { } } - public void authenticate(String key) throws IOException, IllegalAccessException { + /** + * 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 keyHasAccessToCupboard(String key) throws IOException, IllegalAccessException { 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 (userType != User.UserType.MANAGER) { + throw new IllegalAccessException("Provided key does not grant access to perform the requested operation"); + } } /** 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 91e3ba5..aaa8cb8 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 @@ -111,7 +111,7 @@ public class CupboardService { if (checkoutAmount <= 0) { throw new IllegalArgumentException("Amount must be greater than 0"); } - authService.authenticate(key); + authService.keyIsValid(key); Need need = cupboardDAO.getNeed(id); need.incrementCurrent(checkoutAmount); } @@ -124,6 +124,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/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java index 6ef6710..89697bf 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,11 +22,17 @@ import com.ufund.api.ufundapi.service.CupboardService; public class CupboardControllerTest { private CupboardController cupboardController; private CupboardService mockCupboardService; + private final String key = "dummyKey"; @BeforeEach public void setupCupboardDAO() { + AuthService 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 @@ -43,7 +50,7 @@ public class CupboardControllerTest { entry("type", "MONETARY") ); - var res = cupboardController.createNeed(needMap); + var res = cupboardController.createNeed(needMap, key); assertEquals(HttpStatus.OK, res.getStatusCode()); assertEquals(need, res.getBody()); @@ -58,7 +65,7 @@ public class CupboardControllerTest { entry("maxGoal", -100.0), entry("type", "MONETARY")); - var res = cupboardController.createNeed(needMap); + var res = cupboardController.createNeed(needMap, key); assertEquals(HttpStatus.BAD_REQUEST, res.getStatusCode()); } @@ -72,7 +79,7 @@ public class CupboardControllerTest { entry("maxGoal", 100.0), entry("type", "MONETARY")); - var res = cupboardController.createNeed(needMap); + var res = cupboardController.createNeed(needMap, key); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); } @@ -174,7 +181,7 @@ public class CupboardControllerTest { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); 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()); @@ -185,7 +192,7 @@ public class CupboardControllerTest { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); 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()); } @@ -196,7 +203,7 @@ public class CupboardControllerTest { 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,7 +213,7 @@ 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()); } @@ -217,7 +224,7 @@ public class CupboardControllerTest { 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()); } 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 cc7df40..06fb6cd 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 @@ -82,7 +82,7 @@ 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 response = userController.getUser(username, key); @@ -237,7 +237,7 @@ 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 @@ -298,7 +298,7 @@ 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 response = userController.deleteUser(username, key); 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 d3085e5..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 @@ -40,34 +40,34 @@ 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 { + 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.authenticate(username, key)); + 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)); } 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/need-page/need-page.component.ts b/ufund-ui/src/app/components/need-page/need-page.component.ts index 597d0e0..e38554c 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 @@ -2,30 +2,30 @@ import {Component, Input} from '@angular/core'; import {GoalType, Need} from '../../models/Need'; import {ActivatedRoute} from "@angular/router"; import {CupboardService} from "../../services/cupboard.service"; -import { NgFor } from '@angular/common'; +import {NgFor} from '@angular/common'; @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, + ) {} - 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(); + } +} diff --git a/ufund-ui/src/app/models/Need.ts b/ufund-ui/src/app/models/Need.ts index 9e97fd4..5cd4e39 100644 --- a/ufund-ui/src/app/models/Need.ts +++ b/ufund-ui/src/app/models/Need.ts @@ -1,13 +1,13 @@ export interface Need { - name: string, - id: number, - filterAttributes: string[], - type: GoalType; - maxGoal: number; - current: number; + name: string, + id: number, + filterAttributes: string[], + type: GoalType; + maxGoal: number; + current: number; } 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 -- cgit v1.2.3 From 0829feb20e60bc6d323dcc0d9376f4feb45115eb Mon Sep 17 00:00:00 2001 From: sowgro Date: Wed, 26 Mar 2025 18:23:17 -0400 Subject: Push starter code for Input() --- .../app/components/cupboard/cupboard.component.html | 8 ++++---- .../src/app/components/cupboard/cupboard.component.ts | 6 +++--- .../app/components/need-list/need-list.component.ts | 18 ++++++++++-------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 3ed06fb..c2d146b 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -1,6 +1,6 @@

          Cupboard

          - +

          Admin View

          @@ -23,7 +23,7 @@ {{statusText | async}} - +

          Update Need

          @@ -41,8 +41,8 @@ {{statusText | async}} - +

          - + diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index e38f8c0..cf9b95e 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, ViewChild } from '@angular/core'; +import {Component, Input, OnInit, ViewChild} from '@angular/core'; import { CupboardService } from '../../services/cupboard.service'; import { UsersService } from '../../services/users.service'; import { Need, GoalType } from '../../models/Need'; @@ -38,9 +38,9 @@ export class CupboardComponent implements OnInit { }; selectedNeedId: number | null = null; searchResults: any[] = []; - + selectForm(name: string) { - //get search results from the need list + //get search results from the need list if (this.needList) { this.searchResults = this.needList.searchResults; } 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 9ef191a..bf78d99 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,4 +1,4 @@ -import { Component } from '@angular/core'; +import {Component, Input} from '@angular/core'; import { NgForm } from '@angular/forms'; import {Need} from '../../models/Need'; import {CupboardService} from '../../services/cupboard.service'; @@ -15,6 +15,8 @@ export class NeedListComponent { needs: Need[] = []; searchResults: Need[] = []; + @Input() editF?: Function + constructor( private cupboardService: CupboardService, private usersService: UsersService @@ -43,7 +45,7 @@ export class NeedListComponent { } if (form) { this.searchDelay = setTimeout(() => { - + if (form) { const currentSearchValue = form.search; //latest value of the search this.cupboardService.searchNeeds(currentSearchValue).subscribe((n) => { @@ -58,9 +60,9 @@ export class NeedListComponent { clearTimeout(this.searchDelay); this.searchResults = this.needs; } - - + + } delete(id : number) { @@ -80,10 +82,10 @@ export class NeedListComponent { } changeText(id : number, text : string) { - const span = document.getElementById('hover-status-label-' + id); + const span = document.getElementById('hover-status-label-' + id); if (span) { span.innerHTML = ' ' + text; - } + } } add(need: Need) { @@ -101,7 +103,7 @@ export class NeedListComponent { } else { window.alert("This need is already in your basket!") } - + } @@ -140,4 +142,4 @@ export class NeedListComponent { button.style.visibility = 'hidden'; } } -} \ No newline at end of file +} -- cgit v1.2.3 From 0549991d0b32de4de544d16478ce5b2782c1809d Mon Sep 17 00:00:00 2001 From: benal01 Date: Wed, 26 Mar 2025 18:59:55 -0400 Subject: use (output) for need edit selection --- ufund-ui/src/app/components/cupboard/cupboard.component.html | 2 +- ufund-ui/src/app/components/need-list/need-list.component.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index c2d146b..4b76f25 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -1,6 +1,6 @@

          Cupboard

          - +

          Admin View

          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 bf78d99..2eed87d 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,4 +1,4 @@ -import {Component, Input} from '@angular/core'; +import {Component, Output, EventEmitter} from '@angular/core'; import { NgForm } from '@angular/forms'; import {Need} from '../../models/Need'; import {CupboardService} from '../../services/cupboard.service'; @@ -11,11 +11,11 @@ import { userType } from '../../models/User'; styleUrl: './need-list.component.css' }) export class NeedListComponent { - selectedNeed: Need | undefined; + selectedNeed: Need | null = null; needs: Need[] = []; searchResults: Need[] = []; - @Input() editF?: Function + @Output() currentNeed = new EventEmitter(); constructor( private cupboardService: CupboardService, @@ -114,6 +114,8 @@ export class NeedListComponent { } select(need : Need) { + //emit value + this.currentNeed.emit(need); if (this.selectedNeed) { //revert already selected need to previous style console.log(need.id); -- cgit v1.2.3 From 5dfb1327c4507ae1613debb5b485fd74edff33db Mon Sep 17 00:00:00 2001 From: sowgro Date: Wed, 26 Mar 2025 19:00:04 -0400 Subject: fix expiration logic and cleanup --- ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java | 2 +- .../main/java/com/ufund/api/ufundapi/persistence/UserAuthFIleDAO.java | 2 +- .../src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) 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 786b104..22e86e3 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 @@ -38,7 +38,7 @@ public class Need { * @param maxGoal The maximum goal for this need * @param type The type of need (monetary, physical) */ - public Need(String name, GoalType type, double maxGoal) { // TODO why is this needed + public Need(String name, GoalType type, double maxGoal) { this.name = name; this.type = type; this.maxGoal = maxGoal; 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 9023b42..7bda3f9 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 @@ -37,7 +37,7 @@ public class UserAuthFIleDAO implements UserAuthDAO { UserAuth[] userAuthKeysArray = objectMapper.readValue(new File(filename), UserAuth[].class); for (UserAuth userAuth : userAuthKeysArray) { - if (userAuth.getExpiration().compareTo(LocalDateTime.now()) > -1) { // Someone else double check the logic is correct. Checks if auth is valid and adds if so + if (userAuth.getExpiration().isBefore(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 0d9b9e4..4b09449 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 @@ -81,7 +81,8 @@ public class UserFileDAO implements UserDAO { public User updateUser(User user) throws IOException { synchronized (users) { if (users.containsKey(user.getUsername())) { - if (user.getBasket() == null || user.getType() == null) { // TODO clean this up + if (user.getBasket() == null || user.getType() == null) { + System.err.println("CRUTCH HAPPENED"); User oldData = users.get(user.getUsername()); User crutch = new User(oldData.getUsername(), 0, new ArrayList<>(), oldData.getType()); crutch.copyPassword(oldData); -- cgit v1.2.3 From 959aa5101fbba55f20eda46d02addd27a74cf950 Mon Sep 17 00:00:00 2001 From: benal01 Date: Wed, 26 Mar 2025 19:03:16 -0400 Subject: snap form open on edit event --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index cf9b95e..0d2c1f5 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -66,6 +66,7 @@ export class CupboardComponent implements OnInit { } populateForm(need: any): void { + this.selectForm('update'); this.selectedNeed = { ...need }; } -- cgit v1.2.3 From 959b5bbaaa370542b75d804cedbbbecea881df0f Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Wed, 26 Mar 2025 19:12:46 -0400 Subject: Added a progress bar to signup --- ufund-ui/src/app/components/signup/signup.component.css | 8 ++++++++ ufund-ui/src/app/components/signup/signup.component.html | 1 + 2 files changed, 9 insertions(+) diff --git a/ufund-ui/src/app/components/signup/signup.component.css b/ufund-ui/src/app/components/signup/signup.component.css index 2a10016..d4ea97b 100644 --- a/ufund-ui/src/app/components/signup/signup.component.css +++ b/ufund-ui/src/app/components/signup/signup.component.css @@ -14,3 +14,11 @@ background-color: white; box-shadow: 0 0 10px 10px black; } + +#bar { + width: 100%; + height: 10px; + padding: 0; + margin: 0; +} + diff --git a/ufund-ui/src/app/components/signup/signup.component.html b/ufund-ui/src/app/components/signup/signup.component.html index 742b8cf..5b1b4f7 100644 --- a/ufund-ui/src/app/components/signup/signup.component.html +++ b/ufund-ui/src/app/components/signup/signup.component.html @@ -2,6 +2,7 @@ + {{statusText | async}} {{strength | async}} Account created Proceed to login -- cgit v1.2.3 From d5ae670dbce9e5cabbd594759df490176fd8cecd Mon Sep 17 00:00:00 2001 From: benal01 Date: Wed, 26 Mar 2025 19:12:52 -0400 Subject: use selected id for the update form --- ufund-ui/src/app/components/cupboard/cupboard.component.html | 1 - ufund-ui/src/app/components/cupboard/cupboard.component.ts | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 4b76f25..d54eed9 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -29,7 +29,6 @@

          Update Need


          -



          diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 0d2c1f5..a8b9c14 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -79,14 +79,13 @@ export class CupboardComponent implements OnInit { console.log(form); const need: Need = { name: form.name, - id: form.id, //system will control this + id: this.selectedNeed.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) { -- cgit v1.2.3 From 350a120eb0a578aa468b903a83f47168d6b8db13 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Wed, 26 Mar 2025 19:20:26 -0400 Subject: Fixed expiration and authDAO test --- .../main/java/com/ufund/api/ufundapi/persistence/UserAuthFIleDAO.java | 2 +- .../java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 7bda3f9..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 @@ -37,7 +37,7 @@ public class UserAuthFIleDAO implements UserAuthDAO { UserAuth[] userAuthKeysArray = objectMapper.readValue(new File(filename), UserAuth[].class); for (UserAuth userAuth : userAuthKeysArray) { - if (userAuth.getExpiration().isBefore(LocalDateTime.now())) { + if (userAuth.getExpiration().isAfter(LocalDateTime.now())) { userAuthMap.put(userAuth.getKey(), userAuth); } } 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 5e92deb..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 @@ -43,7 +43,7 @@ public class UserAuthFileDAOTest { String key = "123"; UserAuth auth = userAuthFIleDAO.getUserAuth(key); - assertEquals(auth, userAuths[0]); + assertEquals(userAuths[0], auth); } @Test -- cgit v1.2.3 From 057efa1b557d5d874300c6cda8c7d74519c946d6 Mon Sep 17 00:00:00 2001 From: benal01 Date: Thu, 27 Mar 2025 08:50:12 -0400 Subject: use instead of table with *ngFor for sort algorithms --- .../src/app/components/need-list/need-list.component.html | 15 ++++++--------- .../src/app/components/need-list/need-list.component.ts | 1 + 2 files changed, 7 insertions(+), 9 deletions(-) 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 de4be58..9799493 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,14 +1,11 @@

          Needs List

          -
          -

          Sort by:

          - -

          -

          -

          -

          -
          -
          + +
          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 208045f..c1063ce 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 @@ -45,6 +45,7 @@ export class NeedListComponent { selectedNeed: Need | null = null; needs: Need[] = []; searchResults: Need[] = []; + sortSelection: string = ''; currentSortAlgo: sortAlgo = sortByMaxGoal; SortingAlgoArrays: {func:sortAlgo,name:string}[] = [ -- cgit v1.2.3 From 84083e7229678c30d827270bfa25de66a02d7b8c Mon Sep 17 00:00:00 2001 From: benal01 Date: Thu, 27 Mar 2025 08:54:06 -0400 Subject: display name for algorithms --- ufund-ui/src/app/components/need-list/need-list.component.html | 2 +- ufund-ui/src/app/components/need-list/need-list.component.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) 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 9799493..a653527 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 @@ -3,7 +3,7 @@ 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 c1063ce..2fdd993 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 @@ -48,11 +48,11 @@ export class NeedListComponent { sortSelection: string = ''; currentSortAlgo: sortAlgo = sortByMaxGoal; - SortingAlgoArrays: {func:sortAlgo,name:string}[] = [ - {func:sortByMaxGoal,name:"sortByMaxGoal"}, - {func:sortByName,name:"sortByName"}, - {func:sortByNameReverse,name:"sortByNameReverse"}, - {func:sortByMinGoal,name:"sortByMinGoal"}, + SortingAlgoArrays: {func:sortAlgo,name:string,display:string}[] = [ + {func:sortByMaxGoal,name:"sortByMaxGoal", display:"Max Goal"}, + {func:sortByName,name:"sortByName", display:"Name"}, + {func:sortByNameReverse,name:"sortByNameReverse", display:"Name (reverse)"}, + {func:sortByMinGoal,name:"sortByMinGoal", display:"Min Goal"}, ]; @Output() currentNeed = new EventEmitter(); -- cgit v1.2.3 From 65590e6dfbed90e4acd342a72feb8d7b5120d70c Mon Sep 17 00:00:00 2001 From: benal01 Date: Thu, 27 Mar 2025 09:49:41 -0400 Subject: refactor sorting to use acending descending toggle --- .../components/need-list/need-list.component.html | 5 ++- .../components/need-list/need-list.component.ts | 46 +++++++++++++--------- 2 files changed, 31 insertions(+), 20 deletions(-) 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 a653527..5be915c 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 @@ -3,9 +3,12 @@ +
          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 2fdd993..97be0cb 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 @@ -17,11 +17,7 @@ const sortByName: sortAlgo = (a: Need, b: Need): number => { return 1; } -const sortByNameReverse: sortAlgo = (a: Need, b: Need): number => { - return sortByName(a,b)*-1; -} - -const sortByMaxGoal: sortAlgo = (a: Need, b: Need): number => { +const sortByGoal: sortAlgo = (a: Need, b: Need): number => { if(a.maxGoal == b.maxGoal) { return sortByName(a,b); } @@ -31,10 +27,6 @@ const sortByMaxGoal: sortAlgo = (a: Need, b: Need): number => { return 1; } -const sortByMinGoal: sortAlgo = (a: Need, b: Need): number => { - return sortByMaxGoal(a,b)*-1; -} - @Component({ selector: 'app-need-list', standalone: false, @@ -45,14 +37,13 @@ export class NeedListComponent { selectedNeed: Need | null = null; needs: Need[] = []; searchResults: Need[] = []; + sortMode = 'Ascending' sortSelection: string = ''; - currentSortAlgo: sortAlgo = sortByMaxGoal; + currentSortAlgo: sortAlgo = sortByGoal; - SortingAlgoArrays: {func:sortAlgo,name:string,display:string}[] = [ - {func:sortByMaxGoal,name:"sortByMaxGoal", display:"Max Goal"}, - {func:sortByName,name:"sortByName", display:"Name"}, - {func:sortByNameReverse,name:"sortByNameReverse", display:"Name (reverse)"}, - {func:sortByMinGoal,name:"sortByMinGoal", display:"Min Goal"}, + SortingAlgoArrays: {func:sortAlgo,name:string, display:string[]}[] = [ + {func:sortByGoal,name:"sortByMaxGoal", display:["Max Goal", "Min Goal"]}, + {func:sortByName,name:"sortByName", display:["Name", "Name (Descending)"]}, ]; @Output() currentNeed = new EventEmitter(); @@ -64,22 +55,34 @@ export class NeedListComponent { refresh() { this.cupboardService.getNeeds().subscribe(n => { - this.needs = n.sort(this.currentSortAlgo); + if (this.sortMode == 'Ascending') { + this.needs = n.sort(this.currentSortAlgo); + } else { + this.needs = n.sort(this.currentSortAlgo).reverse(); + } this.searchResults = this.needs; }); - console.log(this.searchResults); } ngOnInit(): void { this.refresh() } + changeSortMode(form : any) { + if (this.sortMode == 'Ascending'){ + this.sortMode = 'Descending' + } else { + this.sortMode = 'Ascending' + } + this.search(form) + } + changeSortAlgo(algoName: string, form: any) { console.log(algoName); this.SortingAlgoArrays.forEach(algo => { if(algo.name === algoName) { this.currentSortAlgo = algo.func; - console.log("changed sorting algorithm to: ", algo.name) + console.log("changed sorting algorithm to: ", algo.name + this.sortMode) return } }); @@ -102,7 +105,12 @@ export class NeedListComponent { if (form) { const currentSearchValue = form.search; //latest value of the search this.cupboardService.searchNeeds(currentSearchValue).subscribe((n) => { - this.searchResults = n.sort(this.currentSortAlgo); + if (this.sortMode == 'Ascending') { + this.searchResults = n.sort(this.currentSortAlgo); + } else { + this.searchResults = n.sort(this.currentSortAlgo).reverse(); + } + console.log(currentSearchValue, this.searchResults); }); } -- cgit v1.2.3 From ee4154df85a971f3a0f8e43fd6afdfa6a620ea99 Mon Sep 17 00:00:00 2001 From: benal01 Date: Thu, 27 Mar 2025 10:09:19 -0400 Subject: refactor change sort algo func with [(ngModel)] binding --- .../components/need-list/need-list.component.html | 2 +- .../components/need-list/need-list.component.ts | 25 ++++++++++------------ 2 files changed, 12 insertions(+), 15 deletions(-) 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 5be915c..4f259a0 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,7 +1,7 @@

          Needs List

          - 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 97be0cb..177d9f7 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 @@ -38,8 +38,9 @@ export class NeedListComponent { needs: Need[] = []; searchResults: Need[] = []; sortMode = 'Ascending' - sortSelection: string = ''; + currentSortAlgo: sortAlgo = sortByGoal; + sortSelection: string = this.currentSortAlgo.name; SortingAlgoArrays: {func:sortAlgo,name:string, display:string[]}[] = [ {func:sortByGoal,name:"sortByMaxGoal", display:["Max Goal", "Min Goal"]}, @@ -77,19 +78,6 @@ export class NeedListComponent { this.search(form) } - changeSortAlgo(algoName: string, form: any) { - console.log(algoName); - this.SortingAlgoArrays.forEach(algo => { - if(algo.name === algoName) { - this.currentSortAlgo = algo.func; - console.log("changed sorting algorithm to: ", algo.name + this.sortMode) - return - } - }); - this.refresh() - this.search(form); - } - private searchDelay: any; async search(form: any) { @@ -103,6 +91,15 @@ export class NeedListComponent { this.searchDelay = setTimeout(() => { 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') { -- cgit v1.2.3 From 0b4c76c5dc7313ae42c62be3c682c1f88cec13fd Mon Sep 17 00:00:00 2001 From: benal01 Date: Thu, 27 Mar 2025 10:36:32 -0400 Subject: defaut value for sorting --- ufund-ui/src/app/components/need-list/need-list.component.html | 2 +- ufund-ui/src/app/components/need-list/need-list.component.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 4f259a0..693307f 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,7 +1,7 @@

          Needs List

          - 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 177d9f7..f935e03 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 @@ -40,10 +40,10 @@ export class NeedListComponent { sortMode = 'Ascending' currentSortAlgo: sortAlgo = sortByGoal; - sortSelection: string = this.currentSortAlgo.name; + sortSelection: string = 'sortByGoal'; SortingAlgoArrays: {func:sortAlgo,name:string, display:string[]}[] = [ - {func:sortByGoal,name:"sortByMaxGoal", display:["Max Goal", "Min Goal"]}, + {func:sortByGoal,name:"sortByGoal", display:["Max Goal", "Min Goal"]}, {func:sortByName,name:"sortByName", display:["Name", "Name (Descending)"]}, ]; -- cgit v1.2.3 From 7ccbfb414de47941c8acb2e6f9c2cc7a01cd819c Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Thu, 27 Mar 2025 18:47:07 -0400 Subject: Added requirements list, updated bar, and disabling of creation with weak passwords. --- .../src/app/components/signup/signup.component.css | 13 +++++++--- .../app/components/signup/signup.component.html | 10 +++++++- .../src/app/components/signup/signup.component.ts | 29 +++++++++++++++------- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/ufund-ui/src/app/components/signup/signup.component.css b/ufund-ui/src/app/components/signup/signup.component.css index d4ea97b..799cbd2 100644 --- a/ufund-ui/src/app/components/signup/signup.component.css +++ b/ufund-ui/src/app/components/signup/signup.component.css @@ -17,8 +17,15 @@ #bar { width: 100%; - height: 10px; - padding: 0; - margin: 0; + height: 20px; + -webkit-appearance: none; + appearance: none; + border: none; + border-radius: 10px; + overflow: hidden; + background-color: red; } +#requirement2 { + color: red; +} diff --git a/ufund-ui/src/app/components/signup/signup.component.html b/ufund-ui/src/app/components/signup/signup.component.html index 5b1b4f7..1b50d39 100644 --- a/ufund-ui/src/app/components/signup/signup.component.html +++ b/ufund-ui/src/app/components/signup/signup.component.html @@ -1,8 +1,16 @@

          Signup:

          - + + +
          {{test | async}}
          + + + + {{requirement}} + + {{statusText | async}} {{strength | async}} Account created Proceed to login diff --git a/ufund-ui/src/app/components/signup/signup.component.ts b/ufund-ui/src/app/components/signup/signup.component.ts index 48c6387..10fbce5 100644 --- a/ufund-ui/src/app/components/signup/signup.component.ts +++ b/ufund-ui/src/app/components/signup/signup.component.ts @@ -2,6 +2,7 @@ import { Component } from '@angular/core'; import {UsersService} from '../../services/users.service'; import {Router} from '@angular/router'; import {BehaviorSubject} from 'rxjs'; +import {Need} from '../../models/Need'; @Component({ selector: 'app-signup', @@ -13,8 +14,11 @@ export class SignupComponent { protected statusText = new BehaviorSubject("") protected showSuccessMessage = new BehaviorSubject(false) - protected passwordStrength = new BehaviorSubject("") + protected passwordStrongEnough = new BehaviorSubject(true) + passwordRequirements: String[] = [("❌ Password length"), ("❌ Lowercase letters")]; protected strength = new BehaviorSubject(0) + protected color = new BehaviorSubject("red") + protected test = new BehaviorSubject("Password does not meet requirements") constructor( protected usersService: UsersService, @@ -36,7 +40,12 @@ export class SignupComponent { } checkPasswordStrength(password: string) { + this.passwordRequirements = [("❌ Password length"), ("❌ Lowercase letters")]; + this.test.next("Password does not meet requirements") this.statusText.next("") + this.passwordStrongEnough.next(true) + this.color.next("red") + if (password.match(/[^!-~]/g)) { this.statusText.next("Invalid characters") return @@ -45,32 +54,34 @@ export class SignupComponent { let strength = 0; if (password.length > 6) { strength++ - console.log("Long") + this.passwordRequirements[0] = "✅ Password length" + this.color.next("green") } if (password.length > 12) { strength++ - console.log("Longer") } if (password.match(/[a-z]/g)) { strength++ - console.log("a") } - if (password.match(/[0-9]/g)) { + if (password.match(/[A-Z]/g)) { strength++ - console.log("0") } - if (password.match(/[A-Z]/g)) { + if (password.match(/[0-9]/g)) { strength++ - console.log("A") } if (password.match(/[!-/]/g)) { strength++ - console.log("!") + } + + if (strength >= 5) { + this.passwordStrongEnough.next(false) + this.test.next("") } this.strength.next(strength) } + protected readonly length = length; } let friendlyHttpStatus: {[key: number]: string} = { -- cgit v1.2.3 From 451a9abd5a4c461ccbb0b7b7d51b78dbfe12ec54 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Thu, 27 Mar 2025 18:47:26 -0400 Subject: Added requirements list, updated bar, and disabling of creation with weak passwords. --- ufund-ui/src/app/components/signup/signup.component.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/ufund-ui/src/app/components/signup/signup.component.ts b/ufund-ui/src/app/components/signup/signup.component.ts index 10fbce5..9532e42 100644 --- a/ufund-ui/src/app/components/signup/signup.component.ts +++ b/ufund-ui/src/app/components/signup/signup.component.ts @@ -2,7 +2,6 @@ import { Component } from '@angular/core'; import {UsersService} from '../../services/users.service'; import {Router} from '@angular/router'; import {BehaviorSubject} from 'rxjs'; -import {Need} from '../../models/Need'; @Component({ selector: 'app-signup', -- cgit v1.2.3 From 4f5e9e9ecda282a98af5d70bd6cf0540973c7314 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 27 Mar 2025 18:47:27 -0400 Subject: Remove crutch --- .../com/ufund/api/ufundapi/persistence/UserFileDAO.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java index 4b09449..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,7 +2,6 @@ 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; @@ -81,16 +80,8 @@ public class UserFileDAO implements UserDAO { public User updateUser(User user) throws IOException { synchronized (users) { if (users.containsKey(user.getUsername())) { - if (user.getBasket() == null || user.getType() == null) { - System.err.println("CRUTCH HAPPENED"); - User oldData = users.get(user.getUsername()); - User crutch = new User(oldData.getUsername(), 0, new ArrayList<>(), oldData.getType()); - crutch.copyPassword(oldData); - users.put(user.getUsername(), crutch); - } else { - var old = users.put(user.getUsername(), user); - user.copyPassword(Objects.requireNonNull(old)); - } + var old = users.put(user.getUsername(), user); + user.copyPassword(Objects.requireNonNull(old)); save(); return user; } else { -- cgit v1.2.3 From fb4e2bc3eb66ca861eb8393ade21811e4510669a Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 28 Mar 2025 19:09:53 -0400 Subject: Start implementation new design --- ufund-ui/public/jf.png | Bin 0 -> 1159826 bytes ufund-ui/src/app/app.component.css | 25 +++++++++++++---- ufund-ui/src/app/app.component.html | 6 ++--- .../components/home-page/home-page.component.css | 30 +++++++++++++++++++++ .../components/home-page/home-page.component.html | 12 +++++++-- .../src/app/components/login/login.component.css | 8 ++++-- ufund-ui/src/index.html | 4 +++ ufund-ui/src/styles.css | 19 ++++++++++--- 8 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 ufund-ui/public/jf.png diff --git a/ufund-ui/public/jf.png b/ufund-ui/public/jf.png new file mode 100644 index 0000000..bbf95d5 Binary files /dev/null and b/ufund-ui/public/jf.png differ diff --git a/ufund-ui/src/app/app.component.css b/ufund-ui/src/app/app.component.css index 17bbed7..5596cf8 100644 --- a/ufund-ui/src/app/app.component.css +++ b/ufund-ui/src/app/app.component.css @@ -8,23 +8,38 @@ display: flex; flex-direction: row; justify-content: space-between; - border-bottom: light-dark(#d3d3d3, black) solid 1px; - padding: 0 10px; - background-color: light-dark(#f5f5f5, #2e2e2e); + /*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: 10px; + 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 { + /*color: light-dark(black, white)*/ + text-decoration: underline; } } diff --git a/ufund-ui/src/app/app.component.html b/ufund-ui/src/app/app.component.html index 3058117..b0ee329 100644 --- a/ufund-ui/src/app/app.component.html +++ b/ufund-ui/src/app/app.component.html @@ -1,14 +1,14 @@
          - +

          Location: {{need?.location}}

          Goal: {{need?.maxGoal}}

          Current: {{need?.current}}

          +

          Urgent: {{need?.urgent}}

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

          \ No newline at end of file -- cgit v1.2.3 From 785d0df231d0cfdbf63f5ed60b56fb882f694725 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sat, 29 Mar 2025 15:28:59 -0400 Subject: Finished implementing signup page and checked for the majority of edge cases. --- .../src/app/components/signup/signup.component.css | 23 +++++-- .../app/components/signup/signup.component.html | 23 +++---- .../src/app/components/signup/signup.component.ts | 80 ++++++++++++++++------ 3 files changed, 85 insertions(+), 41 deletions(-) diff --git a/ufund-ui/src/app/components/signup/signup.component.css b/ufund-ui/src/app/components/signup/signup.component.css index 799cbd2..2fa5051 100644 --- a/ufund-ui/src/app/components/signup/signup.component.css +++ b/ufund-ui/src/app/components/signup/signup.component.css @@ -16,16 +16,27 @@ } #bar { + height: 5px; width: 100%; - height: 20px; - -webkit-appearance: none; appearance: none; - border: none; - border-radius: 10px; overflow: hidden; - background-color: red; + margin-top: -5px; } -#requirement2 { +#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; } + diff --git a/ufund-ui/src/app/components/signup/signup.component.html b/ufund-ui/src/app/components/signup/signup.component.html index 1b50d39..e078123 100644 --- a/ufund-ui/src/app/components/signup/signup.component.html +++ b/ufund-ui/src/app/components/signup/signup.component.html @@ -1,16 +1,13 @@

          Signup:

          - - - - -
          {{test | async}}
          - - - - - {{requirement}} + +{{usernameStatusText | async}} + + +{{statusText | async}} + + {{requirement.title}} - -{{statusText | async}} -{{strength | async}} + +{{passwordStatusText | async}} + Account created Proceed to login diff --git a/ufund-ui/src/app/components/signup/signup.component.ts b/ufund-ui/src/app/components/signup/signup.component.ts index 9532e42..b3432e6 100644 --- a/ufund-ui/src/app/components/signup/signup.component.ts +++ b/ufund-ui/src/app/components/signup/signup.component.ts @@ -1,23 +1,34 @@ -import { Component } from '@angular/core'; +import {Component, ElementRef, ViewChild} from '@angular/core'; import {UsersService} from '../../services/users.service'; import {Router} from '@angular/router'; import {BehaviorSubject} from 'rxjs'; +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 statusText = new BehaviorSubject("") + protected passwordStatusText = new BehaviorSubject("") + protected usernameStatusText = new BehaviorSubject("") protected showSuccessMessage = new BehaviorSubject(false) - protected passwordStrongEnough = new BehaviorSubject(true) - passwordRequirements: String[] = [("❌ Password length"), ("❌ Lowercase letters")]; + protected passwordStrongEnough = new BehaviorSubject(false) + protected ableToCreateAccount = new BehaviorSubject(false) + protected passwordRequirements: PasswordRequirements = new PasswordRequirements() protected strength = new BehaviorSubject(0) - protected color = new BehaviorSubject("red") - protected test = new BehaviorSubject("Password does not meet requirements") constructor( protected usersService: UsersService, @@ -38,49 +49,74 @@ export class SignupComponent { }) } + comparePassword(username: string, passConfirm:string, password: string) { + this.passwordStatusText.next("") + this.usernameStatusText.next("") + this.checkPasswordStrength(password); + + if (username === "") { + this.usernameStatusText.next("Username field can't be blank") + } + + if (!(password === passConfirm) && !!passConfirm) { + this.passwordStatusText.next("Passwords don't match") + } + this.ableToCreateAccount.next(this.passwordStrongEnough.getValue() && password === passConfirm && !!username) + } + checkPasswordStrength(password: string) { - this.passwordRequirements = [("❌ Password length"), ("❌ Lowercase letters")]; - this.test.next("Password does not meet requirements") - this.statusText.next("") - this.passwordStrongEnough.next(true) - this.color.next("red") + this.strength.next(0) + this.passwordRequirements = new PasswordRequirements() + this.passwordStrongEnough.next(false) if (password.match(/[^!-~]/g)) { this.statusText.next("Invalid characters") + return } - let strength = 0; if (password.length > 6) { - strength++ - this.passwordRequirements[0] = "✅ Password length" - this.color.next("green") + this.passwordRequirements.sixLong.value = true } if (password.length > 12) { - strength++ + this.passwordRequirements.twelveLong.value = true } if (password.match(/[a-z]/g)) { - strength++ + this.passwordRequirements.lowercase.value = true } if (password.match(/[A-Z]/g)) { - strength++ + this.passwordRequirements.uppercase.value = true } if (password.match(/[0-9]/g)) { - strength++ + this.passwordRequirements.number.value = true } - if (password.match(/[!-/]/g)) { - strength++ + 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(false) - this.test.next("") + this.passwordStrongEnough.next(true) + this.statusText.next("") + } else if (strength == 0) { + this.statusText.next("") + } else { + this.statusText.next("Password does not meet requirements") } 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} = { -- cgit v1.2.3 From b539c504782072fe933668b893c708bf577443dd Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sat, 29 Mar 2025 15:29:16 -0400 Subject: Finished implementing signup page and checked for the majority of edge cases. --- ufund-ui/src/app/components/signup/signup.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ufund-ui/src/app/components/signup/signup.component.ts b/ufund-ui/src/app/components/signup/signup.component.ts index b3432e6..383d6a7 100644 --- a/ufund-ui/src/app/components/signup/signup.component.ts +++ b/ufund-ui/src/app/components/signup/signup.component.ts @@ -1,4 +1,4 @@ -import {Component, ElementRef, ViewChild} from '@angular/core'; +import {Component} from '@angular/core'; import {UsersService} from '../../services/users.service'; import {Router} from '@angular/router'; import {BehaviorSubject} from 'rxjs'; -- cgit v1.2.3 From 41c92354536d5545dee97e368b3a4b3c25c1a77f Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sat, 29 Mar 2025 15:47:46 -0400 Subject: Added emojis before requirements --- .../src/app/components/signup/signup.component.html | 8 ++++++++ ufund-ui/src/app/components/signup/signup.component.ts | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ufund-ui/src/app/components/signup/signup.component.html b/ufund-ui/src/app/components/signup/signup.component.html index e078123..e282a9c 100644 --- a/ufund-ui/src/app/components/signup/signup.component.html +++ b/ufund-ui/src/app/components/signup/signup.component.html @@ -1,13 +1,21 @@

          Signup:

          {{usernameStatusText | async}} + + + {{statusText | async}} + {{requirement.title}} + + {{passwordStatusText | async}} + + Account created Proceed to login diff --git a/ufund-ui/src/app/components/signup/signup.component.ts b/ufund-ui/src/app/components/signup/signup.component.ts index 383d6a7..60f4098 100644 --- a/ufund-ui/src/app/components/signup/signup.component.ts +++ b/ufund-ui/src/app/components/signup/signup.component.ts @@ -4,12 +4,12 @@ import {Router} from '@angular/router'; import {BehaviorSubject} from 'rxjs'; 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} + 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({ @@ -76,21 +76,27 @@ export class SignupComponent { } if (password.length > 6) { + this.passwordRequirements.sixLong.title = '✅ Is 6 characters or longer' this.passwordRequirements.sixLong.value = true } if (password.length > 12) { + this.passwordRequirements.twelveLong.title = '✅ Is 12 characters or longer' this.passwordRequirements.twelveLong.value = true } if (password.match(/[a-z]/g)) { + this.passwordRequirements.lowercase.title = '✅ Includes lowercase letter' this.passwordRequirements.lowercase.value = true } if (password.match(/[A-Z]/g)) { + this.passwordRequirements.uppercase.title = '✅ Includes uppercase letter' this.passwordRequirements.uppercase.value = true } if (password.match(/[0-9]/g)) { + this.passwordRequirements.number.title = '✅ Includes number' this.passwordRequirements.number.value = true } if (password.match(/[^A-Za-z0-9]/g)) { + this.passwordRequirements.symbol.title = '✅ Includes symbol' this.passwordRequirements.symbol.value = true } -- cgit v1.2.3 From 88650361adfc9be8344b0d383100b0c6ab513973 Mon Sep 17 00:00:00 2001 From: benal01 Date: Sun, 30 Mar 2025 00:33:41 -0400 Subject: basic css and info display for needs --- .../src/app/components/need-list/need-list.component.css | 13 +++++++++++-- .../src/app/components/need-list/need-list.component.html | 9 ++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) 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 19c126f..345326f 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 @@ -31,12 +31,21 @@ li { > button { background-color: transparent; width: 88%; - float: left; transition: all 0.3s ease; font-weight: bold; - display: flex; border: none; border-radius: 5px; + padding-left: 1.5%; + > section { + width: 100%; + flex: none; + display: inline-block; + background-color: magenta; + > progress { + width: 25%; + float: none; + } + } } > section { 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 ed151a3..88b9752 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 @@ -28,7 +28,14 @@
          • -- cgit v1.2.3 From daae556a1be7a30bc6f4606bd1b1567b713d054a Mon Sep 17 00:00:00 2001 From: benal01 Date: Sun, 30 Mar 2025 00:39:23 -0400 Subject: better display for urgency --- ufund-ui/src/app/components/need-list/need-list.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 88b9752..866e5e4 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 @@ -28,7 +28,7 @@
            • - + {{statusText | async}} diff --git a/ufund-ui/src/app/components/signup/signup.component.css b/ufund-ui/src/app/components/signup/signup.component.css index 2fa5051..f286cf9 100644 --- a/ufund-ui/src/app/components/signup/signup.component.css +++ b/ufund-ui/src/app/components/signup/signup.component.css @@ -1,8 +1,13 @@ -:host, .border { +:host { display: flex; flex-direction: column; max-width: 300px; - gap: 5px + gap: 10px; + + & > div { + display: flex; + flex-direction: column; + } } .border { @@ -20,7 +25,7 @@ width: 100%; appearance: none; overflow: hidden; - margin-top: -5px; + /*margin-top: -5px;*/ } #bar::-webkit-progress-bar { diff --git a/ufund-ui/src/app/components/signup/signup.component.html b/ufund-ui/src/app/components/signup/signup.component.html index e282a9c..ebedc2a 100644 --- a/ufund-ui/src/app/components/signup/signup.component.html +++ b/ufund-ui/src/app/components/signup/signup.component.html @@ -1,21 +1,26 @@

              Signup:

              - -{{usernameStatusText | async}} - - - - - -{{statusText | async}} - - - {{requirement.title}} - - - - -{{passwordStatusText | async}} - - - -Account created Proceed to login +
              + + {{usernameStatusText | async}} +
              + +
              + + + {{passwordStatusText | async}} + + + {{requirement.title}} + +
              + +
              + + {{confirmPassStatusText | async}} +
              + +
              + + Account created Proceed to login + {{statusText | async}} +
              diff --git a/ufund-ui/src/app/components/signup/signup.component.ts b/ufund-ui/src/app/components/signup/signup.component.ts index 60f4098..3b43287 100644 --- a/ufund-ui/src/app/components/signup/signup.component.ts +++ b/ufund-ui/src/app/components/signup/signup.component.ts @@ -4,12 +4,12 @@ import {Router} from '@angular/router'; import {BehaviorSubject} from 'rxjs'; 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} + 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({ @@ -21,14 +21,15 @@ class PasswordRequirements { export class SignupComponent { - protected statusText = new BehaviorSubject("") protected passwordStatusText = new BehaviorSubject("") + protected confirmPassStatusText = new BehaviorSubject("") 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, @@ -49,8 +50,8 @@ export class SignupComponent { }) } - comparePassword(username: string, passConfirm:string, password: string) { - this.passwordStatusText.next("") + validate(username: string, passConfirm:string, password: string) { + this.confirmPassStatusText.next("") this.usernameStatusText.next("") this.checkPasswordStrength(password); @@ -59,7 +60,7 @@ export class SignupComponent { } if (!(password === passConfirm) && !!passConfirm) { - this.passwordStatusText.next("Passwords don't match") + this.confirmPassStatusText.next("Passwords don't match") } this.ableToCreateAccount.next(this.passwordStrongEnough.getValue() && password === passConfirm && !!username) } @@ -70,33 +71,27 @@ export class SignupComponent { this.passwordStrongEnough.next(false) if (password.match(/[^!-~]/g)) { - this.statusText.next("Invalid characters") + this.passwordStatusText.next("Invalid characters") return } if (password.length > 6) { - this.passwordRequirements.sixLong.title = '✅ Is 6 characters or longer' this.passwordRequirements.sixLong.value = true } if (password.length > 12) { - this.passwordRequirements.twelveLong.title = '✅ Is 12 characters or longer' this.passwordRequirements.twelveLong.value = true } if (password.match(/[a-z]/g)) { - this.passwordRequirements.lowercase.title = '✅ Includes lowercase letter' this.passwordRequirements.lowercase.value = true } if (password.match(/[A-Z]/g)) { - this.passwordRequirements.uppercase.title = '✅ Includes uppercase letter' this.passwordRequirements.uppercase.value = true } if (password.match(/[0-9]/g)) { - this.passwordRequirements.number.title = '✅ Includes number' this.passwordRequirements.number.value = true } if (password.match(/[^A-Za-z0-9]/g)) { - this.passwordRequirements.symbol.title = '✅ Includes symbol' this.passwordRequirements.symbol.value = true } @@ -107,11 +102,11 @@ export class SignupComponent { if (strength >= 5) { this.passwordStrongEnough.next(true) - this.statusText.next("") + this.passwordStatusText.next("") } else if (strength == 0) { - this.statusText.next("") + this.passwordStatusText.next("") } else { - this.statusText.next("Password does not meet requirements") + this.passwordStatusText.next("Password does not meet requirements") } this.strength.next(strength) -- cgit v1.2.3 From 42725635e70426c4d2923c680609da8277c693ea Mon Sep 17 00:00:00 2001 From: sowgro Date: Sun, 30 Mar 2025 14:44:04 -0400 Subject: fix imports in need-list.component.ts --- .../components/need-list/need-list.component.ts | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index 2bbacb0..66e53e8 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 @@ -3,6 +3,8 @@ import {Need} from '../../models/Need'; import {CupboardService} from '../../services/cupboard.service'; import { UsersService } from '../../services/users.service'; import { userType } from '../../models/User'; +import {AuthService} from '../../services/auth.service'; +import {catchError, of} from 'rxjs'; interface sortAlgo { (a: Need,b: Need): number; @@ -72,7 +74,8 @@ export class NeedListComponent { constructor( private cupboardService: CupboardService, - private usersService: UsersService + private usersService: UsersService, + private authService: AuthService ) {} refresh() { @@ -148,12 +151,12 @@ export class NeedListComponent { } 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); } @@ -165,17 +168,19 @@ export class NeedListComponent { } 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!") } -- cgit v1.2.3 From 5c49027cbccf913130d864db127f3ebf9dea9d15 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sun, 30 Mar 2025 15:50:56 -0400 Subject: Added additional tests to bring coverage up to 100# on controllers --- .../ufundapi/controller/CupboardController.java | 2 +- .../controller/CupboardControllerTest.java | 137 ++++++++++++++++++++- 2 files changed, 135 insertions(+), 4 deletions(-) diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java index 55ee457..bbfd3f6 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 @@ -182,7 +182,7 @@ public class CupboardController { /** * Checks out a need by checkoutAmount * - * @param data JSON object with paramters needID and amount + * @param data JSON object with parameters needID and amount * @param key Key used to authenticate user * @return OK if successful, other statuses if failure */ 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 89697bf..d775d14 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 @@ -23,10 +23,11 @@ public class CupboardControllerTest { private CupboardController cupboardController; private CupboardService mockCupboardService; private final String key = "dummyKey"; + private AuthService mockAuthService; @BeforeEach public void setupCupboardDAO() { - AuthService mockAuthService = mock(AuthService.class); + mockAuthService = mock(AuthService.class); mockCupboardService = mock(CupboardService.class); cupboardController = new CupboardController(mockCupboardService, mockAuthService); @@ -63,7 +64,8 @@ public class CupboardControllerTest { Map needMap = Map.ofEntries( entry("name", "Name"), entry("maxGoal", -100.0), - entry("type", "MONETARY")); + entry("type", "MONETARY") + ); var res = cupboardController.createNeed(needMap, key); @@ -77,13 +79,44 @@ public class CupboardControllerTest { Map needMap = Map.ofEntries( entry("name", "Name"), entry("maxGoal", 100.0), - entry("type", "MONETARY")); + entry("type", "MONETARY") + ); var res = cupboardController.createNeed(needMap, key); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); } + @Test + public void createNeedConflict() throws IOException, DuplicateKeyException { + when(mockCupboardService.createNeed("Name", 100, Need.GoalType.MONETARY)).thenThrow(new DuplicateKeyException("")); + + Map needMap = Map.ofEntries( + entry("name", "Name"), + entry("maxGoal", 100.0), + entry("type", "MONETARY") + ); + + 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 needMap = Map.ofEntries( + entry("name", "Name"), + entry("maxGoal", 100.0), + entry("type", "MONETARY") + ); + + 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); @@ -197,6 +230,36 @@ public class CupboardControllerTest { assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); } + @Test + public void updateNeedMissing() throws IOException { + var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + 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 { + var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + 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 { + var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + 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); @@ -218,6 +281,17 @@ public class CupboardControllerTest { assertEquals(HttpStatus.NOT_FOUND, res.getStatusCode()); } + @Test + public void deleteNeedUnauthorized() throws IOException, IllegalAccessException { + var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + 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); @@ -228,4 +302,61 @@ public class CupboardControllerTest { assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); } + + @Test + public void checkoutNeeds() throws IOException, IllegalAccessException { + doNothing().when(mockCupboardService).checkoutNeed(0, 20, key); + + + Map 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 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 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 needMap = Map.ofEntries( + entry("needID", 0), + entry("amount", 20) + ); + + var res = cupboardController.checkoutNeeds(needMap, key); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); + } } -- cgit v1.2.3 From c44eb965652a96498bff057d6d282af42196473e Mon Sep 17 00:00:00 2001 From: benal01 Date: Sun, 30 Mar 2025 16:22:02 -0400 Subject: 23 new needs that adhere to the updated structure --- ufund-api/data/cupboard.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ufund-api/data/cupboard.json b/ufund-api/data/cupboard.json index abc2293..3d49031 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":null,"current":0.0},{"name":"Diving Equipment","location":"Gulf of Mexico","id":6,"maxGoal":50.0,"type":"PHYSICAL","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Life Straw","location":"RIT","id":7,"maxGoal":1.0,"type":"PHYSICAL","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Dog Fish research","location":"RIT","id":8,"maxGoal":1000000.0,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Jellyfish Glue","location":"Pacific","id":9,"maxGoal":100000.0,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Fish Food","location":"","id":10,"maxGoal":1000.0,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Harpoons","location":"Atlantic City","id":11,"maxGoal":900.0,"type":"PHYSICAL","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Sea Urchin Hats","location":"Seaworld","id":12,"maxGoal":90.0,"type":"PHYSICAL","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Awareness Exhibit","location":"Seneca Park Zoo","id":13,"maxGoal":1.0E7,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"New Whale","location":"Seneca Park Zoo","id":14,"maxGoal":1.0,"type":"PHYSICAL","urgent":false,"filterAttributes":null,"current":0.0},{"name":"New Gosnell Algae Filter","location":"Gosnell College","id":15,"maxGoal":40.0,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Awareness Lunches","location":"Colleges and Highschools","id":16,"maxGoal":5000.0,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Fish Column for RIT Tours","location":"Wallace Library","id":17,"maxGoal":2.0E7,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Submarine Matinience","location":"New York Harbor","id":18,"maxGoal":1000000.0,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Volunteer Lunches ","location":"Lake Ontario","id":19,"maxGoal":150.0,"type":"PHYSICAL","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Volunteer Misc. Equipment","location":"Lake Ontario","id":20,"maxGoal":2500.0,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Invasive eel removal","location":"Pacific Seafloor","id":21,"maxGoal":1.0E8,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Fishing Liscense Enforcement","location":"Rochester Bridges","id":22,"maxGoal":10000.0,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Waste Runoff Management","location":"RIT Watershed","id":23,"maxGoal":98000.0,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Lobbying for anti-dynamite fishing legislation","location":"Washington DC","id":24,"maxGoal":50000.0,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Lobbying for better fishing practice legislation","location":"Washington DC","id":25,"maxGoal":65000.0,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0},{"name":"Bioluminescence Tunnel","location":"Golisano College of Computing","id":26,"maxGoal":2.8E7,"type":"MONETARY","urgent":true,"filterAttributes":null,"current":0.0},{"name":"Pollution awareness campain","location":"Middle and Highschools","id":27,"maxGoal":35000.0,"type":"MONETARY","urgent":false,"filterAttributes":null,"current":0.0}] \ No newline at end of file -- cgit v1.2.3 From 1abdb1408159796d12ed28c73862dd8d186384f0 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sun, 30 Mar 2025 16:41:24 -0400 Subject: Fixed broken tests and made them more consistent --- .../ufundapi/controller/CupboardController.java | 2 - .../java/com/ufund/api/ufundapi/model/Need.java | 18 +--- .../api/ufundapi/service/CupboardService.java | 2 +- .../controller/CupboardControllerTest.java | 95 +++++++++++++++++----- .../com/ufund/api/ufundapi/model/NeedTest.java | 51 +++++++----- .../com/ufund/api/ufundapi/model/UserTest.java | 7 +- .../ufundapi/persistence/CupboardFileDAOTest.java | 16 ++-- .../api/ufundapi/service/CupboardServiceTest.java | 85 +++++++++++-------- 8 files changed, 167 insertions(+), 109 deletions(-) diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java index c62bff3..d426aee 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 @@ -106,8 +106,6 @@ public class CupboardController { * * @param name The name parameter which contains the text used to find the {@link Need need} * - * @deprecated Searching should now be done client side in the future - * * @return ResponseEntity with array of {@link Need need} objects (may be empty) and * HTTP status of OK
              * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise 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 00cd38f..55a9441 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 @@ -46,7 +46,7 @@ public class Need { * @param type The type of need (monetary, physical) * @param urgent The urgency of the need */ - public Need(String name, String location, GoalType type, double maxGoal, boolean urgent) { + public Need(String name, String location, double maxGoal, GoalType type, boolean urgent) { this.name = name; this.location = location; this.type = type; @@ -74,10 +74,6 @@ public class Need { return name; } - public String getLocation() { - return location; - } - public int getId() { return id; } @@ -98,10 +94,6 @@ public class Need { return current; } - public boolean isUrgent() { - return urgent; - } - public void setCurrent(double current) { this.current = current; } @@ -122,15 +114,7 @@ public class Need { this.name = name; } - public void setLocation(String location) { - this.location = location; - } - public void setID(int id){ this.id = id; } - - public void setUrgent(boolean urgent) { - this.urgent = urgent; - } } \ No newline at end of file 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 15d1fad..4dcfcad 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 @@ -43,7 +43,7 @@ public class CupboardService { } } - Need need = new Need(name, location, goalType, maxGoal, urgent); + Need need = new Need(name, location, maxGoal, goalType, urgent); return cupboardDAO.addNeed(need); } 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 89697bf..31e085b 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 @@ -38,16 +38,20 @@ public class CupboardControllerTest { @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; + var need = new Need(name, location, maxGoal, type, urgent); + when(mockCupboardService.createNeed(name, "Atlantis", maxGoal, type, false)).thenReturn(need); Map needMap = Map.ofEntries( entry("name", "Test"), + entry("location", "Atlantis"), entry("maxGoal", 100.0), - entry("type", "MONETARY") + entry("type", "MONETARY"), + entry("urgent", false) ); var res = cupboardController.createNeed(needMap, key); @@ -58,12 +62,15 @@ 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 needMap = Map.ofEntries( - entry("name", "Name"), - entry("maxGoal", -100.0), - entry("type", "MONETARY")); + entry("name", "Test"), + entry("location", "Atlantis"), + entry("maxGoal", -100), + entry("type", "MONETARY"), + entry("urgent", false) + ); var res = cupboardController.createNeed(needMap, key); @@ -72,12 +79,15 @@ public class CupboardControllerTest { @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 needMap = Map.ofEntries( - entry("name", "Name"), - entry("maxGoal", 100.0), - entry("type", "MONETARY")); + entry("name", "Test"), + entry("location", "Atlantis"), + entry("maxGoal", 100), + entry("type", "MONETARY"), + entry("urgent", false) + ); var res = cupboardController.createNeed(needMap, key); @@ -86,7 +96,12 @@ public class CupboardControllerTest { @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; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.getNeeds()).thenReturn(new Need[]{need}); var res = cupboardController.getNeeds(); @@ -116,7 +131,12 @@ public class CupboardControllerTest { @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; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.searchNeeds("Na")).thenReturn(new Need[]{need}); var res = cupboardController.searchNeeds("Na"); @@ -146,7 +166,12 @@ public class CupboardControllerTest { @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; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.getNeed(need.getId())).thenReturn(need); var res = cupboardController.getNeed(need.getId()); @@ -157,7 +182,12 @@ 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; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.getNeed(need.getId())).thenThrow(new IOException()); var res = cupboardController.getNeed(need.getId()); @@ -167,7 +197,12 @@ 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; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.getNeed(need.getId())).thenReturn(null); var res = cupboardController.getNeed(need.getId()); @@ -178,7 +213,12 @@ 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; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.updateNeed(need, 1)).thenReturn(need); var res = cupboardController.updateNeed(need, 1, key); @@ -189,7 +229,12 @@ 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; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.updateNeed(need, 1)).thenThrow(new IOException()); var res = cupboardController.updateNeed(need, 1, key); @@ -199,7 +244,12 @@ public class CupboardControllerTest { @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; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.getNeed(1)).thenReturn(need); when(mockCupboardService.deleteNeed(1)).thenReturn(true); @@ -220,7 +270,12 @@ public class CupboardControllerTest { @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; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.getNeed(1)).thenReturn(need); when(mockCupboardService.deleteNeed(1)).thenThrow(new IOException()); 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..c7d17c7 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,26 @@ 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; + var need = new Need(name, location, maxGoal, type, urgent); 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; + var need = new Need(name, location, maxGoal, type, urgent); assertEquals(name, need.getName()); - assertEquals(id, need.getId()); + assertEquals(0, need.getId()); assertEquals(maxGoal, need.getMaxGoal()); assertEquals(type, need.getType()); } @@ -38,9 +41,11 @@ 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; + var need = new Need(name, location, maxGoal, type, urgent); double current = 0.00; need.setCurrent(current); @@ -60,9 +65,11 @@ 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; + var need = new Need(name, location, maxGoal, type, urgent); String[] filterAttributes = {"seaweed", "divers", "pacific", "plankton"}; @@ -75,9 +82,11 @@ 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; + var need = new Need(name, location, maxGoal, type, urgent); double newGoal = 200.00; need.setMaxGoal(newGoal); @@ -90,9 +99,11 @@ 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; + var need = new Need(name, location, maxGoal, type, urgent); 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 517a7e2..01b558c 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,7 +52,7 @@ 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); @@ -71,9 +71,8 @@ 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); 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 d83e825..acb759a 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 @@ -28,15 +28,13 @@ public class CupboardFileDAOTest { public void setupCupboardFileDao() throws IOException { ObjectMapper 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) + 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); + when(mockObjectMapper.readValue(new File("doesnt_matter.txt"), Need[].class)).thenReturn(testNeeds); cupboardFileDao = new CupboardFileDAO("doesnt_matter.txt", mockObjectMapper); } @@ -56,7 +54,7 @@ public class CupboardFileDAOTest { @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); @@ -92,7 +90,7 @@ public class CupboardFileDAOTest { 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); @@ -105,7 +103,7 @@ public class CupboardFileDAOTest { Need unupdatedNeed = needs[needs.length - 1]; assertNotNull(unupdatedNeed); - Need updatedNeed = new Need("sequin sea urchin hats", 20, 100, GoalType.PHYSICAL); + 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/service/CupboardServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java index 05ea2e8..f3cbc23 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 @@ -36,16 +36,18 @@ 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; + var need = new Need(name, location, maxGoal, type, urgent); // 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, maxGoal, type, urgent); // Analyze assertNotNull(response); @@ -56,9 +58,11 @@ public class CupboardServiceTest { 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; + var need = new Need(name, location, maxGoal, type, urgent); // When the same id is passed in, our mock User DAO will return the User object when(mockCupboardDAO.addNeed(any())).thenReturn(need); @@ -69,16 +73,18 @@ public class CupboardServiceTest { // Analyze assertThrows(IllegalArgumentException.class, () -> - cupboardService.createNeed(name, maxGoal, type)); + cupboardService.createNeed(name, location, maxGoal, type, urgent)); } @Test 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; + var need = new Need(name, location, maxGoal, type, urgent); Need[] needs = { need }; // When the same id is passed in, our mock User DAO will return the User object @@ -90,16 +96,18 @@ public class CupboardServiceTest { // Analyze assertThrows(DuplicateKeyException.class, () -> - cupboardService.createNeed(name, maxGoal, type)); + cupboardService.createNeed(name, location, maxGoal, type, urgent)); } @Test 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; + var need = new Need(name, location, maxGoal, type, urgent); Need[] needs = { need }; // When the same id is passed in, our mock User DAO will return the User object @@ -117,9 +125,11 @@ public class CupboardServiceTest { 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; + var need = new Need(name, location, maxGoal, type, urgent); Need[] needs = { need }; // When the same id is passed in, our mock User DAO will return the User object @@ -136,16 +146,17 @@ public class CupboardServiceTest { 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; + var need = new Need(name, location, maxGoal, type, urgent); // 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); @@ -155,17 +166,18 @@ public class CupboardServiceTest { 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; + Need need = new Need(name, location, maxGoal, type, urgent); + Need newNeed = new Need("Octopus", location, maxGoal, type, urgent); // 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); @@ -175,17 +187,18 @@ public class CupboardServiceTest { 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; + Need need = new Need(name, location, maxGoal, type, urgent); // 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 -- cgit v1.2.3 From 5eba2e924c57a7771c002fa3833beb5ed4275fd2 Mon Sep 17 00:00:00 2001 From: benal01 Date: Sun, 30 Mar 2025 16:44:38 -0400 Subject: location filter, filter order change, and refresh() resets search field for increased usability --- .../components/need-list/need-list.component.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index 66e53e8..af8cab4 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,4 +1,5 @@ import {Component , Output, EventEmitter} from '@angular/core'; +import { NgForm } from '@angular/forms'; import {Need} from '../../models/Need'; import {CupboardService} from '../../services/cupboard.service'; import { UsersService } from '../../services/users.service'; @@ -48,6 +49,13 @@ const sortByPriority: sortAlgo = (a: Need, b: Need): number => { 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, @@ -64,10 +72,11 @@ export class NeedListComponent { 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:sortByGoal,name:"sortByGoal", display:["Largest Maximum Goal", "Smallest Maximum Goal"]}, + {func:sortByLocation,name:"sortByLocation", display:["Location (A to Z)", "Location (Z to A)"]}, {func:sortByCompletion,name:"sortByCompletion", display:["Most Completed", "Least Completed"]}, - {func:sortByPriority,name:"sortByPriority", display:["Highest Priority", "Lowest Priority"]}, + {func:sortByGoal,name:"sortByGoal", display:["Largest Maximum Goal", "Smallest Maximum Goal"]}, ]; @Output() currentNeed = new EventEmitter(); @@ -87,6 +96,10 @@ export class NeedListComponent { } this.searchResults = this.needs; }); + + const form = document.getElementById('search-form') as HTMLFormElement; + form.reset(); + this.search(null); } ngOnInit(): void { @@ -148,6 +161,7 @@ export class NeedListComponent { this.cupboardService.deleteNeed(id).subscribe(() => { this.needs = this.needs.filter(n => n.id !== id) }) + this.refresh(); } isManager() { @@ -226,3 +240,7 @@ export class NeedListComponent { } } } +function not(location: string) { + throw new Error('Function not implemented.'); +} + -- cgit v1.2.3 From fd3fcd8f0e13e32774c020aee1b46e91d9b96c50 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sun, 30 Mar 2025 18:52:27 -0400 Subject: Fixed 2 broken tests in CupboardControllerTest --- .../ufundapi/controller/CupboardControllerTest.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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 4702771..75dbf84 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 @@ -97,12 +97,14 @@ public class CupboardControllerTest { @Test public void createNeedConflict() throws IOException, DuplicateKeyException { - when(mockCupboardService.createNeed("Name", "Atlantis", 100, Need.GoalType.MONETARY, false)).thenThrow(new DuplicateKeyException("")); + when(mockCupboardService.createNeed("Test", "Atlantis", 100, Need.GoalType.MONETARY, false)).thenThrow(new DuplicateKeyException("")); Map needMap = Map.ofEntries( - entry("name", "Name"), - entry("maxGoal", 100.0), - entry("type", "MONETARY") + entry("name", "Test"), + entry("location", "Atlantis"), + entry("maxGoal", 100), + entry("type", "MONETARY"), + entry("urgent", false) ); var res = cupboardController.createNeed(needMap, key); @@ -115,9 +117,11 @@ public class CupboardControllerTest { doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key); Map needMap = Map.ofEntries( - entry("name", "Name"), - entry("maxGoal", 100.0), - entry("type", "MONETARY") + entry("name", "Test"), + entry("location", "Atlantis"), + entry("maxGoal", 100), + entry("type", "MONETARY"), + entry("urgent", false) ); var res = cupboardController.createNeed(needMap, key); -- cgit v1.2.3 From 6bfbf7fa3b5b14b04f99f2dd6c33d336f6f081f6 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sun, 30 Mar 2025 20:31:32 -0400 Subject: Experimental sign up page design --- ufund-api/data/cupboard.json | 2 +- ufund-api/data/userAuths.json | 2 +- ufund-api/data/users.json | 2 +- .../src/app/components/signup/signup.component.css | 28 ++++++++++++- .../app/components/signup/signup.component.html | 47 ++++++++++++---------- .../src/app/components/signup/signup.component.ts | 10 ++--- 6 files changed, 61 insertions(+), 30 deletions(-) diff --git a/ufund-api/data/cupboard.json b/ufund-api/data/cupboard.json index abc2293..b0e71ca 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":"Jellyfish Hats","location":null,"id":26,"maxGoal":10.0,"type":"MONETARY","urgent":false,"filterAttributes":["#savethejellyfish","Clothing","Storefront"],"current":0.0},{"name":"Coral re-re-habilitation","location":null,"id":28,"maxGoal":10000.0,"type":"MONETARY","urgent":false,"filterAttributes":["Preservation","#savethecoral","#helloPhil"],"current":0.0}] \ 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-ui/src/app/components/signup/signup.component.css b/ufund-ui/src/app/components/signup/signup.component.css index f286cf9..429bc42 100644 --- a/ufund-ui/src/app/components/signup/signup.component.css +++ b/ufund-ui/src/app/components/signup/signup.component.css @@ -1,7 +1,16 @@ :host { + display: flex; + align-items: center; + justify-content: center; + height: 100%; + margin-top: -66px + +} + +#box { display: flex; flex-direction: column; - max-width: 300px; + /*max-width: 300px;*/ gap: 10px; & > div { @@ -45,3 +54,20 @@ 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 index ebedc2a..bc3aaf0 100644 --- a/ufund-ui/src/app/components/signup/signup.component.html +++ b/ufund-ui/src/app/components/signup/signup.component.html @@ -1,26 +1,31 @@ -

              Signup:

              -
              - - {{usernameStatusText | async}} -
              +
              +

              Create an account

              +
              + + {{usernameStatusText | async}} +
              -
              - - - {{passwordStatusText | async}} +
              +
              + + + {{passwordStatusText | async}} +
              - - {{requirement.title}} - -
              +
              + {{requirement.value?"check":"close"}} {{requirement.title}} +
              +
              -
              - - {{confirmPassStatusText | async}} -
              +
              + + {{(passwordsMatch|async)?"check":"close"}} Passwords match +
              -
              - - Account created Proceed to login - {{statusText | async}} +
              + + Account created Proceed to login + {{statusText | async}} +
              + Already have an account? Log in
              diff --git a/ufund-ui/src/app/components/signup/signup.component.ts b/ufund-ui/src/app/components/signup/signup.component.ts index 3b43287..1ab863d 100644 --- a/ufund-ui/src/app/components/signup/signup.component.ts +++ b/ufund-ui/src/app/components/signup/signup.component.ts @@ -22,7 +22,7 @@ class PasswordRequirements { export class SignupComponent { protected passwordStatusText = new BehaviorSubject("") - protected confirmPassStatusText = new BehaviorSubject("") + protected passwordsMatch = new BehaviorSubject(false) protected usernameStatusText = new BehaviorSubject("") protected showSuccessMessage = new BehaviorSubject(false) protected passwordStrongEnough = new BehaviorSubject(false) @@ -51,7 +51,7 @@ export class SignupComponent { } validate(username: string, passConfirm:string, password: string) { - this.confirmPassStatusText.next("") + this.passwordsMatch.next(false) this.usernameStatusText.next("") this.checkPasswordStrength(password); @@ -59,8 +59,8 @@ export class SignupComponent { this.usernameStatusText.next("Username field can't be blank") } - if (!(password === passConfirm) && !!passConfirm) { - this.confirmPassStatusText.next("Passwords don't match") + if (passConfirm && password === passConfirm) { + this.passwordsMatch.next(true) } this.ableToCreateAccount.next(this.passwordStrongEnough.getValue() && password === passConfirm && !!username) } @@ -106,7 +106,7 @@ export class SignupComponent { } else if (strength == 0) { this.passwordStatusText.next("") } else { - this.passwordStatusText.next("Password does not meet requirements") + this.passwordStatusText.next("5/6 checks required") } this.strength.next(strength) -- cgit v1.2.3 From 197be103d02db808b0e6bf8a1d1369e3d7928c03 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sun, 30 Mar 2025 20:48:22 -0400 Subject: Modified controllers to return error text when catching errors. Also added additional error checking to CupboardService for physical needs. --- .../api/ufundapi/controller/AuthController.java | 6 +-- .../ufundapi/controller/CupboardController.java | 54 +++++++++++----------- .../api/ufundapi/controller/UserController.java | 26 +++++------ .../controller/CupboardControllerTest.java | 8 ++-- .../ufundapi/controller/UserControllerTest.java | 34 +++++++------- 5 files changed, 64 insertions(+), 64 deletions(-) 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 aa99a90..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 @@ -43,10 +43,10 @@ public class AuthController { return new ResponseEntity<>(key, HttpStatus.OK); } catch (IllegalAccessException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -64,7 +64,7 @@ public class AuthController { return new ResponseEntity<>(HttpStatus.OK); } catch (IOException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + 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 d426aee..cce016c 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 @@ -51,7 +51,7 @@ public class CupboardController { * INTERNAL_SERVER_ERROR otherwise */ @PostMapping("") - public ResponseEntity createNeed(@RequestBody Map params, @RequestHeader("jelly-api-key") String key) { + public ResponseEntity createNeed(@RequestBody Map params, @RequestHeader("jelly-api-key") String key) { LOG.log(Level.INFO, "POST /cupboard body={0}", params); String name = (String) params.get("name"); @@ -66,16 +66,16 @@ public class CupboardController { return new ResponseEntity<>(need, HttpStatus.OK); } catch (DuplicateKeyException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.CONFLICT); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.CONFLICT); } catch (IllegalArgumentException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST); } catch (IllegalAccessException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -88,15 +88,15 @@ public class CupboardController { * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise */ @GetMapping("") - public ResponseEntity getNeeds() { + public ResponseEntity 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); } } @@ -112,15 +112,15 @@ public class CupboardController { *

              */ @GetMapping("/") - public ResponseEntity searchNeeds(@RequestParam String name) { + public ResponseEntity 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); } } @@ -133,7 +133,7 @@ public class CupboardController { * ResponseEntity with HTTP status of NOT_FOUND if not found
              */ @GetMapping("/{id}") - public ResponseEntity getNeed(@PathVariable int id) { + public ResponseEntity getNeed(@PathVariable int id) { LOG.log(Level.INFO, "GET /cupboard/{0}", id); try { @@ -143,9 +143,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); } } @@ -157,7 +157,7 @@ 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 updateNeed(@RequestBody Need need, @PathVariable int id, @RequestHeader("jelly-api-key") String key) { + public ResponseEntity 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); @@ -169,13 +169,13 @@ public class CupboardController { } } catch (IllegalArgumentException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST); } catch (IllegalAccessException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -196,13 +196,13 @@ public class CupboardController { return new ResponseEntity<>(HttpStatus.OK); } catch (IllegalArgumentException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST); } catch (IllegalAccessException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -213,7 +213,7 @@ 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 deleteNeed(@PathVariable int id, @RequestHeader("jelly-api-key") String key) { + public ResponseEntity deleteNeed(@PathVariable int id, @RequestHeader("jelly-api-key") String key) { LOG.log(Level.INFO, "DELETE /cupboard/{0}", id); try { authService.keyHasAccessToCupboard(key); @@ -225,10 +225,10 @@ public class CupboardController { } } catch (IllegalAccessException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } } 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 33d2e4f..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 @@ -41,7 +41,7 @@ public class UserController { * otherwise */ @PostMapping("") - public ResponseEntity createUser(@RequestBody Map params) { + public ResponseEntity createUser(@RequestBody Map params) { LOG.log(Level.INFO, "POST /users body={0}", params); String username = params.get("username"); String password = params.get("password"); @@ -55,10 +55,10 @@ public class UserController { } } catch (DuplicateKeyException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.CONFLICT); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.CONFLICT); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -73,7 +73,7 @@ public class UserController { * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise */ @GetMapping("/{username}") - public ResponseEntity getUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) { + public ResponseEntity getUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) { LOG.log(Level.INFO, "GET /user/{0} key={1}", of(username, key)); try { @@ -86,10 +86,10 @@ public class UserController { } } catch (IllegalAccessException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -104,7 +104,7 @@ public class UserController { * INTERNAL_SERVER_ERROR if there was an issue */ @PutMapping("/{username}") - public ResponseEntity updateUser(@RequestBody User user, @PathVariable String username, @RequestHeader("jelly-api-key") String key) { + public ResponseEntity 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.keyHasAccessToUser(username, key); @@ -116,13 +116,13 @@ public class UserController { } } catch (IllegalArgumentException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST); } catch (IllegalAccessException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -135,7 +135,7 @@ public class UserController { * INTERNAL_SERVER_ERROR if an error occurred */ @DeleteMapping("/{username}") - public ResponseEntity deleteUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) { + public ResponseEntity deleteUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) { LOG.log(Level.INFO, "DELETE /users/{0} id={1}", of(username, key)); try { @@ -147,10 +147,10 @@ public class UserController { } } catch (IllegalAccessException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getLocalizedMessage()); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } } 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 75dbf84..c159db4 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 @@ -142,7 +142,7 @@ public class CupboardControllerTest { var res = cupboardController.getNeeds(); assertEquals(HttpStatus.OK, res.getStatusCode()); - assertArrayEquals(new Need[]{need}, res.getBody()); + assertArrayEquals(new Need[]{need}, (Need[]) res.getBody()); } @Test @@ -161,7 +161,7 @@ public class CupboardControllerTest { var res = cupboardController.getNeeds(); assertEquals(HttpStatus.OK, res.getStatusCode()); - assertArrayEquals(new Need[]{}, res.getBody()); + assertArrayEquals(new Need[]{}, (Need[]) res.getBody()); } @Test @@ -177,7 +177,7 @@ public class CupboardControllerTest { var res = cupboardController.searchNeeds("Na"); assertEquals(HttpStatus.OK, res.getStatusCode()); - assertArrayEquals(new Need[]{need}, res.getBody()); + assertArrayEquals(new Need[]{need}, (Need[]) res.getBody()); } @Test @@ -196,7 +196,7 @@ 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 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 06fb6cd..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 response = userController.getUser(username, key); + ResponseEntity 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 response = userController.getUser(username, key); + ResponseEntity response = userController.getUser(username, key); // Analyze assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); @@ -85,7 +85,7 @@ public class UserControllerTest { doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key); // Invoke - ResponseEntity response = userController.getUser(username, key); + ResponseEntity 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 response = userController.getUser(username, key); + ResponseEntity response = userController.getUser(username, key); // Analyze assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -119,7 +119,7 @@ public class UserControllerTest { // Invoke - ResponseEntity response = userController.createUser(userMap); + ResponseEntity response = userController.createUser(userMap); // Analyze assertEquals(HttpStatus.CREATED, response.getStatusCode()); @@ -138,7 +138,7 @@ public class UserControllerTest { // Invoke - ResponseEntity response = userController.createUser(userMap); + ResponseEntity 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 response = userController.createUser(userMap); + ResponseEntity response = userController.createUser(userMap); // Analyze assertEquals(HttpStatus.CONFLICT, response.getStatusCode()); @@ -172,7 +172,7 @@ public class UserControllerTest { // Invoke - ResponseEntity response = userController.createUser(userMap); + ResponseEntity 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 response = userController.updateUser(user, username, key); + ResponseEntity 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 response = userController.updateUser(user, username, key); + ResponseEntity 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 response = userController.updateUser(user, username, key); + ResponseEntity response = userController.updateUser(user, username, key); // Analyze assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -241,7 +241,7 @@ public class UserControllerTest { // Invoke - ResponseEntity response = userController.updateUser(user, username, key); + ResponseEntity response = userController.updateUser(user, username, key); // Analyze assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); @@ -256,7 +256,7 @@ public class UserControllerTest { when(mockUserService.deleteUser(username)).thenReturn(true); // Invoke - ResponseEntity response = userController.deleteUser(username, key); + ResponseEntity 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 response = userController.deleteUser(username, key); + ResponseEntity 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 response = userController.deleteUser(username, key); + ResponseEntity response = userController.deleteUser(username, key); // Analyze assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -301,7 +301,7 @@ public class UserControllerTest { doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key); // Invoke - ResponseEntity response = userController.deleteUser(username, key); + ResponseEntity response = userController.deleteUser(username, key); // Analyze assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); -- cgit v1.2.3 From eb09f05ca697a3a6d3587f9278e332056bfd6f66 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sun, 30 Mar 2025 20:48:32 -0400 Subject: Modified controllers to return error text when catching errors. Also added additional error checking to CupboardService for physical needs. --- .../src/main/java/com/ufund/api/ufundapi/service/CupboardService.java | 4 ++++ 1 file changed, 4 insertions(+) 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 4dcfcad..a86fe28 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 @@ -35,6 +35,8 @@ public class CupboardService { 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()) { @@ -95,6 +97,8 @@ 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); } -- cgit v1.2.3 From aa5610d0f56c2a048212b3bd3a9ca5671ec855fa Mon Sep 17 00:00:00 2001 From: sowgro Date: Sun, 30 Mar 2025 21:46:54 -0400 Subject: Continue working on css --- .../components/dashboard/dashboard.component.css | 2 +- .../components/need-list/need-list.component.css | 7 +++- .../components/need-list/need-list.component.html | 5 +-- .../components/need-page/need-page.component.css | 10 +++++ .../components/need-page/need-page.component.html | 47 ++++++++++++---------- ufund-ui/src/styles.css | 4 ++ 6 files changed, 47 insertions(+), 28 deletions(-) diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.css b/ufund-ui/src/app/components/dashboard/dashboard.component.css index 9db015e..78a69ba 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.css +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.css @@ -1,7 +1,7 @@ :host { display: flex; flex-direction: column; - width: 1200px; + width: 1000px; align-self: center; gap: 20px } 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 5e07856..05354fc 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 @@ -75,14 +75,17 @@ li > button:hover p { #search-container { background-color: #d9d9d9; +} + #search-form { background-color: light-dark(#d9d9d9, #1b1b1b); padding: 10px 20px 20px 20px; border: 2px solid #000; border-radius: 5px; + border-radius: 5px; + visibility: visible; + .wide-input { width: 60%; } - border-radius: 5px; - visibility: visible; } 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 866e5e4..72bc9c5 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,4 +1,3 @@ -

              Needs List

              @@ -43,9 +42,9 @@ -
              - \ No newline at end of file + 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..a3a4014 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,10 @@ +:host { + display: flex; + justify-content: center; +} + +#box { + display: flex; + flex-direction: column; + width: 1000px; +} 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 7ce7633..a72167c 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,23 +1,26 @@ - -

              Viewing Need: {{need?.name}}

              -internal id: {{need?.id}} -
              -

              Looking for

              -

              {{need?.type}}

              -

              Donations.

              -
              -
              -

              Tags:

              -
                -
              • -

                {{tag}}

                -
              • -
              -
              +
              +

              {{need?.name}}

              +
              +

              Looking for {{need?.type}} Donations.

              +
              +
              +

              Tags:

              +
                +
              • +

                {{tag}}

                +
              • +
              +
              -
              -

              Location: {{need?.location}}

              -

              Goal: {{need?.maxGoal}}

              -

              Current: {{need?.current}}

              -

              Urgent: {{need?.urgent}}

              -

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

              +
              +

              Location: {{need?.location}}

              +

              Urgent: {{need?.urgent}}

              + {{need?.current}} / {{need?.maxGoal}} + + This goal is {{(((need?.current ?? 0)*100) / (need?.maxGoal ?? 0)).toFixed(0)}}% complete! +
              + + + +
              +
              diff --git a/ufund-ui/src/styles.css b/ufund-ui/src/styles.css index e4b4e8c..b3ecbd0 100644 --- a/ufund-ui/src/styles.css +++ b/ufund-ui/src/styles.css @@ -57,3 +57,7 @@ button, .button { .icon { font-family: 'Material Symbols Outlined' } + +h1 { + font-size: 40px; +} -- cgit v1.2.3 From cfe40fa1e416fbf4586ef36b63a145453a4d6224 Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 31 Mar 2025 00:38:37 -0400 Subject: Continue working on css (1) --- ufund-ui/public/delete.png | Bin 6396 -> 0 bytes ufund-ui/public/edit.png | Bin 6649 -> 0 bytes ufund-ui/public/search.png | Bin 12743 -> 0 bytes ufund-ui/src/app/app.component.css | 28 +++++ ufund-ui/src/app/app.component.html | 8 ++ ufund-ui/src/app/app.component.ts | 13 ++- .../app/components/cupboard/cupboard.component.css | 13 +-- .../components/cupboard/cupboard.component.html | 6 +- .../mini-need-list/mini-need-list.component.css | 1 + .../components/need-list/need-list.component.css | 126 ++++++++++----------- .../components/need-list/need-list.component.html | 73 ++++++------ .../components/need-list/need-list.component.ts | 4 +- ufund-ui/src/app/services/toasts.service.ts | 19 ++++ 13 files changed, 179 insertions(+), 112 deletions(-) delete mode 100644 ufund-ui/public/delete.png delete mode 100644 ufund-ui/public/edit.png delete mode 100644 ufund-ui/public/search.png create mode 100644 ufund-ui/src/app/services/toasts.service.ts diff --git a/ufund-ui/public/delete.png b/ufund-ui/public/delete.png deleted file mode 100644 index 6403705..0000000 Binary files a/ufund-ui/public/delete.png and /dev/null differ diff --git a/ufund-ui/public/edit.png b/ufund-ui/public/edit.png deleted file mode 100644 index 3b6e2d8..0000000 Binary files a/ufund-ui/public/edit.png and /dev/null differ diff --git a/ufund-ui/public/search.png b/ufund-ui/public/search.png deleted file mode 100644 index 1940ef5..0000000 Binary files a/ufund-ui/public/search.png and /dev/null differ diff --git a/ufund-ui/src/app/app.component.css b/ufund-ui/src/app/app.component.css index 5596cf8..5af3958 100644 --- a/ufund-ui/src/app/app.component.css +++ b/ufund-ui/src/app/app.component.css @@ -43,3 +43,31 @@ text-decoration: underline; } } + +.toast { + transform: translateY(-90px); + 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; + } +} + +.toast.active { + transform: translateY(0); +} diff --git a/ufund-ui/src/app/app.component.html b/ufund-ui/src/app/app.component.html index b0ee329..b41a225 100644 --- a/ufund-ui/src/app/app.component.html +++ b/ufund-ui/src/app/app.component.html @@ -1,3 +1,11 @@ +
              + + + + + +
              + +
              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 af8cab4..47114c3 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 @@ -66,7 +66,7 @@ export class NeedListComponent { selectedNeed: Need | null = null; needs: Need[] = []; searchResults: Need[] = []; - sortMode = 'Ascending' + sortMode: 'Ascending' | 'Descending' = 'Ascending' currentSortAlgo: sortAlgo = sortByPriority; sortSelection: string = 'sortByPriority'; @@ -98,7 +98,7 @@ export class NeedListComponent { }); const form = document.getElementById('search-form') as HTMLFormElement; - form.reset(); + form.reset(); this.search(null); } 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..0c35e45 --- /dev/null +++ b/ufund-ui/src/app/services/toasts.service.ts @@ -0,0 +1,19 @@ +import {Injectable} from '@angular/core'; + +export enum ToastType { + INFO, + WARNING, + ERROR +} + +@Injectable({ + providedIn: 'root' +}) +export class ToastsService { + + constructor() {} + + sendToast(type: ToastType, message: string, action?: {label: string, onAction: () => void}) { + + } +} -- cgit v1.2.3 From 227360990424abe323c44664b1d58d667b89a92f Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 31 Mar 2025 10:10:41 -0400 Subject: backend support for description --- .../com/ufund/api/ufundapi/controller/CupboardController.java | 5 +++-- .../src/main/java/com/ufund/api/ufundapi/model/Need.java | 11 +++++++++-- .../java/com/ufund/api/ufundapi/service/CupboardService.java | 7 +++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java index d426aee..ea86aa8 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 @@ -5,7 +5,6 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import com.ufund.api.ufundapi.service.AuthService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; @@ -22,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 @@ -58,11 +58,12 @@ public class CupboardController { 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 { authService.keyHasAccessToCupboard(key); - Need need = cupboardService.createNeed(name, location, maxGoal, goalType, urgent); + Need need = cupboardService.createNeed(name, location, maxGoal, goalType, urgent, description); return new ResponseEntity<>(need, HttpStatus.OK); } catch (DuplicateKeyException ex) { LOG.log(Level.WARNING, ex.getLocalizedMessage()); 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 55a9441..35e81b3 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 @@ -17,6 +17,7 @@ public class Need { @JsonProperty("maxGoal") private double maxGoal; @JsonProperty("urgent") private boolean urgent; @JsonProperty("current") private double current; + @JsonProperty("description") private String description; /** * Create a new need, used by the controller @@ -27,14 +28,16 @@ public class 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("location") String location, @JsonProperty("id") int id, @JsonProperty("maxGoal") double maxGoal, @JsonProperty("type") GoalType type, @JsonProperty("urgent") boolean urgent) { + public Need(@JsonProperty("name") String name, @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.location = location; this.name = name; this.maxGoal = maxGoal; this.type = type; this.urgent = urgent; + this.description = description; } /** @@ -45,13 +48,15 @@ public class 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, String location, double maxGoal, GoalType type, boolean urgent) { + public Need(String name, String location, double maxGoal, GoalType type, boolean urgent, String description) { this.name = name; this.location = location; this.type = type; this.maxGoal = maxGoal; this.urgent = urgent; + this.description = description; } /** @@ -68,6 +73,7 @@ public class Need { this.maxGoal = other.maxGoal; this.current = other.current; this.urgent = other.urgent; + this.description = other.description; } public String getName() { @@ -94,6 +100,7 @@ public class Need { return current; } + public void setCurrent(double current) { this.current = current; } 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 4dcfcad..d216b01 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 @@ -25,13 +25,16 @@ public class CupboardService { * Creates a new Need * * @param name The name 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, String location, double maxGoal, Need.GoalType goalType, boolean urgent) throws IOException, DuplicateKeyException { + public Need createNeed(String name, 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"); @@ -43,7 +46,7 @@ public class CupboardService { } } - Need need = new Need(name, location, maxGoal, goalType, urgent); + Need need = new Need(name, location, maxGoal, goalType, urgent, description); return cupboardDAO.addNeed(need); } -- cgit v1.2.3 From bcdf234066ee277b7436428989d5e0dbf58c2f60 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 31 Mar 2025 10:15:40 -0400 Subject: description textarea for forms --- ufund-ui/src/app/components/cupboard/cupboard.component.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 25b88ba..89d8fbe 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -24,6 +24,8 @@

              + +
              @@ -46,7 +48,8 @@
              - + +
              {{statusText | async}} -- cgit v1.2.3 From d4dd348e81d3aef4cc62335f1dad5a02452dfadd Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 31 Mar 2025 10:16:03 -0400 Subject: frontend model support for description --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 6 ++++-- ufund-ui/src/app/models/Need.ts | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 85ffd17..feb39e0 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -91,7 +91,8 @@ export class CupboardComponent implements OnInit { type: GoalType[form.type as keyof typeof GoalType], urgent: form.urgent, filterAttributes: [], - current: 0 + current: 0, + description: form.description }; this.cupboardService.updateNeed(need.id, need) @@ -127,7 +128,8 @@ export class CupboardComponent implements OnInit { 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); diff --git a/ufund-ui/src/app/models/Need.ts b/ufund-ui/src/app/models/Need.ts index 1451cad..2a2800c 100644 --- a/ufund-ui/src/app/models/Need.ts +++ b/ufund-ui/src/app/models/Need.ts @@ -7,6 +7,7 @@ export interface Need { maxGoal: number; current: number; urgent: boolean; + description: string; } export enum GoalType { -- cgit v1.2.3 From 5f083f775917c15597b3b70a0eb6a0ce2fda7667 Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 31 Mar 2025 11:28:42 -0400 Subject: More css tweaks --- ufund-ui/src/app/app.component.html | 4 ++-- ufund-ui/src/app/app.component.ts | 19 ++++++++++++------- .../src/app/components/login/login.component.html | 1 - ufund-ui/src/styles.css | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ufund-ui/src/app/app.component.html b/ufund-ui/src/app/app.component.html index b41a225..89075e1 100644 --- a/ufund-ui/src/app/app.component.html +++ b/ufund-ui/src/app/app.component.html @@ -17,8 +17,8 @@
              Cupboard Basket - - + + diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index 7d9afcd..8068659 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -3,6 +3,8 @@ import {BehaviorSubject, Observable} from 'rxjs'; import { DOCUMENT } from '@angular/common'; import {AuthService} from './services/auth.service'; import {ToastType} from './services/toasts.service'; +import {User} from './models/User'; +import {ActivatedRoute, Router} from '@angular/router'; interface ToastProps { type: ToastType, message: string, action?: {label: string, onAction: () => void} @@ -16,12 +18,14 @@ interface ToastProps { }) export class AppComponent implements OnInit { // title = 'ufund-ui'; - currentUser$: BehaviorSubject = new BehaviorSubject("Logged out."); + currentUser?: BehaviorSubject; toast = new BehaviorSubject({type: ToastType.INFO, message: "testToast"}) constructor( private authService: AuthService, + private router: Router, + private route: ActivatedRoute, @Inject(DOCUMENT) private document: Document ) {} @@ -30,14 +34,15 @@ export class AppComponent implements OnInit { } ngOnInit() { - this.authService.getCurrentUserSubject().subscribe(r => { - this.currentUser$?.next(r - ? "Logged in as " + r.username - : "Logged out." - ) - }) + this.currentUser = this.authService.getCurrentUserSubject() } + login() { + this.router.navigate(['/login'], {queryParams: {redir: this.router.url}}); + } + logout() { + location.reload() + } } diff --git a/ufund-ui/src/app/components/login/login.component.html b/ufund-ui/src/app/components/login/login.component.html index 743b1b3..e1c3e2a 100644 --- a/ufund-ui/src/app/components/login/login.component.html +++ b/ufund-ui/src/app/components/login/login.component.html @@ -1,5 +1,4 @@
              - You must be logged in to view this page

              Login

              diff --git a/ufund-ui/src/styles.css b/ufund-ui/src/styles.css index b3ecbd0..b152e61 100644 --- a/ufund-ui/src/styles.css +++ b/ufund-ui/src/styles.css @@ -32,7 +32,7 @@ input { } } -button, .button { +button, input[type=button], input[type=reset], input[type=submit], .button { font-size: 14pt; padding: 6px 16px; border-radius: 9999px; -- cgit v1.2.3 From cb5be32bf0d050cc1fd37d7cc9b4c51e1c51fffe Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 12:08:22 -0400 Subject: Added dynamic error messaging to the cupboard --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 85ffd17..88ab46c 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,4 +1,4 @@ -import {Component, Input, OnInit, ViewChild} from '@angular/core'; +import {Component, OnInit, ViewChild} from '@angular/core'; import { CupboardService } from '../../services/cupboard.service'; import { Need, GoalType } from '../../models/Need'; import { userType } from '../../models/User'; @@ -99,7 +99,7 @@ export class CupboardComponent implements OnInit { 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"); + this.statusText.next(ex.error); } else { this.statusText.next("Error on creating need"); } @@ -136,7 +136,7 @@ export class CupboardComponent implements OnInit { 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"); + this.statusText.next(ex.error); } else { this.statusText.next("Error on creating need"); } -- cgit v1.2.3 From 655f83af9ba59d6153c9916b9a31bfe12680655e Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 13:12:42 -0400 Subject: Implemented localStorage cookies to maintain user persistence --- ufund-ui/src/app/app.component.ts | 14 ++++++++++++-- ufund-ui/src/app/components/login/login.component.ts | 2 ++ ufund-ui/src/app/services/auth.service.ts | 14 ++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index 8068659..34256f3 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -1,5 +1,5 @@ -import {Component, OnInit, Inject, ViewChild} from '@angular/core'; -import {BehaviorSubject, Observable} from 'rxjs'; +import {Component, OnInit, Inject} from '@angular/core'; +import {BehaviorSubject} from 'rxjs'; import { DOCUMENT } from '@angular/common'; import {AuthService} from './services/auth.service'; import {ToastType} from './services/toasts.service'; @@ -34,7 +34,17 @@ export class AppComponent implements OnInit { } ngOnInit() { + console.log("AAAAAAAAAAAAAAAA") 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) + } else { + console.log("key missing") + console.log(data) + } } login() { diff --git a/ufund-ui/src/app/components/login/login.component.ts b/ufund-ui/src/app/components/login/login.component.ts index f6a2996..4dcaedd 100644 --- a/ufund-ui/src/app/components/login/login.component.ts +++ b/ufund-ui/src/app/components/login/login.component.ts @@ -35,6 +35,8 @@ export class LoginComponent implements OnInit { 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]) console.log(ex) diff --git a/ufund-ui/src/app/services/auth.service.ts b/ufund-ui/src/app/services/auth.service.ts index 6bc7145..b75c931 100644 --- a/ufund-ui/src/app/services/auth.service.ts +++ b/ufund-ui/src/app/services/auth.service.ts @@ -1,7 +1,8 @@ -import {Injectable} from '@angular/core'; +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' @@ -24,7 +25,9 @@ export class AuthService { }); constructor( - private http: HttpClient + private http: HttpClient, + // private userService: UsersService + private injector: Injector ) {} async login(username: string, password: string) { @@ -42,6 +45,13 @@ export class AuthService { // 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; } -- cgit v1.2.3 From 07a9e3c6faf735b374c6b63235defeb8a38a6661 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 13:27:02 -0400 Subject: Implemented logout functionality with localStorage --- ufund-ui/src/app/app.component.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index 34256f3..94a6439 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -52,6 +52,7 @@ export class AppComponent implements OnInit { } logout() { + localStorage.removeItem("credential") location.reload() } -- cgit v1.2.3 From ec88317c75ec907c319412502a1b189c97db9173 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 14:36:39 -0400 Subject: Modified need list to display percent as a whole number --- ufund-ui/src/app/components/need-list/need-list.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3a4ca9c..e24ee09 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 @@ -41,7 +41,7 @@
              - {{need.current}}/{{need.maxGoal}} ({{(need.current / need.maxGoal) * 100}}%) + {{need.current}}/{{need.maxGoal}} ({{((need.current / need.maxGoal) * 100).toFixed(0)}}%)
              -- cgit v1.2.3 From 2031579ce6033fbe67a78b66d3da2ee6872748de Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 15:08:59 -0400 Subject: Removed old logging --- ufund-ui/src/app/app.component.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ufund-ui/src/app/app.component.ts b/ufund-ui/src/app/app.component.ts index 94a6439..df9114e 100644 --- a/ufund-ui/src/app/app.component.ts +++ b/ufund-ui/src/app/app.component.ts @@ -34,16 +34,12 @@ export class AppComponent implements OnInit { } ngOnInit() { - console.log("AAAAAAAAAAAAAAAA") 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) - } else { - console.log("key missing") - console.log(data) } } -- cgit v1.2.3 From 9f31fea81818dae21f67b23a6004a3ca369f8e0d Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 15:09:23 -0400 Subject: Added check to prevent redirect to login page --- ufund-ui/src/app/components/dashboard/dashboard.component.ts | 4 ++-- .../src/app/components/funding-basket/funding-basket.component.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.ts b/ufund-ui/src/app/components/dashboard/dashboard.component.ts index 165c7ba..49d93bf 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.ts +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.ts @@ -27,7 +27,7 @@ export class DashboardComponent implements OnInit{ ngOnInit() { let user = this.authService.getCurrentUser() - if(!user) { + if(!localStorage.getItem("credential") && !user) { this.router.navigate(['/login']) return } @@ -35,7 +35,7 @@ export class DashboardComponent implements OnInit{ 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.inBasket = r.filter(n => n.id in user?.basket) + this.inBasket = r.filter(n => n.id in user!.basket) }) } 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 faa7e0b..5c5776f 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 @@ -26,7 +26,7 @@ export class FundingBasketComponent implements OnInit { // this is for login rerouting ngOnInit(): void { - if (!this.authService.getCurrentUser()) { + if (!localStorage.getItem("credential") && !this.authService.getCurrentUser()) { this.router.navigate(['/login'], {queryParams: {redir: this.router.url}}); return; } -- cgit v1.2.3 From d07e7630c836711b92cffd41fe99d15c84cb025f Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 15:09:41 -0400 Subject: Added animation to header tabs when hovering over them --- ufund-ui/src/app/app.component.css | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/ufund-ui/src/app/app.component.css b/ufund-ui/src/app/app.component.css index 5af3958..5204919 100644 --- a/ufund-ui/src/app/app.component.css +++ b/ufund-ui/src/app/app.component.css @@ -38,10 +38,31 @@ text-decoration: none; } - a:hover { - /*color: light-dark(black, white)*/ - 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); + } + + } .toast { -- cgit v1.2.3 From b07405c2a1817271c84e25bfe62b6b3ff36136f9 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 15:10:52 -0400 Subject: Unused imports --- ufund-ui/src/app/components/dashboard/dashboard.component.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.ts b/ufund-ui/src/app/components/dashboard/dashboard.component.ts index 49d93bf..645893f 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.ts +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.ts @@ -1,10 +1,8 @@ import {Component, OnInit} from '@angular/core'; -import {userType} from '../../models/User'; import {AuthService} from '../../services/auth.service'; import {Router} from '@angular/router'; import {Need} from '../../models/Need'; import {CupboardService} from '../../services/cupboard.service'; -import {UsersService} from '../../services/users.service'; import {firstValueFrom} from 'rxjs'; @Component({ -- cgit v1.2.3 From da47933078796ea1b7b7b20468d2c2fe19b2e74f Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 17:27:57 -0400 Subject: Added bat file --- start.bat | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 start.bat 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 -- cgit v1.2.3 From f7a0ce90b0ead17ad4002108d7e868899954c69d Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 17:28:20 -0400 Subject: Removed login check for now --- .../app/components/funding-basket/funding-basket.component.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 5c5776f..08515c2 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 @@ -26,7 +26,7 @@ export class FundingBasketComponent implements OnInit { // this is for login rerouting ngOnInit(): void { - if (!localStorage.getItem("credential") && !this.authService.getCurrentUser()) { + if (!this.authService.getCurrentUser()) { this.router.navigate(['/login'], {queryParams: {redir: this.router.url}}); return; } @@ -45,6 +45,15 @@ export class FundingBasketComponent implements OnInit { contribution.setAttribute("style", "color: #ff0000"); } } + // 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.getElementById("funding-basket")?.querySelectorAll('.contribution')!) { let contribution = c as HTMLInputElement; -- cgit v1.2.3 From 97c9e1e0bb73c7b08c830c47548ac1c4b5bebd0b Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 31 Mar 2025 17:33:04 -0400 Subject: TOASTS --- ufund-ui/src/app/app.component.css | 28 ----------- ufund-ui/src/app/app.component.html | 8 --- ufund-ui/src/app/app.component.ts | 14 ++---- ufund-ui/src/app/app.module.ts | 2 + .../src/app/components/toast/toast.component.css | 57 ++++++++++++++++++++++ .../src/app/components/toast/toast.component.html | 7 +++ .../src/app/components/toast/toast.component.ts | 37 ++++++++++++++ ufund-ui/src/app/services/toasts.service.ts | 12 ++++- 8 files changed, 118 insertions(+), 47 deletions(-) create mode 100644 ufund-ui/src/app/components/toast/toast.component.css create mode 100644 ufund-ui/src/app/components/toast/toast.component.html create mode 100644 ufund-ui/src/app/components/toast/toast.component.ts diff --git a/ufund-ui/src/app/app.component.css b/ufund-ui/src/app/app.component.css index 5204919..0bcd658 100644 --- a/ufund-ui/src/app/app.component.css +++ b/ufund-ui/src/app/app.component.css @@ -64,31 +64,3 @@ } - -.toast { - transform: translateY(-90px); - 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; - } -} - -.toast.active { - transform: translateY(0); -} diff --git a/ufund-ui/src/app/app.component.html b/ufund-ui/src/app/app.component.html index 89075e1..959eada 100644 --- a/ufund-ui/src/app/app.component.html +++ b/ufund-ui/src/app/app.component.html @@ -1,11 +1,3 @@ -
              - - - - - -
              - - +
              {{need.current}}/{{need.maxGoal}} ({{(need.current / need.maxGoal) * 100}}%)
              - +
              + {{need.description}} +
              + +

              Update Need

              @@ -53,9 +51,8 @@

              - + - {{statusText | async}}

              diff --git a/ufund-ui/src/app/components/login/login.component.html b/ufund-ui/src/app/components/login/login.component.html index e1c3e2a..c67b903 100644 --- a/ufund-ui/src/app/components/login/login.component.html +++ b/ufund-ui/src/app/components/login/login.component.html @@ -6,5 +6,4 @@ - {{statusText | async}} -- cgit v1.2.3 From 9c9708cc846dafe33234c38c37425468b9877514 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 21:32:55 -0400 Subject: Updated toast's types --- ufund-ui/src/app/components/cupboard/cupboard.component.ts | 12 ++++++------ .../components/funding-basket/funding-basket.component.ts | 6 +++++- ufund-ui/src/app/components/signup/signup.component.ts | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index fff8760..662def4 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -100,11 +100,11 @@ export class CupboardComponent implements OnInit { this.cupboardService.updateNeed(need.id, need) .pipe(catchError((ex, _) => { if (ex.status == 500) { - this.toastService.sendToast(ToastType.INFO, 'Fields cannot be blank'); + this.toastService.sendToast(ToastType.ERROR, 'Fields cannot be blank'); } else if (ex.status == 400) { - this.toastService.sendToast(ToastType.INFO, ex.error); + this.toastService.sendToast(ToastType.ERROR, ex.error); } else { - this.toastService.sendToast(ToastType.INFO, "Error on creating need"); + this.toastService.sendToast(ToastType.ERROR, "Error on creating need"); } return of() })) @@ -139,11 +139,11 @@ export class CupboardComponent implements OnInit { this.cupboardService.createNeed(need) .pipe(catchError((ex, _) => { if (ex.status == 500) { - this.toastService.sendToast(ToastType.INFO, "Fields cannot be blank"); + this.toastService.sendToast(ToastType.ERROR, "Fields cannot be blank"); } else if (ex.status == 400) { - this.toastService.sendToast(ToastType.INFO, ex.error); + this.toastService.sendToast(ToastType.ERROR, ex.error); } else { - this.toastService.sendToast(ToastType.INFO, "Error on creating need"); + this.toastService.sendToast(ToastType.ERROR, "Error on creating need"); } return of() })) 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 24e2c0b..54ae720 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 @@ -46,7 +46,11 @@ export class FundingBasketComponent implements OnInit { this.isValid = false; contribution.setAttribute("style", "color: #ff0000"); - this.toastService.sendToast(ToastType.WARNING, "Invalid input in funding basket!") + this.toastService.sendToast(ToastType.ERROR, "Invalid input in funding basket!") + + setTimeout(() => { + contribution.setAttribute("style", "color: #ffffff"); + }, 3000); } } // if (this.usersService.getBasket().value != await firstValueFrom(this.usersService.getUser(1)) diff --git a/ufund-ui/src/app/components/signup/signup.component.ts b/ufund-ui/src/app/components/signup/signup.component.ts index 5ec84ae..a20d828 100644 --- a/ufund-ui/src/app/components/signup/signup.component.ts +++ b/ufund-ui/src/app/components/signup/signup.component.ts @@ -47,7 +47,7 @@ export class SignupComponent { this.usersService.createUser(username, password).then(() => { this.showSuccessMessage.next(true); }).catch(ex => { - this.toastService.sendToast(ToastType.INFO, "Unable to create account: " + friendlyHttpStatus[ex.status]) + this.toastService.sendToast(ToastType.ERROR, "Unable to create account: " + friendlyHttpStatus[ex.status]) console.log(ex) }) } -- cgit v1.2.3 From 827831df4452449f11799c5e7daa2c6d1dd2ea90 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 21:35:26 -0400 Subject: Updated README --- README.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 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 -- cgit v1.2.3 From aef3df6f9eacfe37479046826a9ca14310b72456 Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 31 Mar 2025 21:54:38 -0400 Subject: Apply css to funding basket --- .../funding-basket/funding-basket.component.css | 85 +++++++++++++++- .../funding-basket/funding-basket.component.html | 112 ++++++++++++++------- .../funding-basket/funding-basket.component.ts | 6 +- .../components/need-list/need-list.component.css | 21 +++- .../components/need-list/need-list.component.html | 23 +++-- .../components/need-list/need-list.component.ts | 13 +-- ufund-ui/src/styles.css | 4 + 7 files changed, 202 insertions(+), 62 deletions(-) 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..a17f710 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: 1000px; + 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: 10px; + 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 @@ -

              Funding Basket

              -
              - - {{ this.usersService.getBasket().getValue().length }} -
              + + + + -
              -

              There are no needs in the basket

              -
              + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              +

              Funding Basket

              + +
              +
              +
              +
              +
              + {{need.name}} + {{need.type}} +
              + +
              + URGENT + location_on{{need.location}} +
              +
              + +
              - - - - - - - - - - - -
              - {{need.name}} -

              Goal: {{need.maxGoal}}

              -

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

              -

              How much to Contribute:

              -
              -
              - +
              + + {{need.current}}/{{need.maxGoal}} ({{((need.current / need.maxGoal) * 100).toFixed(0)}}%) + +
              + + + + +
              + +
              + +
              -
              -
              -
              -

              Invalid input in funding basket!

              - - {{statusText | async}} -
              \ No newline at end of file +
              +
              +
              + + +
              + There are no needs in your basket! Browse the cupboard +
              +
              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 24e2c0b..646ef35 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 @@ -39,7 +39,7 @@ export class FundingBasketComponent implements OnInit { async checkout() { this.isValid = true; - for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) { + for (let c of document.querySelectorAll('.contribution')!) { let contribution = c as HTMLInputElement; contribution.setAttribute("style", ""); if (contribution.value == '' || contribution.valueAsNumber <= 0) { @@ -59,7 +59,7 @@ export class FundingBasketComponent implements OnInit { // } // } if (this.isValid) { - for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) { + 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; @@ -77,11 +77,11 @@ export class FundingBasketComponent implements OnInit { })) .subscribe((result) => { if (result) { - console.log('need updated successfully'); //this.needList?.refresh() } else { console.log('need update failed'); } + this.toastService.sendToast(ToastType.INFO, "Checkout successful"); }); } } 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 1936b38..d4be5fa 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 @@ -5,11 +5,10 @@ } .needEntry { - background-color: #3a3a3a; + background-color: #2e2e2e; display: flex; flex-direction: column; border-radius: 5px; - padding: 10px; } #needList { @@ -59,6 +58,7 @@ select { flex-direction: row; justify-content: space-between; + .left { display: flex; flex-direction: column; @@ -83,3 +83,20 @@ select { 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/need-list/need-list.component.html b/ufund-ui/src/app/components/need-list/need-list.component.html index c325320..84f83d6 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 @@ -26,37 +26,38 @@
              -
              +
              {{need.name}} {{need.type}}
              - +
              URGENT location_on{{need.location}}
              - + +
              +
              {{need.current}}/{{need.maxGoal}} ({{((need.current / need.maxGoal) * 100).toFixed(0)}}%)
              -
              - {{need.description}} -
              - -
              - + +
              +
              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 47114c3..7a9d647 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,11 +1,11 @@ -import {Component , Output, EventEmitter} from '@angular/core'; -import { NgForm } from '@angular/forms'; +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; @@ -84,7 +84,8 @@ export class NeedListComponent { constructor( private cupboardService: CupboardService, private usersService: UsersService, - private authService: AuthService + private authService: AuthService, + private toastService: ToastsService ) {} refresh() { @@ -196,7 +197,7 @@ export class NeedListComponent { 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!") } diff --git a/ufund-ui/src/styles.css b/ufund-ui/src/styles.css index b152e61..f515154 100644 --- a/ufund-ui/src/styles.css +++ b/ufund-ui/src/styles.css @@ -38,6 +38,10 @@ button, input[type=button], input[type=reset], input[type=submit], .button { 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); -- cgit v1.2.3 From 4f8ddd385924b3c7c2b36acd28daf658ecc2cb09 Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 31 Mar 2025 21:57:32 -0400 Subject: Tweak validation in funding basket --- .../src/app/components/funding-basket/funding-basket.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts index b3826be..ecf452a 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 @@ -45,11 +45,11 @@ export class FundingBasketComponent implements OnInit { if (contribution.value == '' || contribution.valueAsNumber <= 0) { this.isValid = false; - contribution.setAttribute("style", "color: #ff0000"); + contribution.setAttribute("style", "border-color: #ff0000"); this.toastService.sendToast(ToastType.ERROR, "Invalid input in funding basket!") setTimeout(() => { - contribution.setAttribute("style", "color: #ffffff"); + contribution.setAttribute("style", "border-color: #ffffff"); }, 3000); } } -- cgit v1.2.3 From 786a6db3f5a22f7bb2cc249731ef654b675c3c86 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 31 Mar 2025 22:15:37 -0400 Subject: moving functionality to new component --- ufund-ui/src/app/app.module.ts | 2 + .../components/cupboard/cupboard.component.html | 23 -------- .../app/components/cupboard/cupboard.component.ts | 39 -------------- .../components/need-edit/need-edit.component.css | 0 .../components/need-edit/need-edit.component.html | 22 ++++++++ .../components/need-edit/need-edit.component.ts | 61 ++++++++++++++++++++++ 6 files changed, 85 insertions(+), 62 deletions(-) create mode 100644 ufund-ui/src/app/components/need-edit/need-edit.component.css create mode 100644 ufund-ui/src/app/components/need-edit/need-edit.component.html create mode 100644 ufund-ui/src/app/components/need-edit/need-edit.component.ts diff --git a/ufund-ui/src/app/app.module.ts b/ufund-ui/src/app/app.module.ts index c91256e..16455be 100644 --- a/ufund-ui/src/app/app.module.ts +++ b/ufund-ui/src/app/app.module.ts @@ -17,6 +17,7 @@ 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: [ @@ -31,6 +32,7 @@ import { ToastComponent } from './components/toast/toast.component'; SignupComponent, MiniNeedListComponent, ToastComponent, + NeedEditComponent, ], imports: [ BrowserModule, diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index 6f7799e..e9387a2 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -32,29 +32,6 @@
              -
              -

              Update Need

              -
              -
              -
              -
              -
              -
              -
              -
              - -
              - -
              - -
              -
              -
              - - -
              - -

              diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 662def4..e70d98f 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -82,45 +82,6 @@ export class CupboardComponent implements OnInit { return type === ("MANAGER" as unknown as userType); } - 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.needList?.refresh() - } else { - console.log("need update failed"); - } - } - - ); - } - submit(form: any) { const need: Need = { name: form.name, 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..e69de29 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..bcb166b --- /dev/null +++ b/ufund-ui/src/app/components/need-edit/need-edit.component.html @@ -0,0 +1,22 @@ +
              +

              Update Need

              +
              +
              +
              +
              +
              +
              +
              +
              + +
              + +
              + +
              +
              +
              + + +
              +
              \ No newline at end of file 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..02ffb71 --- /dev/null +++ b/ufund-ui/src/app/components/need-edit/need-edit.component.ts @@ -0,0 +1,61 @@ +import { Component, Input, Output } 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() selectedNeedID: number | null = null; + + 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.needList?.refresh() + } else { + console.log("need update failed"); + } + } + + ); + } +} \ No newline at end of file -- cgit v1.2.3 From 4186983da13740ec0a4731770ac238922631be11 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 31 Mar 2025 22:52:49 -0400 Subject: auto refresh with emitter --- ufund-ui/src/app/components/cupboard/cupboard.component.html | 1 + ufund-ui/src/app/components/need-edit/need-edit.component.ts | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html index e9387a2..2cfbe2d 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -8,6 +8,7 @@
              +

              Create Need

              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 index 02ffb71..2462534 100644 --- a/ufund-ui/src/app/components/need-edit/need-edit.component.ts +++ b/ufund-ui/src/app/components/need-edit/need-edit.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, Output } from '@angular/core'; +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'; @@ -18,7 +18,7 @@ export class NeedEditComponent { ) {} @Input() selectedNeed!: Need; - @Output() selectedNeedID: number | null = null; + @Output() refreshNeedList = new EventEmitter(); update(form: any) { console.log(form); @@ -50,7 +50,7 @@ export class NeedEditComponent { (result) => { if (result) { console.log("need updated successfully"); - // this.needList?.refresh() + this.refreshNeedList.emit(); } else { console.log("need update failed"); } -- cgit v1.2.3 From 896e1219526a19400c7143b274193f8b818d6156 Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 31 Mar 2025 23:37:00 -0400 Subject: Commit half working changes to move to my laptop --- .../funding-basket/funding-basket.component.ts | 1 - .../components/need-list/need-list.component.html | 4 +- .../components/need-list/need-list.component.ts | 4 +- .../components/need-page/need-page.component.css | 57 ++++++++++++++++++++ .../components/need-page/need-page.component.html | 41 ++++++++++++-- .../components/need-page/need-page.component.ts | 62 ++++++++++++++++++++-- ufund-ui/src/styles.css | 6 ++- 7 files changed, 161 insertions(+), 14 deletions(-) diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts index ecf452a..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 @@ -13,7 +13,6 @@ import {ToastsService, ToastType} from '../../services/toasts.service'; styleUrl: './funding-basket.component.css' }) export class FundingBasketComponent implements OnInit { - statusText: any; constructor( private router: Router, 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 84f83d6..e00ba47 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 @@ -54,10 +54,10 @@ addAdd To Basket
              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 7a9d647..d641acf 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 @@ -160,6 +160,7 @@ export class NeedListComponent { 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(); @@ -199,10 +200,7 @@ export class NeedListComponent { } else { this.toastService.sendToast(ToastType.ERROR, "This need is already in your basket!") } - - } - } back() { 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 a3a4014..f950171 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 @@ -8,3 +8,60 @@ flex-direction: column; 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; + } + + .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; +} + +.actionArea { + display: flex; + padding: 5px; + gap: 5px; +} + +#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 a72167c..a8479fd 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 @@ -13,14 +13,47 @@
              + {{need?.description}} + Need image

              Location: {{need?.location}}

              Urgent: {{need?.urgent}}

              {{need?.current}} / {{need?.maxGoal}} This goal is {{(((need?.current ?? 0)*100) / (need?.maxGoal ?? 0)).toFixed(0)}}% complete! -
              - - - +
              + + + +
              + +
              +
              +
              + {{need.name}} + {{need.type}} +
              + +
              + URGENT + location_on{{need.location}} +
              +
              + +
              + +
              + + {{need.current}}/{{need.maxGoal}} ({{((need.current / need.maxGoal) * 100).toFixed(0)}}%) + +
              +
              + +
              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 e38554c..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,8 +1,12 @@ 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', @@ -14,11 +18,15 @@ export class NeedPageComponent { constructor( private route: ActivatedRoute, private cupboardService: CupboardService, + private authService: AuthService, + private usersService: UsersService, + private toastService: ToastsService, + private router: Router ) {} public GoalType = GoalType; - @Input() need?: Need; + @Input() need!: Need; ngOnInit(): void { const id = Number(this.route.snapshot.paramMap.get('id')); @@ -28,4 +36,52 @@ export class NeedPageComponent { 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/styles.css b/ufund-ui/src/styles.css index f515154..75d6b36 100644 --- a/ufund-ui/src/styles.css +++ b/ufund-ui/src/styles.css @@ -1,7 +1,7 @@ /* You can add global styles to this file, and also import other style files */ :root { - color-scheme: light dark; + color-scheme: /*light*/ dark; } * { @@ -65,3 +65,7 @@ button, input[type=button], input[type=reset], input[type=submit], .button { h1 { font-size: 40px; } + +progress { + min-width: 100%; +} -- cgit v1.2.3 From bb2e7b50e1ca96120fc42eed1f090cf0e1c98258 Mon Sep 17 00:00:00 2001 From: benal01 Date: Mon, 31 Mar 2025 23:47:36 -0400 Subject: needs per page --- .../components/need-list/need-list.component.html | 9 +++++- .../components/need-list/need-list.component.ts | 34 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) 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 84f83d6..d43e07b 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.html +++ b/ufund-ui/src/app/components/need-list/need-list.component.html @@ -24,8 +24,15 @@

              All Needs

              No Results Found

              +
              + Page {{currentPage + 1}} of {{totalPages}}
              + + + + +
              -
              +
              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 7a9d647..bc3de42 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 @@ -66,7 +66,36 @@ 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'; @@ -96,6 +125,7 @@ export class NeedListComponent { this.needs = n.sort(this.currentSortAlgo).reverse(); } this.searchResults = this.needs; + this.updateVisibleNeeds(); }); const form = document.getElementById('search-form') as HTMLFormElement; @@ -105,6 +135,7 @@ export class NeedListComponent { ngOnInit(): void { this.refresh() + } changeSortMode(form : any) { @@ -145,8 +176,7 @@ export class NeedListComponent { } else { this.searchResults = n.sort(this.currentSortAlgo).reverse(); } - - console.log(currentSearchValue, this.searchResults); + this.updateVisibleNeeds(); }); } }, 250); -- cgit v1.2.3 From 61daadccf89b2b84820386558ac454c0123d4299 Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 1 Apr 2025 01:16:49 -0400 Subject: More css cleanup --- ufund-ui/src/app/app.component.css | 44 ++++++++-------- .../app/components/cupboard/cupboard.component.css | 4 +- .../funding-basket/funding-basket.component.css | 2 +- .../components/home-page/home-page.component.css | 1 + .../components/need-list/need-list.component.css | 8 +++ .../components/need-list/need-list.component.html | 15 +++--- .../components/need-page/need-page.component.css | 30 ++++++----- .../components/need-page/need-page.component.html | 60 +++++++++------------- 8 files changed, 85 insertions(+), 79 deletions(-) diff --git a/ufund-ui/src/app/app.component.css b/ufund-ui/src/app/app.component.css index 0bcd658..f4ed668 100644 --- a/ufund-ui/src/app/app.component.css +++ b/ufund-ui/src/app/app.component.css @@ -38,29 +38,33 @@ text-decoration: none; } - a { - display: block; - position: relative; - padding: 0.1em 0; + a:hover { + text-decoration: underline; } - 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 {*/ + /* display: block;*/ + /* position: relative;*/ + /* padding: 0.1em 0;*/ + /*}*/ - a:hover::after, - a:focus::after { - opacity: 1; - transform: translate3d(0, 0.2em, 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/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index faff4d4..4116a77 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -4,7 +4,7 @@ } #box { - width: 1000px; + width: 800px; display: flex; flex-direction: column; } @@ -22,7 +22,7 @@ border-top-left-radius: 5px; border-top-right-radius: 5px; margin-right: 5px; - border-bottom: 0px; + border-bottom: 0; } .selected-tab { 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 a17f710..dff6e06 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 @@ -5,7 +5,7 @@ #box { display: flex; - width: 1000px; + width: 800px; flex-direction: column; gap: 10px; } 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 16f3140..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 @@ -4,6 +4,7 @@ flex-direction: column; align-items: center; justify-content: center; + overflow: clip; } #hero { 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 d4be5fa..041b4ce 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 @@ -100,3 +100,11 @@ select { 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 8ea7b88..8ea88b1 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 @@ -15,6 +15,8 @@ + +
              @@ -24,13 +26,6 @@

              All Needs

              No Results Found

              -
              - Page {{currentPage + 1}} of {{totalPages}}
              - - - - -
              @@ -69,3 +64,9 @@
              + +
              + + Page {{currentPage + 1}} of {{totalPages}} + +
              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 f950171..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 @@ -6,7 +6,9 @@ #box { display: flex; flex-direction: column; - width: 1000px; + width: 800px; + justify-content: start; + gap: 10px; } .needName { @@ -15,7 +17,9 @@ .needType { text-transform: uppercase; - font-size: 10pt; + /*font-size: 10pt;*/ + margin-top: -20px; + /*margin-bottom: 20px;*/ } .split { @@ -47,21 +51,23 @@ .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; -} +/*#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 a8479fd..e8d292e 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,10 +1,29 @@

              {{need?.name}}

              -
              -

              Looking for {{need?.type}} Donations.

              + {{need?.type}} GOAL + + Need image + +

              {{need?.description}}

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

              Tags:

              + + Target Goal: {{need.maxGoal}} + + Amount Currently Collected: {{need.current}} + + Location: {{need.location}} + + Urgency: + Not urgent + URGENT + + +
              + Tags:
              • {{tag}}

                @@ -12,14 +31,6 @@
              -
              - {{need?.description}} - Need image -

              Location: {{need?.location}}

              -

              Urgent: {{need?.urgent}}

              - {{need?.current}} / {{need?.maxGoal}} - - This goal is {{(((need?.current ?? 0)*100) / (need?.maxGoal ?? 0)).toFixed(0)}}% complete!
              - -
              -
              -
              - {{need.name}} - {{need.type}} -
              - -
              - URGENT - location_on{{need.location}} -
              -
              - -
              - -
              - - {{need.current}}/{{need.maxGoal}} ({{((need.current / need.maxGoal) * 100).toFixed(0)}}%) - -
              - -
              - -
              -- cgit v1.2.3 From 0e9c0803e35a23ef2e873dc7ebf224a49a92f207 Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 1 Apr 2025 02:16:04 -0400 Subject: Get everything working enough to go in main --- .../app/components/cupboard/cupboard.component.css | 18 +++++++++++++--- .../components/cupboard/cupboard.component.html | 24 +++++++++++----------- .../app/components/cupboard/cupboard.component.ts | 2 +- .../components/dashboard/dashboard.component.html | 2 +- .../components/dashboard/dashboard.component.ts | 9 ++++++-- .../funding-basket/funding-basket.component.css | 2 +- .../components/need-edit/need-edit.component.css | 21 +++++++++++++++++++ .../components/need-edit/need-edit.component.html | 6 ++++-- .../components/need-list/need-list.component.css | 2 +- .../components/need-list/need-list.component.html | 1 - .../components/need-page/need-page.component.html | 6 +++--- 11 files changed, 66 insertions(+), 27 deletions(-) diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.css b/ufund-ui/src/app/components/cupboard/cupboard.component.css index 4116a77..e45d929 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.css +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.css @@ -30,13 +30,25 @@ } #create-form, #delete-form, #update-form { - background-color: #d9d9d9; + background-color: #3a3a3a; padding: 10px 20px 20px 20px; border: 2px solid #000; border-radius: 5px; visibility: visible; + /*position: absolute;*/ } -#create-button { - padding: 10px 20px; +#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 2cfbe2d..37954bb 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.html +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html @@ -1,14 +1,14 @@
              -

              Cupboard

              +
              -
              -

              Admin View

              - - + +
              + +

              Create Need

              @@ -27,12 +27,12 @@

              - -
              +
              +
              -
              - +
              +
              diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index e70d98f..2230cd3 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -16,7 +16,7 @@ import {ToastsService, ToastType} from '../../services/toasts.service'; export class CupboardComponent implements OnInit { - selectedForm = "create"; + selectedForm?: string = undefined; needs: any; @ViewChild("needList") needList?: NeedListComponent diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.html b/ufund-ui/src/app/components/dashboard/dashboard.component.html index 330d1f3..6a95ecd 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.html +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.html @@ -2,4 +2,4 @@

              Your Dashboard

              - + diff --git a/ufund-ui/src/app/components/dashboard/dashboard.component.ts b/ufund-ui/src/app/components/dashboard/dashboard.component.ts index 645893f..c94b5c6 100644 --- a/ufund-ui/src/app/components/dashboard/dashboard.component.ts +++ b/ufund-ui/src/app/components/dashboard/dashboard.component.ts @@ -4,6 +4,7 @@ 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', @@ -20,7 +21,8 @@ export class DashboardComponent implements OnInit{ constructor( protected authService: AuthService, protected router: Router, - protected cupboardService: CupboardService + protected cupboardService: CupboardService, + protected userService: UsersService ) {} ngOnInit() { @@ -33,7 +35,10 @@ export class DashboardComponent implements OnInit{ 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.inBasket = r.filter(n => n.id in user!.basket) + }) + + 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 dff6e06..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 @@ -20,7 +20,7 @@ #needList { display: flex; flex-direction: column; - gap: 10px; + gap: 15px; max-width: 1000px; } 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 index e69de29..17605c2 100644 --- a/ufund-ui/src/app/components/need-edit/need-edit.component.css +++ 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 index bcb166b..e776415 100644 --- a/ufund-ui/src/app/components/need-edit/need-edit.component.html +++ b/ufund-ui/src/app/components/need-edit/need-edit.component.html @@ -1,9 +1,11 @@

              Update Need

              -
              +

              +

              +



              @@ -19,4 +21,4 @@
              -
              \ 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 041b4ce..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 @@ -14,7 +14,7 @@ #needList { display: flex; flex-direction: column; - gap: 10px + gap: 15px } select { 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 8ea88b1..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 @@ -25,7 +25,6 @@

              Search Results({{needs.length - searchResults.length}} needs filtered):

              All Needs

              No Results Found

              -
              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 e8d292e..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 @@ -35,9 +35,9 @@ - + + + -- cgit v1.2.3 From bc9d3417795d841b4cb3e9fb022f8d61448af946 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Tue, 1 Apr 2025 07:47:13 -0400 Subject: Added updated acceptance test plan --- etc/Acceptance Test Plan.xlsx | Bin 30698 -> 71297 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/etc/Acceptance Test Plan.xlsx b/etc/Acceptance Test Plan.xlsx index dd55e20..396cc1c 100644 Binary files a/etc/Acceptance Test Plan.xlsx and b/etc/Acceptance Test Plan.xlsx differ -- cgit v1.2.3