mirror of
https://github.com/opelly27/WinStudentGoalTracker.git
synced 2026-05-20 09:57:37 +00:00
latest
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { StudentCardDto } from '../classes/student-card.dto';
|
||||
import { ApiResult } from '../classes/api-result';
|
||||
import { StudentGoalSummary } from '../classes/student-goal';
|
||||
import { StudentGoalSummary, StudentGoalItem } from '../classes/student-goal';
|
||||
import { CreateGoalDto } from '../classes/create-goal.dto';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -105,6 +106,25 @@ export class DummyStudentService {
|
||||
|
||||
}
|
||||
|
||||
async createGoal(studentId: string, data: CreateGoalDto): Promise<ApiResult<StudentGoalItem>> {
|
||||
const student = this.data[studentId];
|
||||
if (!student) {
|
||||
return ApiResult.fail('Student not found');
|
||||
}
|
||||
|
||||
const newGoal: StudentGoalItem = {
|
||||
goalId: `g${Date.now()}`,
|
||||
goalParentId: null,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
category: data.category,
|
||||
progressEventCount: 0,
|
||||
};
|
||||
|
||||
student.goals.push(newGoal);
|
||||
return ApiResult.ok(newGoal);
|
||||
}
|
||||
|
||||
async addProgressEvent(studentId: string, goalId: string, content: string): Promise<ApiResult> {
|
||||
return ApiResult.empty();
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@ import { ApiResult } from '../classes/api-result';
|
||||
import { ResponseResult } from '../classes/auth.models';
|
||||
import { describeHttpError } from '../classes/http-errors';
|
||||
import { CreateStudentDto } from '../classes/create-student.dto';
|
||||
import { CreateGoalDto } from '../classes/create-goal.dto';
|
||||
import { StudentCardDto } from '../classes/student-card.dto';
|
||||
import { StudentGoalSummary } from '../classes/student-goal';
|
||||
import { StudentGoalSummary, StudentGoalItem } from '../classes/student-goal';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -73,6 +74,22 @@ export class StudentService {
|
||||
}
|
||||
}
|
||||
|
||||
// *****************************************************************
|
||||
// Creates a new goal for a student and returns the created goal.
|
||||
// *****************************************************************
|
||||
async createGoal(studentId: string, data: CreateGoalDto): Promise<ApiResult<StudentGoalItem>> {
|
||||
try {
|
||||
const result = await firstValueFrom(
|
||||
this.http.post<ResponseResult<StudentGoalItem>>(`${this.base}/api/Student/${studentId}/goals`, data)
|
||||
);
|
||||
return result.success && result.data
|
||||
? ApiResult.ok(result.data)
|
||||
: ApiResult.fail(result.message);
|
||||
} catch (error) {
|
||||
return ApiResult.fail(describeHttpError(error as HttpErrorResponse));
|
||||
}
|
||||
}
|
||||
|
||||
async addProgressEvent(studentId: string, goalId: string, content: string): Promise<ApiResult> {
|
||||
try {
|
||||
const result = await firstValueFrom(
|
||||
|
||||
Reference in New Issue
Block a user