added core services: entry, tmdb, toggle
This commit is contained in:
1 parent
08959c46b1
commit
daa948b9b9
4 files changed
+152
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, map } from 'rxjs';
|
||||
import { Entry } from '../../shared/models/entry.model';
|
||||
import { EntryId } from '../../shared/models/entryId.model';
|
||||
import { EntryRating } from '../../shared/models/entryRating.model';
|
||||
// import { environment } from '../../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class EntryService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
// private apiUrl = environment.apiBaseUrl;
|
||||
private baseUrl = 'http://localhost:4000/api/v1';
|
||||
|
||||
addEntry(tmdb_id: string): Observable<Entry> {
|
||||
return this.http.post<Entry>(`${this.baseUrl}/entries`, { tmdb_id: tmdb_id });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, map } from 'rxjs';
|
||||
import { Entry } from '../../shared/models/entry.model';
|
||||
import { EntryId } from '../../shared/models/entryId.model';
|
||||
import { EntryRating } from '../../shared/models/entryRating.model';
|
||||
// import { environment } from '../../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class TmdbService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
// private apiUrl = environment.apiBaseUrl;
|
||||
private tmdb_apiUrl = ' https://api.themoviedb.org/3';
|
||||
private tmdb_apiKey = '5323ef3dc430df54dcb9e58c37fd22bb';
|
||||
|
||||
fetchdata(endPoint: string): Observable<any> {
|
||||
return this.http.get<{ results: any[] }>(endPoint);
|
||||
}
|
||||
|
||||
getPopularMovies(page: number, isMovie: boolean): Observable<Entry[]> {
|
||||
var type = isMovie ? 'movie' : 'tv';
|
||||
var endPoint = `${this.tmdb_apiUrl}/${type}/popular?page=${page}&api_key=${this.tmdb_apiKey}&language=en-US`;
|
||||
console.log(endPoint);
|
||||
return this.fetchdata(endPoint)
|
||||
.pipe(
|
||||
map((response) =>
|
||||
response.results.map((movie: any) =>
|
||||
this.adaptMovieToEntry(movie, isMovie)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
getTrendingMovies(page: number, isMovie: boolean): Observable<Entry[]> {
|
||||
var type = isMovie ? 'movie' : 'tv';
|
||||
var endPoint = `${this.tmdb_apiUrl}/trending/${type}/day?api_key=${this.tmdb_apiKey}&language=en-US`;
|
||||
console.log(endPoint);
|
||||
return this.fetchdata(endPoint)
|
||||
.pipe(
|
||||
map((response) =>
|
||||
response.results.map((movie: any) =>
|
||||
this.adaptMovieToEntry(movie, isMovie)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private adaptMovieToEntry(movie: any, isMovie: boolean): Entry {
|
||||
const entryId = {
|
||||
tmdb_id: movie.id,
|
||||
} as EntryId;
|
||||
const entryRating = {
|
||||
tmdb_rating: movie.vote_average,
|
||||
} as EntryRating;
|
||||
|
||||
return {
|
||||
entryId: entryId,
|
||||
entryRating: entryRating,
|
||||
|
||||
title: movie.title,
|
||||
original_title: movie.original_title,
|
||||
release_date: movie.release_date,
|
||||
|
||||
storyline: movie.storyline,
|
||||
|
||||
watchlist: false,
|
||||
favorit: false,
|
||||
hidden: false,
|
||||
|
||||
is_tvseries: isMovie,
|
||||
status: movie.status,
|
||||
|
||||
poster_path: movie.poster_path,
|
||||
} as Entry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ToggleService {
|
||||
isToggeled: boolean = false;
|
||||
isHovered: boolean = false;
|
||||
|
||||
constructor() {}
|
||||
|
||||
toggleSidebar() {
|
||||
if (this.isToggeled) {
|
||||
document.body.classList.remove('toggled');
|
||||
this.isToggeled = false;
|
||||
} else {
|
||||
document.body.classList.add('toggled');
|
||||
this.isToggeled = true;
|
||||
}
|
||||
// document.body.classList.toggle('toggled');
|
||||
}
|
||||
|
||||
hoverSidebar(isHovering: boolean) {
|
||||
if (isHovering) {
|
||||
document.body.classList.add('sidebar-hovered');
|
||||
isHovering = true;
|
||||
} else {
|
||||
document.body.classList.remove('sidebar-hovered');
|
||||
isHovering = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user