diff --git a/backend/user_app/views.py b/backend/user_app/views.py index 8f0c271..35fb086 100644 --- a/backend/user_app/views.py +++ b/backend/user_app/views.py @@ -7,7 +7,7 @@ from .models import CustomUser @api_view(['GET', 'POST']) @permission_classes([IsAuthenticated]) -def user_list(request): +def users_list(request): if request.method == 'GET': user = CustomUser.objects.all() @@ -23,7 +23,7 @@ def user_list(request): @api_view(['GET', 'PUT', 'DELETE']) @permission_classes([IsAuthenticated]) -def user_detail(request, id): +def user_video_preferences(request, id): try: user = CustomUser.objects.get(pk=id) @@ -47,7 +47,7 @@ def user_detail(request, id): @api_view(['PUT']) @permission_classes([IsAuthenticated]) -def user_liked_detail(request, id): +def user_liked_videos(request, id): try: user = CustomUser.objects.get(pk=id) except CustomUser.DoesNotExist: @@ -62,7 +62,7 @@ def user_liked_detail(request, id): @api_view(['PUT']) @permission_classes([IsAuthenticated]) -def user_watched_detail(request, id): +def user_watched_videos(request, id): try: user = CustomUser.objects.get(pk=id) except CustomUser.DoesNotExist: diff --git a/backend/videoflix/urls.py b/backend/videoflix/urls.py index 0ece5c7..fbfbfba 100644 --- a/backend/videoflix/urls.py +++ b/backend/videoflix/urls.py @@ -28,11 +28,11 @@ urlpatterns = [ path('video/progress/', video_views.video_progress_view, name='video-progress'), # Users URLs - path('users/', user_views.user_list, name='user_list'), - path('users//', user_views.user_detail, name='user_detail'), - path('users/liked//', user_views.user_liked_detail, name='user_liked_detail'), - path('users/watched//', user_views.user_watched_detail, name='user_watched_detail'), - + path('users/', user_views.users_list, name='users_list'), + path('users//video-prefs/', user_views.user_video_preferences, name='user_video_preferences'), + path('users//liked/', user_views.user_liked_videos, name='user_favorite_videos'), + path('users//watched/', user_views.user_watched_videos, name='user_watched_videos'), + # Authentication URLs path('auth/', AuthView.as_view(), name='auth_view'), path('auth/login/', LoginView.as_view(), name='login'), diff --git a/frontend/src/app/components/home/home.component.ts b/frontend/src/app/components/home/home.component.ts index 315b13a..00545f2 100644 --- a/frontend/src/app/components/home/home.component.ts +++ b/frontend/src/app/components/home/home.component.ts @@ -101,7 +101,7 @@ export class HomeComponent implements OnInit { private async loadUserVideoPreferences(): Promise { try { const { liked_videos, watched_videos } = - await this.userService.getLikedAndWatchedVideos(); + await this.userService.getUserVideoPreferences(); this.favoriteVideos = liked_videos; this.watchedVideos = watched_videos; } catch (error) { diff --git a/frontend/src/app/services/api.service.ts b/frontend/src/app/services/api.service.ts index f1e0816..ea2b22a 100644 --- a/frontend/src/app/services/api.service.ts +++ b/frontend/src/app/services/api.service.ts @@ -46,16 +46,16 @@ export class ApiService { } /** - * Sends a POST request to the specified endpoint with a request body. + * Sends a POST request to the specified endpoint with upload event tracking. * - * @template T The expected type of the response. + * @template T The expected type of the final response body. * @param endpoint The API endpoint to send the request to. - * @param body The request payload to send. + * @param body The request payload (e.g., FormData for file upload). * @param auth Whether to include authentication headers. Defaults to false. - * @param options Additional options for the request. - * @returns An Observable of type HttpEvent. + * @param options Additional HTTP options (e.g., observe, reportProgress). + * @returns An Observable emitting HttpEvent objects. */ - postWithProgress( + postWithUploadEvents( endpoint: string, body: any, auth: boolean = false, diff --git a/frontend/src/app/services/user.service.ts b/frontend/src/app/services/user.service.ts index 744ef87..4e8039f 100644 --- a/frontend/src/app/services/user.service.ts +++ b/frontend/src/app/services/user.service.ts @@ -20,9 +20,9 @@ export class UserService { * - `liked_videos`: a list of video IDs liked by the current user * - `watched_videos`: a list of video IDs watched by the current user */ - getLikedAndWatchedVideos(): Promise { + getUserVideoPreferences(): Promise { return firstValueFrom( - this.apiService.get(`/users/${this.currentUserId}/`, true) + this.apiService.get(`/user/${this.currentUserId}/video-prefs/`, true) ); } @@ -35,7 +35,7 @@ export class UserService { updateLikedVideos(likedVideos: any): Promise { return firstValueFrom( this.apiService.put( - `/users/liked/${this.currentUserId}/`, + `/user/${this.currentUserId}/liked/`, likedVideos, true ) @@ -51,7 +51,7 @@ export class UserService { updateWatchedVideos(watchedVideos: any): Promise { return firstValueFrom( this.apiService.put( - `/users/watched/${this.currentUserId}/`, + `/user/${this.currentUserId}/watched/`, watchedVideos, true ) diff --git a/frontend/src/app/services/video.service.ts b/frontend/src/app/services/video.service.ts index 51cc242..14dd82f 100644 --- a/frontend/src/app/services/video.service.ts +++ b/frontend/src/app/services/video.service.ts @@ -4,6 +4,7 @@ import { ApiService } from './api.service'; import { AuthService } from './auth.service'; import { ResolutionService } from './resolution.service'; import { Video } from '../interfaces/video.interface'; +import { HttpEvent } from '@angular/common/http'; @Injectable({ providedIn: 'root', @@ -37,23 +38,13 @@ export class VideoService { } /** - * Fetch a video by its video URL + * Uploads a video file to the server with progress tracking. * - * @param videoUrl the ID of the video to fetch - * @returns a promise resolving to the video object + * @param formData The FormData object representing the video to upload. + * @returns An Observable emitting HttpEvent objects (e.g., progress, response). */ - getVideoFiles(videoUrl: number): Promise { - return firstValueFrom(this.apiService.get(`/${videoUrl}`, true)); - } - - /** - * Upload a video to the server - * - * @param formData the FormData object representing the video to upload - * @returns a promise resolved when the upload is successful - */ - uploadVideoWithProgress(formData: FormData): Observable { - return this.apiService.postWithProgress( + uploadVideoWithProgress(formData: FormData): Observable> { + return this.apiService.postWithUploadEvents( '/video/upload/', formData, true,