created the entry service
This commit is contained in:
1 parent
19ff25dfbc
commit
38682b68da
1 file changed
+73
@@ -10,4 +10,77 @@ import { EntryRating } from '../../shared/models/entryRating.model';
|
|||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class EntryService {
|
export class EntryService {
|
||||||
|
private backend_apiUrl = 'http://localhost:4000/api/v1';
|
||||||
|
private apiAction = 'entries';
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
// get entries
|
||||||
|
getEntries(): Observable<Entry[]> {
|
||||||
|
return this.http
|
||||||
|
.get<any>(`${this.backend_apiUrl}/${this.apiAction}`)
|
||||||
|
.pipe(map((response) => response.map((e: any) => this.mapToEntry(e))));
|
||||||
|
}
|
||||||
|
|
||||||
|
// get entry by id
|
||||||
|
getEntryById(entryId: string) {
|
||||||
|
return this.http.get<Entry>(
|
||||||
|
`${this.backend_apiUrl}/${this.apiAction}/${entryId}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update entry
|
||||||
|
updateEntryById(entry: Entry) {
|
||||||
|
return this.http.post<Entry>(`${this.backend_apiUrl}/${this.apiAction}`, {
|
||||||
|
entry,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// update entry
|
||||||
|
refrechEntryById(entryId: number) {
|
||||||
|
return this.http.put<Entry>(
|
||||||
|
`${this.backend_apiUrl}/${this.apiAction}/${entryId}`,
|
||||||
|
[null]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete entry
|
||||||
|
removeEntryById(entryId: string) {
|
||||||
|
return this.http.delete<Entry>(
|
||||||
|
`${this.backend_apiUrl}/${this.apiAction}/${entryId}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// mapper
|
||||||
|
private mapToEntry(data: any): Entry {
|
||||||
|
const entryId = {
|
||||||
|
tmdb_id: data.entryId.tmdb_id,
|
||||||
|
} as EntryId;
|
||||||
|
const entryRating = {
|
||||||
|
tmdb_rating: data.entryRating.tmdb_rating,
|
||||||
|
} as EntryRating;
|
||||||
|
|
||||||
|
var is_tvseries = data.release_date == null ? true : false;
|
||||||
|
var release_date = data.release_date || data.first_air_date;
|
||||||
|
|
||||||
|
return {
|
||||||
|
entryId: entryId,
|
||||||
|
entryRating: entryRating,
|
||||||
|
|
||||||
|
title: data.title,
|
||||||
|
original_title: data.original_title,
|
||||||
|
release_date: release_date,
|
||||||
|
|
||||||
|
storyline: data.storyline,
|
||||||
|
|
||||||
|
watchlist: data.storyline,
|
||||||
|
favorit: false,
|
||||||
|
hidden: false,
|
||||||
|
|
||||||
|
is_tvseries: is_tvseries,
|
||||||
|
status: data.status,
|
||||||
|
|
||||||
|
poster_path: data.poster_path,
|
||||||
|
} as Entry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user