F: implemented config service in other services

This commit is contained in:
X4Lo committed 2025-02-15 23:57:39 +01:00
1 parent 13f68fcac6
commit cfda451f71
16 files changed
+84 -103

No files matched your search

@@ -4,16 +4,18 @@ import { Observable } from 'rxjs';
import { Collection } from '../../shared/models/collection.model';
import { CollectionEntry } from '../../shared/models/collection-entry.model';
import { Entry } from '../../shared/models/entry.model';
import { environment } from '../../../environments/environment.prod';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class CollectionService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'collections';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
// get all collections
getCollections(): Observable<Collection[]> {
@@ -1,17 +1,19 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment.prod';
import { Observable } from 'rxjs';
import { Media } from '../../shared/models/media.model';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class CustomMediaService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'media';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
fetchCustomMedia(): Observable<Media[]> {
return this.http.get<Media[]>(`${this.backend_apiUrl}/${this.apiAction}`);
@@ -1,16 +1,18 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { EntryRating } from '../../shared/models/entry-rating.model';
import { environment } from '../../../environments/environment.prod';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class EntryRatingsService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'entry-ratings';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
updateEntryRatings(entryRatings: EntryRating) {
return this.http.put<EntryRating>(
@@ -1,16 +1,18 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { EntrySeen } from '../../shared/models/entry-seen.model';
import { environment } from '../../../environments/environment.prod';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class EntrySeenService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'entry-seen';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
createEntrySeen(entryId: string, dateSeen: Date, seenWith: string) {
return this.http.post<EntrySeen>(
@@ -45,5 +47,4 @@ export class EntrySeenService {
`${this.backend_apiUrl}/${this.apiAction}/${id}`
);
}
}
@@ -4,21 +4,19 @@ import { Observable, map } from 'rxjs';
import { Entry } from '../../shared/models/entry.model';
import { EntryId } from '../../shared/models/entryId.model';
import { EntryRating } from '../../shared/models/entry-rating.model';
import { environment } from '../../../environments/environment.prod';
import { Media } from '../../shared/models/media.model';
import { LibraryService } from './library.service';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class EntryService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'entries';
constructor(
private http: HttpClient,
private libraryService: LibraryService
) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
// get entries
getEntries(): Observable<Entry[]> {
@@ -2,16 +2,18 @@ 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';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class EpisodeSeenService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'episode-seen';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
createEpisodeSeen(
entryId: number,
@@ -59,5 +61,4 @@ export class EpisodeSeenService {
`${this.backend_apiUrl}/${this.apiAction}/${id}`
);
}
}
@@ -1,17 +1,19 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment.prod';
import { EpisodeDTO } from '../../shared/models/dtos/episode.dto';
import { Observable } from 'rxjs';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class EpisodeService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'episodes';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
getMonthEpisodes(
startDate: string,
@@ -1,17 +1,19 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment.prod';
import { SearchItem } from '../../shared/models/search-item.model';
import { Observable, of } from 'rxjs';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class HistoryService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'history';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
getSearchHistory(): Observable<SearchItem[]> {
return of([] as SearchItem[]);
@@ -2,16 +2,18 @@ import { Injectable } from '@angular/core';
import { MovieDateSeen } from '../../shared/models/dtos/movie-dateSeen.model';
import { HttpClient } from '@angular/common/http';
import { Entry } from '../../shared/models/entry.model';
import { environment } from '../../../environments/environment.prod';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class ImporterService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'entries';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
bulkAddEntries(values: any) {
return this.http.post<any[]>(
@@ -3,7 +3,7 @@ import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable, throwError, map, of, BehaviorSubject } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
import { Entry } from '../../shared/models/entry.model';
import { environment } from '../../../environments/environment.prod';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
@@ -14,13 +14,11 @@ export class LibraryService implements OnInit {
>([]);
public entries$: Observable<Entry[]> = this.entriesSubject.asObservable();
// private oldEntries: Entry[] = [];
// private entriesLoaded = false;
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'entries';
constructor(private http: HttpClient) {
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
this.fetchAllEntries().subscribe(() => {
console.log(
`Library Service: Loaded ${
@@ -119,9 +117,7 @@ export class LibraryService implements OnInit {
public setEntry(entry: Entry) {
const currentEntries = this.entriesSubject.getValue();
let updatedEntries = currentEntries.filter(
(e) => e.id != entry.id
);
let updatedEntries = currentEntries.filter((e) => e.id != entry.id);
updatedEntries.push(entry);
@@ -139,36 +135,4 @@ export class LibraryService implements OnInit {
})
);
}
// private mapMovieToEntry(movie: any): Entry {
// const entryId = {
// tmdb_id: movie.entryId.tmdb_id,
// } as EntryId;
// const entryRating = {
// tmdb_rating: movie.entryRating.tmdb_rating,
// } as EntryRating;
// var is_tvseries = movie.release_date == null ? true : false;
// var release_date = movie.release_date || movie.first_air_date;
// return {
// entryId: entryId,
// entryRating: entryRating,
// title: movie.title,
// original_title: movie.original_title,
// release_date: release_date,
// storyline: movie.storyline,
// watchlist: movie.storyline,
// favorit: false,
// hidden: false,
// is_tvseries: is_tvseries,
// status: movie.status,
// poster_path: movie.poster_path,
// } as Entry;
// }
}
@@ -1,16 +1,18 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment.prod';
import { MaintenanceResult } from '../../shared/models/maintenance-result.model';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class MaintenanceService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'maintenance';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
getOrphanFiles() {
return this.http.get<MaintenanceResult>(
@@ -1,19 +1,19 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment.prod';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class PingService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'ping';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
ping() {
return this.http.get<string>(
`${this.backend_apiUrl}/${this.apiAction}`
);
return this.http.get<string>(`${this.backend_apiUrl}/${this.apiAction}`);
}
}
@@ -2,16 +2,18 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Season } from '../../shared/models/season.model';
import { Episode } from '../../shared/models/episode.models';
import { environment } from '../../../environments/environment.prod';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class SeasonService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl ;
private apiAction = 'seasons';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
// get season by id
getSeasonById(id: number) {
@@ -1,16 +1,18 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment.prod';
import { Settings } from '../../shared/models/settings.model';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class SettingsService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'settings';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
getSettings() {
return this.http.get<Settings>(`${this.backend_apiUrl}/${this.apiAction}`);
@@ -1,15 +1,17 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment.prod';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class StatisticsService {
private backend_apiUrl = environment.API_URL;
private backend_apiUrl;
private apiAction = 'statistics';
constructor(private http: HttpClient) {}
constructor(private http: HttpClient, private configService: ConfigService) {
this.backend_apiUrl = this.configService.getBackendApiUrl();
}
fetchYearlyWatchCount(year: number) {
return this.http.get<any>(
@@ -28,5 +30,4 @@ export class StatisticsService {
`${this.backend_apiUrl}/${this.apiAction}/watch-time/year/${year}`
);
}
}
+8 -10
View File
@@ -4,23 +4,21 @@ import { Observable, filter, from, map, of, switchMap, toArray } from 'rxjs';
import { Entry } from '../../shared/models/entry.model';
import { EntryId } from '../../shared/models/entryId.model';
import { EntryRating } from '../../shared/models/entry-rating.model';
import { environment } from '../../../environments/environment.prod';
import { LibraryService } from './library.service';
import { ConfigService } from './config.service';
@Injectable({
providedIn: 'root',
})
export class TmdbService {
private tmdb_apiUrl;
private tmdb_apiKey;
cach: Record<string, Entry[]> = {};
constructor(
private http: HttpClient,
private libraryService: LibraryService
) {}
// private apiUrl = environment.apiBaseUrl;
private tmdb_apiUrl = environment.TMDB_API_URL;
private tmdb_apiKey = environment.TMDB_API_KEY;
constructor(private http: HttpClient, private configService: ConfigService) {
this.tmdb_apiUrl = this.configService.getTmdbApiUrl();
this.tmdb_apiKey = this.configService.getTmdbApiKey();
}
fetchdata(endPoint: string): Observable<any> {
if (this.cach[endPoint]) {