import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { Course } from '../model/course' ; import { Observable } from 'rxjs' ; import { map , shareReplay } from 'rxjs/operators' ; import { Lesson } from '../model/lesson' ; @ Injectable ( { providedIn : 'root' } ) export class CoursesService { constructor ( private http ) { } loadCourseById ( courseId ) { return this . http . get < Course > ( `/api/courses/${ courseId }` ) . pipe ( shareReplay ( ) ) ; } loadAllCourseLessons ( courseId ) { return this . http . get < Lesson [ ] > ( '/api/lessons' , { params : { pageSize : "10000" , courseId : courseId . toString ( ) } } ) . pipe ( map ( res => res [ "payload" ] ) , shareReplay ( ) ) ; } loadAllCourses ( ) { return this . http . get < Course [ ] > ( "/api/courses" ) . pipe ( map ( res => res [ "payload" ] ) , shareReplay ( ) ) ; } saveCourse ( courseId , changes ) { return this . http . put ( `/api/courses/${ courseId }` , changes ) . pipe ( shareReplay ( ) ) ; } searchLessons ( search ) { return this . http . get < Lesson [ ] > ( '/api/lessons' , { params : { filter : search , pageSize : "100" } } ) . pipe ( map ( res => res [ "payload" ] ) , shareReplay ( ) ) ; } }