mirror of
https://github.com/opelly27/WinStudentGoalTracker.git
synced 2026-05-20 02:57:36 +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.
|
// Saves the progress event. On success, returns to the goal list.
|
||||||
// On failure, displays the error message from the API.
|
// On failure, displays the error message from the API.
|
||||||
// *****************************************************************
|
// *****************************************************************
|
||||||
onSave() {
|
async onSave() {
|
||||||
this.error.set(null);
|
this.error.set(null);
|
||||||
this.saving.set(true);
|
this.saving.set(true);
|
||||||
|
|
||||||
this.saveService.save(this.studentId, this.goalId, this.notes().trim()).subscribe({
|
try {
|
||||||
next: (result) => {
|
const result = await this.saveService.save(this.studentId, this.goalId, this.notes().trim());
|
||||||
this.saving.set(false);
|
this.saving.set(false);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
this.router.navigate(['students', this.studentId, 'goals']);
|
this.router.navigate(['students', this.studentId, 'goals']);
|
||||||
} else {
|
} else {
|
||||||
this.error.set(result.message);
|
this.error.set(result.message);
|
||||||
}
|
}
|
||||||
},
|
} catch (err) {
|
||||||
error: (err: HttpErrorResponse) => {
|
this.saving.set(false);
|
||||||
this.saving.set(false);
|
this.error.set(describeHttpError(err as HttpErrorResponse));
|
||||||
this.error.set(describeHttpError(err));
|
}
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ********************** Support Procedures ***********************
|
// ********************** Support Procedures ***********************
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ export class Home {
|
|||||||
|
|
||||||
protected readonly meta = signal<MobileHomeMeta | null>(null);
|
protected readonly meta = signal<MobileHomeMeta | null>(null);
|
||||||
|
|
||||||
|
|
||||||
|
// TODO show this in the UI
|
||||||
|
public errorMessage = signal<String | null>(null);
|
||||||
|
|
||||||
// ************************** Properties ***************************
|
// ************************** Properties ***************************
|
||||||
|
|
||||||
// ************************ Public Methods *************************
|
// ************************ Public Methods *************************
|
||||||
@@ -41,8 +45,16 @@ export class Home {
|
|||||||
// ********************** Support Procedures ***********************
|
// ********************** Support Procedures ***********************
|
||||||
|
|
||||||
private loadMeta() {
|
private loadMeta() {
|
||||||
this.metaService.getMeta().subscribe(data => {
|
this.metaService.getMeta().then(data => {
|
||||||
this.meta.set(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') ?? '';
|
private readonly studentId = this.route.snapshot.paramMap.get('studentId') ?? '';
|
||||||
protected readonly data = signal<StudentGoalSummary | null>(null);
|
protected readonly data = signal<StudentGoalSummary | null>(null);
|
||||||
|
|
||||||
|
// TODO show this in the UI
|
||||||
|
public errorMessage = signal<String | null>(null);
|
||||||
|
|
||||||
// ************************** Properties ***************************
|
// ************************** Properties ***************************
|
||||||
|
|
||||||
// ************************ Public Methods *************************
|
// ************************ Public Methods *************************
|
||||||
@@ -56,8 +59,18 @@ export class StudentGoals {
|
|||||||
private loadGoals() {
|
private loadGoals() {
|
||||||
if (!this.studentId) return;
|
if (!this.studentId) return;
|
||||||
|
|
||||||
this.goalService.getGoalsForStudent(this.studentId).subscribe(result => {
|
this.goalService.getGoalsForStudent(this.studentId).then(result => {
|
||||||
this.data.set(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 http = inject(HttpClient);
|
||||||
private readonly base = environment.apiBaseUrl;
|
private readonly base = environment.apiBaseUrl;
|
||||||
|
|
||||||
|
// ************************** Auth Endpoints **************************
|
||||||
|
|
||||||
// Phase 1 — verify credentials, receive session token + program list
|
// Phase 1 — verify credentials, receive session token + program list
|
||||||
login(request: LoginRequest): Observable<ResponseResult<LoginResponse>> {
|
login(request: LoginRequest): Observable<ResponseResult<LoginResponse>> {
|
||||||
return this.http.post<ResponseResult<LoginResponse>>(
|
return this.http.post<ResponseResult<LoginResponse>>(
|
||||||
@@ -50,4 +52,7 @@ export class Api {
|
|||||||
request,
|
request,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Observable, of } from 'rxjs';
|
import { Observable, of } from 'rxjs';
|
||||||
|
import { ApiResult } from '../classes/api-result';
|
||||||
|
|
||||||
// *****************************************************************
|
// *****************************************************************
|
||||||
// TODO: This dummy service should be replaced by MobileHomeMeta,
|
// TODO: This dummy service should be replaced by MobileHomeMeta,
|
||||||
@@ -29,11 +30,13 @@ export class DummyMobileHomeMeta {
|
|||||||
// Replace with MobileHomeMeta service that calls
|
// Replace with MobileHomeMeta service that calls
|
||||||
// GET /api/mobile/home-meta (or similar).
|
// GET /api/mobile/home-meta (or similar).
|
||||||
// *****************************************************************
|
// *****************************************************************
|
||||||
getMeta(): Observable<MobileHomeMeta> {
|
async getMeta(): Promise<ApiResult<MobileHomeMeta | null>> {
|
||||||
return of({
|
var payload = {
|
||||||
programName: 'WIN Program',
|
programName: 'WIN Program',
|
||||||
userName: 'Polly Balsillie',
|
userName: 'Polly Balsillie',
|
||||||
});
|
}
|
||||||
|
|
||||||
|
return ApiResult.ok(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************************ Event Handlers *************************
|
// ************************ Event Handlers *************************
|
||||||
|
|||||||
+2
-2
@@ -24,8 +24,8 @@ export class DummySaveProgressEvent {
|
|||||||
// TODO: DUMMY — Always returns success. Replace with
|
// TODO: DUMMY — Always returns success. Replace with
|
||||||
// SaveProgressEvent calling POST /api/progress-events
|
// SaveProgressEvent calling POST /api/progress-events
|
||||||
// *****************************************************************
|
// *****************************************************************
|
||||||
save(studentId: string, goalId: string, content: string): Observable<ApiResult> {
|
async save(studentId: string, goalId: string, content: string): Promise<ApiResult> {
|
||||||
return of(ApiResult.empty());
|
return ApiResult.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************************ Event Handlers *************************
|
// ************************ Event Handlers *************************
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
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,
|
// 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,
|
// Returns the student's identifier and their list of goals,
|
||||||
// given a student ID.
|
// given a student ID.
|
||||||
// *****************************************************************
|
// *****************************************************************
|
||||||
getGoalsForStudent(studentId: string): Observable<StudentGoalSummary | null> {
|
async getGoalsForStudent(studentId: string): Promise<ApiResult<StudentGoalSummary | null>> {
|
||||||
return of(this.data[studentId] ?? null);
|
var goals = this.data[studentId] ?? null;
|
||||||
|
if (goals === null)
|
||||||
|
{
|
||||||
|
return ApiResult.fail('Student not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
return ApiResult.ok(goals);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************************ Event Handlers *************************
|
// ************************ Event Handlers *************************
|
||||||
|
|||||||
Reference in New Issue
Block a user