mirror of
https://github.com/opelly27/WinStudentGoalTracker.git
synced 2026-05-20 01:47:41 +00:00
moved dummy services to return ApiResult type, and Promise API instead of rxjs observable
This commit is contained in:
+13
-15
@@ -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 ***********************
|
||||
|
||||
@@ -24,6 +24,10 @@ export class Home {
|
||||
|
||||
protected readonly meta = signal<MobileHomeMeta | null>(null);
|
||||
|
||||
|
||||
// TODO show this in the UI
|
||||
public errorMessage = signal<String | null>(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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ export class StudentGoals {
|
||||
private readonly studentId = this.route.snapshot.paramMap.get('studentId') ?? '';
|
||||
protected readonly data = signal<StudentGoalSummary | null>(null);
|
||||
|
||||
// TODO show this in the UI
|
||||
public errorMessage = signal<String | null>(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);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ResponseResult<LoginResponse>> {
|
||||
return this.http.post<ResponseResult<LoginResponse>>(
|
||||
@@ -50,4 +52,7 @@ export class Api {
|
||||
request,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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<MobileHomeMeta> {
|
||||
return of({
|
||||
async getMeta(): Promise<ApiResult<MobileHomeMeta | null>> {
|
||||
var payload = {
|
||||
programName: 'WIN Program',
|
||||
userName: 'Polly Balsillie',
|
||||
});
|
||||
}
|
||||
|
||||
return ApiResult.ok(payload);
|
||||
}
|
||||
|
||||
// ************************ Event Handlers *************************
|
||||
|
||||
+2
-2
@@ -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<ApiResult> {
|
||||
return of(ApiResult.empty());
|
||||
async save(studentId: string, goalId: string, content: string): Promise<ApiResult> {
|
||||
return ApiResult.empty();
|
||||
}
|
||||
|
||||
// ************************ Event Handlers *************************
|
||||
|
||||
@@ -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<StudentGoalSummary | null> {
|
||||
return of(this.data[studentId] ?? null);
|
||||
async getGoalsForStudent(studentId: string): Promise<ApiResult<StudentGoalSummary | null>> {
|
||||
var goals = this.data[studentId] ?? null;
|
||||
if (goals === null)
|
||||
{
|
||||
return ApiResult.fail('Student not found');
|
||||
}
|
||||
|
||||
return ApiResult.ok(goals);
|
||||
|
||||
}
|
||||
|
||||
// ************************ Event Handlers *************************
|
||||
|
||||
Reference in New Issue
Block a user