Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { throwError, Observable, forkJoin } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { ConfigService } from './config.service';
import { Course } from './models/course';
import { DegreePlan } from './models/degree-plan';
import { Term } from './models/term';
import { SavedForLaterCourse } from './models/saved-for-later-course';
import { CourseDetails } from './models/course-details';
import { Note } from './models/note';
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
@Injectable()
export class DataService {
private plannerApiUrl: string;
private searchApiUrl: string;
constructor(private http: HttpClient, private configService: ConfigService) {
this.plannerApiUrl = this.configService.apiPlannerUrl;
this.searchApiUrl = this.configService.apiSearchUrl;
}
getAllPlanData(roadmapId: number) {
return forkJoin(
this.getDegreePlannerCourseData(roadmapId),
this.getTerms()
);
}
getDegreePlans(): Observable<DegreePlan[]> {
return this.http.get<DegreePlan[]>(this.plannerApiUrl + '/degreePlan')
.pipe(catchError(this.errorHandler));
}
getDegreePlannerCourseData(roadmapId: number): Observable<Course[]> {
return this.http.get<Course[]>(this.plannerApiUrl + '/degreePlan/' + roadmapId + '/courses')
.pipe(catchError(this.errorHandler));
}
getDegreePlannerCourseData2(roadmapId: number): Observable<Course> {
return this.http.get<Course>(this.plannerApiUrl + '/degreePlan/' + roadmapId + '/courses')
.pipe(catchError(this.errorHandler));
}
getTerms(): Observable<Term[]> {
return this.http.get<Term[]>(this.searchApiUrl + '/terms')
.pipe(catchError(this.errorHandler));
}
getCourseDetails(termCode: string, subjectCode: string, courseId: string): Observable<CourseDetails[]> {
return this.http.get<CourseDetails[]>(this.searchApiUrl + '/course/0000/' + subjectCode + '/' + courseId, httpOptions)
.pipe(catchError(this.errorHandler));
}
getSubjectsMap(): Observable<Object> {
return this.http.get(this.searchApiUrl + '/subjectsMap/0000', httpOptions)
.pipe(catchError(this.errorHandler));
}
getFavoriteCourses(): Observable<SavedForLaterCourse[]> {
return this.http.get<SavedForLaterCourse[]>(this.plannerApiUrl + '/favorites')
.pipe(catchError(this.errorHandler));
}
getAllNotes(planId: number): Observable<Note[]> {
return this.http.get<Note[]>(this.plannerApiUrl + '/degreePlan/' + planId + '/notes')
.pipe(catchError(this.errorHandler));
}
getNote(planId, noteId): Observable<Note[]> {
return this.http.get<Note[]>(this.plannerApiUrl + '/degreePlan/' + planId + '/notes/' + noteId)
.pipe(catchError(this.errorHandler));
}
updateNote(planId, note): Observable<Note[]> {
return this.http.put<Note[]>(this.plannerApiUrl + '/degreePlan/' + planId + '/notes/' + note.id, note, httpOptions)
.pipe(catchError(this.errorHandler));
}
createNote(planId, note): Observable<Note[]> {
return this.http.post<Note[]>(this.plannerApiUrl + '/degreePlan/' + planId + '/notes/', note, httpOptions)
.pipe(catchError(this.errorHandler));
}
removeNote(planId, noteId): Observable<Note[]> {
return this.http.delete<Note[]>(this.plannerApiUrl + '/degreePlan/' + planId + '/notes/' + noteId, httpOptions)
.pipe(catchError(this.errorHandler));
}
saveFavoriteCourse(subjectCode: string, courseId: string): Observable<SavedForLaterCourse> {
return this.http.post<SavedForLaterCourse>(this.plannerApiUrl + '/favorites/' + subjectCode + '/' + courseId, httpOptions)
.pipe(catchError(this.errorHandler));
}
removeFavoriteCourse(subjectCode, courseId): Observable<SavedForLaterCourse> {
return this.http.delete<SavedForLaterCourse>(this.plannerApiUrl + '/favorites/' + subjectCode + '/' + courseId, httpOptions)
.pipe(catchError(this.errorHandler));
}
addCourse(planId, subjectCode, courseId, termCode) {
return this.http.post(this.plannerApiUrl + '/degreePlan/' + planId + '/courses', {subjectCode, courseId, termCode }, httpOptions)
.pipe(catchError(this.errorHandler));
}
removeCourse(planId, recordId) {
return this.http.delete(this.plannerApiUrl + '/degreePlan/' + planId + '/courses/' + recordId, httpOptions)
.pipe(catchError(this.errorHandler));
}
updateCourseTerm(planId, recordId, termCode): Observable<Course> {
return this.http.put<Course>(this.plannerApiUrl + '/degreePlan/' + planId + '/courses/' + recordId + '?termCode=' + termCode, httpOptions)
.pipe(catchError(this.errorHandler));
}
test() {
// return this.http.delete(this.plannerApiUrl + '/degreePlan/519260/courses/259445', httpOptions)
return this.http.put(this.plannerApiUrl + '/degreePlan/519260/courses/259465?termCode=1174', httpOptions)
.pipe(catchError(this.errorHandler));
}
private errorHandler(error: HttpErrorResponse) {
return throwError(error || 'Server Error');
}
}