Skip to content
Snippets Groups Projects
data.service.ts 800 B
Newer Older
import { HttpClient } from '@angular/common/http';
jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed
import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { throwError, Observable } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed
import { ConfigService } from './config.service';
import { Course } from './models/course';
jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed

@Injectable()
export class DataService {
	private plannerApiUrl: string;
pnogal's avatar
pnogal committed
	constructor(private http: HttpClient, private configService: ConfigService) {
		this.plannerApiUrl = this.configService.apiPlannerUrl;
jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed
	}
pnogal's avatar
pnogal committed

	getCourseData(): Observable<Course> {
		return this.http.get<Course>(this.plannerApiUrl + '/degreePlan/520224/courses')
			.pipe(catchError(this.errorHandler));
pnogal's avatar
pnogal committed
	}

	private errorHandler(error: Response) {
		return throwError(error || 'Server Error');
	}

jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed
}