From 15b82360bfac530f827080161119c81d9307bf59 Mon Sep 17 00:00:00 2001 From: Oliver Pelly Date: Mon, 2 Mar 2026 13:01:04 -0800 Subject: [PATCH] moved dummy services to return ApiResult type, and Promise API instead of rxjs observable --- .../add-progress-event/add-progress-event.ts | 28 +++++++++---------- .../src/app/mobile/pages/home/home.ts | 16 +++++++++-- .../pages/student-goals/student-goals.ts | 17 +++++++++-- .../src/app/shared/services/api.ts | 5 ++++ .../dummy-mobile-home-meta.service.ts | 9 ++++-- .../dummy-save-progress-event.service.ts | 4 +-- .../services/dummy-student-goal.service.ts | 13 +++++++-- 7 files changed, 65 insertions(+), 27 deletions(-) diff --git a/ui/winstudentgoaltracker/src/app/mobile/pages/add-progress-event/add-progress-event.ts b/ui/winstudentgoaltracker/src/app/mobile/pages/add-progress-event/add-progress-event.ts index 84022e6..57a7428 100644 --- a/ui/winstudentgoaltracker/src/app/mobile/pages/add-progress-event/add-progress-event.ts +++ b/ui/winstudentgoaltracker/src/app/mobile/pages/add-progress-event/add-progress-event.ts @@ -61,24 +61,22 @@ export class AddProgressEvent { // Saves the progress event. On success, returns to the goal list. // On failure, displays the error message from the API. // ***************************************************************** - onSave() { + async onSave() { this.error.set(null); this.saving.set(true); - this.saveService.save(this.studentId, this.goalId, this.notes().trim()).subscribe({ - next: (result) => { - this.saving.set(false); - if (result.success) { - this.router.navigate(['students', this.studentId, 'goals']); - } else { - this.error.set(result.message); - } - }, - error: (err: HttpErrorResponse) => { - this.saving.set(false); - this.error.set(describeHttpError(err)); - }, - }); + try { + const result = await this.saveService.save(this.studentId, this.goalId, this.notes().trim()); + this.saving.set(false); + if (result.success) { + this.router.navigate(['students', this.studentId, 'goals']); + } else { + this.error.set(result.message); + } + } catch (err) { + this.saving.set(false); + this.error.set(describeHttpError(err as HttpErrorResponse)); + } } // ********************** Support Procedures *********************** diff --git a/ui/winstudentgoaltracker/src/app/mobile/pages/home/home.ts b/ui/winstudentgoaltracker/src/app/mobile/pages/home/home.ts index a07f381..96b1711 100644 --- a/ui/winstudentgoaltracker/src/app/mobile/pages/home/home.ts +++ b/ui/winstudentgoaltracker/src/app/mobile/pages/home/home.ts @@ -24,6 +24,10 @@ export class Home { protected readonly meta = signal(null); + + // TODO show this in the UI + public errorMessage = signal(null); + // ************************** Properties *************************** // ************************ Public Methods ************************* @@ -41,8 +45,16 @@ export class Home { // ********************** Support Procedures *********************** private loadMeta() { - this.metaService.getMeta().subscribe(data => { - this.meta.set(data); + this.metaService.getMeta().then(data => { + + if (!data.success) + { + this.errorMessage.set(data.message); + } + else + { + this.meta.set(data.payload); + } }); } } diff --git a/ui/winstudentgoaltracker/src/app/mobile/pages/student-goals/student-goals.ts b/ui/winstudentgoaltracker/src/app/mobile/pages/student-goals/student-goals.ts index 77544af..6f7e925 100644 --- a/ui/winstudentgoaltracker/src/app/mobile/pages/student-goals/student-goals.ts +++ b/ui/winstudentgoaltracker/src/app/mobile/pages/student-goals/student-goals.ts @@ -25,6 +25,9 @@ export class StudentGoals { private readonly studentId = this.route.snapshot.paramMap.get('studentId') ?? ''; protected readonly data = signal(null); + // TODO show this in the UI + public errorMessage = signal(null); + // ************************** Properties *************************** // ************************ Public Methods ************************* @@ -56,8 +59,18 @@ export class StudentGoals { private loadGoals() { if (!this.studentId) return; - this.goalService.getGoalsForStudent(this.studentId).subscribe(result => { - this.data.set(result); + this.goalService.getGoalsForStudent(this.studentId).then(result => { + + if (!result.success) + { + this.errorMessage.set(result.message) + } + + else + { + this.data.set(result.payload); + } + }); } } diff --git a/ui/winstudentgoaltracker/src/app/shared/services/api.ts b/ui/winstudentgoaltracker/src/app/shared/services/api.ts index 6efa537..8d208e7 100644 --- a/ui/winstudentgoaltracker/src/app/shared/services/api.ts +++ b/ui/winstudentgoaltracker/src/app/shared/services/api.ts @@ -19,6 +19,8 @@ export class Api { private readonly http = inject(HttpClient); private readonly base = environment.apiBaseUrl; + // ************************** Auth Endpoints ************************** + // Phase 1 — verify credentials, receive session token + program list login(request: LoginRequest): Observable> { return this.http.post>( @@ -50,4 +52,7 @@ export class Api { request, ); } + + + } diff --git a/ui/winstudentgoaltracker/src/app/shared/services/dummy-mobile-home-meta.service.ts b/ui/winstudentgoaltracker/src/app/shared/services/dummy-mobile-home-meta.service.ts index bf5abfa..b707da0 100644 --- a/ui/winstudentgoaltracker/src/app/shared/services/dummy-mobile-home-meta.service.ts +++ b/ui/winstudentgoaltracker/src/app/shared/services/dummy-mobile-home-meta.service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core'; import { Observable, of } from 'rxjs'; +import { ApiResult } from '../classes/api-result'; // ***************************************************************** // TODO: This dummy service should be replaced by MobileHomeMeta, @@ -29,11 +30,13 @@ export class DummyMobileHomeMeta { // Replace with MobileHomeMeta service that calls // GET /api/mobile/home-meta (or similar). // ***************************************************************** - getMeta(): Observable { - return of({ + async getMeta(): Promise> { + var payload = { programName: 'WIN Program', userName: 'Polly Balsillie', - }); + } + + return ApiResult.ok(payload); } // ************************ Event Handlers ************************* diff --git a/ui/winstudentgoaltracker/src/app/shared/services/dummy-save-progress-event.service.ts b/ui/winstudentgoaltracker/src/app/shared/services/dummy-save-progress-event.service.ts index e4ac9a1..a8d15e9 100644 --- a/ui/winstudentgoaltracker/src/app/shared/services/dummy-save-progress-event.service.ts +++ b/ui/winstudentgoaltracker/src/app/shared/services/dummy-save-progress-event.service.ts @@ -24,8 +24,8 @@ export class DummySaveProgressEvent { // TODO: DUMMY — Always returns success. Replace with // SaveProgressEvent calling POST /api/progress-events // ***************************************************************** - save(studentId: string, goalId: string, content: string): Observable { - return of(ApiResult.empty()); + async save(studentId: string, goalId: string, content: string): Promise { + return ApiResult.empty(); } // ************************ Event Handlers ************************* diff --git a/ui/winstudentgoaltracker/src/app/shared/services/dummy-student-goal.service.ts b/ui/winstudentgoaltracker/src/app/shared/services/dummy-student-goal.service.ts index dc79b85..0597aee 100644 --- a/ui/winstudentgoaltracker/src/app/shared/services/dummy-student-goal.service.ts +++ b/ui/winstudentgoaltracker/src/app/shared/services/dummy-student-goal.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { Observable, of } from 'rxjs'; +import { ApiResult } from '../classes/api-result'; // ***************************************************************** // TODO: This dummy service should be replaced by StudentGoalService, @@ -84,8 +84,15 @@ export class DummyStudentGoalService { // Returns the student's identifier and their list of goals, // given a student ID. // ***************************************************************** - getGoalsForStudent(studentId: string): Observable { - return of(this.data[studentId] ?? null); + async getGoalsForStudent(studentId: string): Promise> { + var goals = this.data[studentId] ?? null; + if (goals === null) + { + return ApiResult.fail('Student not found'); + } + + return ApiResult.ok(goals); + } // ************************ Event Handlers *************************