updated library service and removed unused functions

This commit is contained in:
X4Lo committed 2024-04-28 00:22:46 +01:00
1 parent e03e887f76
commit 62056bdc98
1 file changed
+34 -44
@@ -15,9 +15,13 @@ export class LibraryService implements OnInit {
private libraryEntriesSubject = new ReplaySubject<Entry[]>(1); private libraryEntriesSubject = new ReplaySubject<Entry[]>(1);
private entriesLoaded = false; // Flag to track if the entries have been loaded private entriesLoaded = false; // Flag to track if the entries have been loaded
private backend_apiUrl = ' http://localhost:4000/api/v1';
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
ngOnInit() {} ngOnInit() {
this.fetchAllEntries(true);
}
public getAllEntries(forceFetch: boolean = false): Observable<Entry[]> { public getAllEntries(forceFetch: boolean = false): Observable<Entry[]> {
if (this.entriesLoaded && !forceFetch) { if (this.entriesLoaded && !forceFetch) {
@@ -28,12 +32,11 @@ export class LibraryService implements OnInit {
} }
} }
public refreshEntries(forceFetch: boolean = true): Observable<Entry[]> { // public refreshEntries(forceFetch: boolean = true): Observable<Entry[]> {
return this.getAllEntries(forceFetch); // return this.getAllEntries(forceFetch);
} // }
// private apiUrl = environment.apiBaseUrl; // private apiUrl = environment.apiBaseUrl;
private backend_apiUrl = ' http://localhost:4000/api/v1';
/** /**
* Fetches data from the specified endpoint and returns an Observable. * Fetches data from the specified endpoint and returns an Observable.
@@ -81,48 +84,35 @@ export class LibraryService implements OnInit {
} }
} }
/** // /**
* Fetches all library and returns an Observable. // * Fetches library data with page and pagesize and returns an Observable.
* @returns {Observable<Entry[]>} An Observable that emits the fetched data. // * @param {string} endPoint The URL of the API endpoint to fetch data from.
*/ // * @param {Object} params Optional query parameters to append to the request URL.
// fetchAllEntries(): Observable<Entry[]> { // * @returns {Observable<Entry[]>} An Observable that emits the fetched data.
// */
// getEntries(page: number, pageSize: number): Observable<Entry[]> {
// var endPoint = `${this.backend_apiUrl}/entries`; // var endPoint = `${this.backend_apiUrl}/entries`;
// return this.fetchData(endPoint).pipe( // return this.fetchData(endPoint, { page: page, pageSize: pageSize }).pipe(
// map((response) => { // map((response) =>
// return response.map((movie: any) => this.adaptMovieToEntry(movie)); // response.results.map((movie: any) => this.mapMovieToEntry(movie))
// }) // )
// ); // );
// } // }
/** // /**
* Fetches library data with page and pagesize and returns an Observable. // * Retrieves a specific page of entries from the library.
* @param {string} endPoint The URL of the API endpoint to fetch data from. // *
* @param {Object} params Optional query parameters to append to the request URL. // * @param page The page number to retrieve.
* @returns {Observable<Entry[]>} An Observable that emits the fetched data. // * @param pageSize Defines the number of entries on each page.
*/ // * @returns An Observable emitting the requested page of entries.
getEntries(page: number, pageSize: number): Observable<Entry[]> { // */
var endPoint = `${this.backend_apiUrl}/entries`; // getEntriesUsingEndPoint(endPoint: string): Observable<Entry[]> {
return this.fetchData(endPoint, { page: page, pageSize: pageSize }).pipe( // return this.fetchData(endPoint).pipe(
map((response) => // map((response) =>
response.results.map((movie: any) => this.adaptMovieToEntry(movie)) // response.results.map((movie: any) => this.mapMovieToEntry(movie))
) // )
); // );
} // }
/**
* Retrieves a specific page of entries from the library.
*
* @param page The page number to retrieve.
* @param pageSize Defines the number of entries on each page.
* @returns An Observable emitting the requested page of entries.
*/
getEntriesUsingEndPoint(endPoint: string): Observable<Entry[]> {
return this.fetchData(endPoint).pipe(
map((response) =>
response.results.map((movie: any) => this.adaptMovieToEntry(movie))
)
);
}
addEntry(tmdb_id: string, is_tvserie: boolean): Observable<Entry | null> { addEntry(tmdb_id: string, is_tvserie: boolean): Observable<Entry | null> {
return this.getAllEntries().pipe( return this.getAllEntries().pipe(
@@ -165,7 +155,7 @@ export class LibraryService implements OnInit {
); );
} }
private adaptMovieToEntry(movie: any): Entry { private mapMovieToEntry(movie: any): Entry {
const entryId = { const entryId = {
tmdb_id: movie.entryId.tmdb_id, tmdb_id: movie.entryId.tmdb_id,
} as EntryId; } as EntryId;