71 lines
1.8 KiB
TypeScript
71 lines
1.8 KiB
TypeScript
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<EpisodeSeen>(
|
|
`${this.backend_apiUrl}/${this.apiAction}`,
|
|
{
|
|
entry_id: entryId,
|
|
episode_id: episodeId,
|
|
date_seen: dateSeen,
|
|
seen_with: seenWith,
|
|
}
|
|
);
|
|
}
|
|
|
|
getEpisodeSeenByEntryId(entryId: number) {
|
|
return this.http.get<any[]>(
|
|
`${this.backend_apiUrl}/${this.apiAction}/by-entry/${entryId}`
|
|
);
|
|
}
|
|
|
|
getEpisodeSeenBySeasonId(entryId: number) {
|
|
return this.http.get<any[]>(
|
|
`${this.backend_apiUrl}/${this.apiAction}/by-season/${entryId}`
|
|
);
|
|
}
|
|
|
|
// get episode-seen by episode Id
|
|
getEpisodeSeenById(id: number) {
|
|
return this.http.get<EpisodeSeen[]>(
|
|
`${this.backend_apiUrl}/${this.apiAction}/${id}`
|
|
);
|
|
}
|
|
|
|
updateEpisodeSeen(episodeSeen: EpisodeSeenDto) {
|
|
return this.http.put<any>(
|
|
`${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<any>(
|
|
`${this.backend_apiUrl}/${this.apiAction}/${id}`
|
|
);
|
|
}
|
|
}
|