import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { EpisodeSeen } from '../../shared/models/episode-seen.model'; import { EpisodeSeenDto } from '../../shared/models/dtos/episode-seen.dto'; import { ConfigService } from './config.service'; @Injectable({ providedIn: 'root', }) export class EpisodeSeenService { private backend_apiUrl; private apiAction = 'episode-seen'; constructor(private http: HttpClient, private configService: ConfigService) { this.backend_apiUrl = this.configService.getBackendApiUrl(); } createEpisodeSeen( entryId: number, episodeId: number, dateSeen: Date, seenWith: string ) { return this.http.post( `${this.backend_apiUrl}/${this.apiAction}`, { entry_id: entryId, episode_id: episodeId, date_seen: dateSeen, seen_with: seenWith, } ); } getEpisodeSeenByEntryId(entryId: number) { return this.http.get( `${this.backend_apiUrl}/${this.apiAction}/by-entry/${entryId}` ); } getEpisodeSeenBySeasonId(entryId: number) { return this.http.get( `${this.backend_apiUrl}/${this.apiAction}/by-season/${entryId}` ); } // get episode-seen by episode Id getEpisodeSeenById(id: number) { return this.http.get( `${this.backend_apiUrl}/${this.apiAction}/${id}` ); } updateEpisodeSeen(episodeSeen: EpisodeSeenDto) { return this.http.put( `${this.backend_apiUrl}/${this.apiAction}/${episodeSeen.id}`, { date_seen: episodeSeen.date_seen, seen_with: episodeSeen.seen_with, episode_id: episodeSeen.episodeId, } ); } removeEpisodeSeen(id: number) { return this.http.delete( `${this.backend_apiUrl}/${this.apiAction}/${id}` ); } }