From 7e08f6379f5a91431cc30c2c3be280cfaff043cd Mon Sep 17 00:00:00 2001 From: Chneemann Date: Tue, 29 Apr 2025 04:04:51 +0200 Subject: [PATCH] refactor: rename MovieService to VideoService and remove 'movie' from backend URLs --- backend/videoflix/urls.py | 4 +- .../home/hero-banner/hero-banner.component.ts | 8 ++-- .../src/app/components/home/home.component.ts | 6 +-- .../upload-movie/upload-movie.component.ts | 6 +-- .../{movie.service.ts => video.service.ts} | 42 +++++++++---------- 5 files changed, 33 insertions(+), 33 deletions(-) rename frontend/src/app/services/{movie.service.ts => video.service.ts} (64%) diff --git a/backend/videoflix/urls.py b/backend/videoflix/urls.py index 694bfbb..f880856 100644 --- a/backend/videoflix/urls.py +++ b/backend/videoflix/urls.py @@ -21,9 +21,9 @@ urlpatterns = [ path('django-rq/', include('django_rq.urls')), # Content URLs - path('video/', video_views.video_list, name='video_list'), + path('videos/', video_views.video_list, name='video_list'), path('video/upload/', video_views.video_upload, name='video_upload'), - path('video/movie//', video_views.check_video_resolutions, name='check_video_resolutions'), + path('video//', video_views.check_video_resolutions, name='check_video_resolutions'), # Users URLs path('users/', user_views.user_list, name='user_list'), diff --git a/frontend/src/app/components/home/hero-banner/hero-banner.component.ts b/frontend/src/app/components/home/hero-banner/hero-banner.component.ts index 2dae029..407dfbc 100644 --- a/frontend/src/app/components/home/hero-banner/hero-banner.component.ts +++ b/frontend/src/app/components/home/hero-banner/hero-banner.component.ts @@ -10,7 +10,7 @@ import { ViewChild, } from '@angular/core'; import { BtnLargeComponent } from '../../../shared/components/buttons/btn-large/btn-large.component'; -import { MovieService } from '../../../services/movie.service'; +import { VideoService } from '../../../services/video.service'; import { environment } from '../../../../environments/environment'; import { BtnSmallComponent } from '../../../shared/components/buttons/btn-small/btn-small.component'; import { UserService } from '../../../services/user.service'; @@ -47,7 +47,7 @@ export class HeroBannerComponent implements OnChanges { movieIsUploaded: { [resolution: string]: boolean }; constructor( - private movieService: MovieService, + private videoService: VideoService, private resolutionService: ResolutionService, public userService: UserService ) { @@ -78,8 +78,8 @@ export class HeroBannerComponent implements OnChanges { if (changes['currentMovie'] && this.currentMovie.length > 0) { const movieId = this.currentMovie[0]?.id; if (movieId) { - this.movieService - .isMovieResolutionUploaded(movieId) + this.videoService + .isVideoResolutionUploaded(movieId) .subscribe((resolutions) => { this.movieIsUploaded = resolutions; this.movieIsUploadedChange.emit(this.movieIsUploaded); diff --git a/frontend/src/app/components/home/home.component.ts b/frontend/src/app/components/home/home.component.ts index d8934d0..8e7d31d 100644 --- a/frontend/src/app/components/home/home.component.ts +++ b/frontend/src/app/components/home/home.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { HeaderComponent } from '../../shared/components/header/header.component'; import { HeroBannerComponent } from './hero-banner/hero-banner.component'; import { CategoriesComponent } from './categories/categories.component'; -import { MovieService } from '../../services/movie.service'; +import { VideoService } from '../../services/video.service'; import { CommonModule } from '@angular/common'; import { VideoPlayerComponent } from './video-player/video-player.component'; import { BtnSmallComponent } from '../../shared/components/buttons/btn-small/btn-small.component'; @@ -40,7 +40,7 @@ export class HomeComponent implements OnInit { movieIsUploaded: { [resolution: string]: boolean }; constructor( - private movieService: MovieService, + private videoService: VideoService, public userService: UserService, private resolutionService: ResolutionService ) { @@ -113,7 +113,7 @@ export class HomeComponent implements OnInit { async loadAllMovies() { this.isLoading = true; try { - this.movies = await this.movieService.getAllMovies(); + this.movies = await this.videoService.getAllVideos(); } finally { this.isLoading = false; } diff --git a/frontend/src/app/components/home/upload-movie/upload-movie.component.ts b/frontend/src/app/components/home/upload-movie/upload-movie.component.ts index 130e752..d48c58f 100644 --- a/frontend/src/app/components/home/upload-movie/upload-movie.component.ts +++ b/frontend/src/app/components/home/upload-movie/upload-movie.component.ts @@ -3,7 +3,7 @@ import { Component, EventEmitter, Output } from '@angular/core'; import { FormsModule, NgForm } from '@angular/forms'; import { ErrorService } from '../../../services/error.service'; import { BtnLargeComponent } from '../../../shared/components/buttons/btn-large/btn-large.component'; -import { MovieService } from '../../../services/movie.service'; +import { VideoService } from '../../../services/video.service'; import { LoadingDialogComponent } from '../../../shared/components/loading-dialog/loading-dialog.component'; @Component({ @@ -33,7 +33,7 @@ export class UploadMovieComponent { constructor( public errorService: ErrorService, - private movieService: MovieService + private videoService: VideoService ) {} stopPropagation(event: MouseEvent) { @@ -74,7 +74,7 @@ export class UploadMovieComponent { try { this.movieData.send = true; let formData = this.createFormData(); - await this.movieService.uploadMovie(formData); + await this.videoService.uploadVideo(formData); ngForm.resetForm(); this.closeMovieUploadOverview(); this.movieData.send = false; diff --git a/frontend/src/app/services/movie.service.ts b/frontend/src/app/services/video.service.ts similarity index 64% rename from frontend/src/app/services/movie.service.ts rename to frontend/src/app/services/video.service.ts index 9e90e73..c77ae3c 100644 --- a/frontend/src/app/services/movie.service.ts +++ b/frontend/src/app/services/video.service.ts @@ -7,14 +7,14 @@ import { ResolutionService } from './resolution.service'; @Injectable({ providedIn: 'root', }) -export class MovieService { - private movieCache: { +export class VideoService { + private videoCache: { [key: number]: { [resolution: string]: boolean }; } = {}; private availableResolutions: string[]; /** - * Initializes the MovieService with ApiService, AuthService, and ResolutionService + * Initializes the VideoService with ApiService, AuthService, and ResolutionService * * It fetches the available resolutions from the ResolutionService and stores * them in the availableResolutions field. @@ -29,63 +29,63 @@ export class MovieService { } /** - * Fetch all movies available on the server + * Fetch all videos available on the server * - * @returns a promise resolving to an array of movie objects + * @returns a promise resolving to an array of video objects */ - getAllMovies(): Promise { - return firstValueFrom(this.apiService.get('/video/', true)); + getAllVideos(): Promise { + return firstValueFrom(this.apiService.get('/videos/', true)); } /** - * Fetch a movie by its video URL + * Fetch a video by its video URL * - * @param videoUrl the ID of the movie to fetch - * @returns a promise resolving to the movie object + * @param videoUrl the ID of the video to fetch + * @returns a promise resolving to the video object */ - getMovieFiles(videoUrl: number): Promise { + getVideoFiles(videoUrl: number): Promise { return firstValueFrom(this.apiService.get(`/${videoUrl}`, true)); } /** - * Upload a movie to the server + * Upload a video to the server * - * @param formData the FormData object representing the movie to upload + * @param formData the FormData object representing the video to upload * @returns a promise resolved when the upload is successful */ - uploadMovie(formData: FormData): Promise { + uploadVideo(formData: FormData): Promise { return firstValueFrom( this.apiService.post('/video/upload/', formData, true) ); } /** - * Check if a movie is available in all resolutions on the server. + * Check if a video is available in all resolutions on the server. * This method caches the result to avoid unnecessary requests. * - * @param videoID the ID of the movie to check + * @param videoID the ID of the video to check * @returns a promise resolving to an object with the available resolutions * as keys and booleans indicating the availability as values. */ - isMovieResolutionUploaded( + isVideoResolutionUploaded( videoID: number ): Observable<{ [resolution: string]: boolean }> { - const cachedResolutions = this.movieCache[videoID]; + const cachedResolutions = this.videoCache[videoID]; if (cachedResolutions && Object.values(cachedResolutions).every(Boolean)) { return of(cachedResolutions); } - return this.apiService.get(`/video/movie/${videoID}/`, true).pipe( + return this.apiService.get(`/video/${videoID}/`, true).pipe( map((res: any) => { const resolutions = Object.fromEntries( this.availableResolutions.map((r) => [r, !!res[r]]) ); - this.movieCache[videoID] = resolutions; + this.videoCache[videoID] = resolutions; return resolutions; }), catchError((error) => { - console.error('Failed to fetch movie resolutions', error); + console.error('Failed to fetch video resolutions', error); this.authService.logout(); return of( Object.fromEntries(this.availableResolutions.map((r) => [r, false]))