64 lines
1.6 KiB
TypeScript
64 lines
1.6 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 { environment } from '../../../environments/environment.prod';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class EpisodeSeenService {
|
|
private backend_apiUrl = environment.API_URL;
|
|
private apiAction = 'episode-seen';
|
|
|
|
constructor(private http: HttpClient) {}
|
|
|
|
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}`
|
|
);
|
|
}
|
|
|
|
// 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}`
|
|
);
|
|
}
|
|
|
|
}
|