docs: add comments to functions for better understanding
This commit is contained in:
parent
9cd395b16e
commit
5417ac0636
5 changed files with 80 additions and 0 deletions
|
|
@ -21,20 +21,46 @@ export class MovieService {
|
|||
private authService: AuthService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Fetch all movies available on the server
|
||||
*
|
||||
* @returns a promise resolving to an array of movie objects
|
||||
*/
|
||||
getAllMovies(): Promise<any> {
|
||||
return firstValueFrom(this.apiService.get('/video/', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a movie by its video URL
|
||||
*
|
||||
* @param videoUrl the ID of the movie to fetch
|
||||
* @returns a promise resolving to the movie object
|
||||
*/
|
||||
getMovieFiles(videoUrl: number): Promise<any> {
|
||||
return firstValueFrom(this.apiService.get(`/${videoUrl}`, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a movie to the server
|
||||
*
|
||||
* @param formData the FormData object representing the movie to upload
|
||||
* @returns a promise resolved when the upload is successful
|
||||
*/
|
||||
uploadMovie(formData: FormData): Promise<any> {
|
||||
return firstValueFrom(
|
||||
this.apiService.post('/video/upload/', formData, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a movie with the given video ID has been uploaded in the following resolutions: 360p, 720p, 1080p.
|
||||
*
|
||||
* @param videoID the ID of the movie to check
|
||||
* @returns an observable that emits an object with the following properties:
|
||||
* - '360': a boolean indicating whether the movie has been uploaded in 360p resolution
|
||||
* - '720': a boolean indicating whether the movie has been uploaded in 720p resolution
|
||||
* - '1080': a boolean indicating whether the movie has been uploaded in 1080p resolution
|
||||
*/
|
||||
isMovieResolutionUploaded(
|
||||
videoID: number
|
||||
): Observable<{ [resolution: string]: boolean }> {
|
||||
|
|
|
|||
|
|
@ -9,12 +9,24 @@ export class TokenService {
|
|||
|
||||
constructor(private router: Router) {}
|
||||
|
||||
/**
|
||||
* Store the given authentication token in either local or session storage.
|
||||
*
|
||||
* @param token The authentication token to store.
|
||||
* @param storage Whether to store the token in local storage (true) or session storage (false).
|
||||
*/
|
||||
setToken(token: string, storage: boolean): void {
|
||||
storage
|
||||
? localStorage.setItem(this.TOKEN_KEY, token)
|
||||
: sessionStorage.setItem(this.TOKEN_KEY, token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authentication token if it exists in either local or session storage.
|
||||
* Note that session storage takes precedence over local storage.
|
||||
*
|
||||
* @returns The authentication token if found, or null otherwise.
|
||||
*/
|
||||
getToken(): string | null {
|
||||
const tokenFromSession = sessionStorage.getItem(this.TOKEN_KEY);
|
||||
if (tokenFromSession) {
|
||||
|
|
@ -25,11 +37,18 @@ export class TokenService {
|
|||
return tokenFromLocal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the authentication token from both local and session storage.
|
||||
* Note that this does not navigate the user away from the current page.
|
||||
*/
|
||||
removeToken(): void {
|
||||
localStorage.removeItem(this.TOKEN_KEY);
|
||||
sessionStorage.removeItem(this.TOKEN_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the session by removing the token from storage and navigating to the home route.
|
||||
*/
|
||||
clearSession(): void {
|
||||
this.removeToken();
|
||||
this.router.navigate(['/']);
|
||||
|
|
|
|||
|
|
@ -10,12 +10,25 @@ export class UserService {
|
|||
|
||||
constructor(private apiService: ApiService) {}
|
||||
|
||||
/**
|
||||
* Fetch the list of movies liked and watched by the current user
|
||||
*
|
||||
* @returns a promise resolving to an object with two properties:
|
||||
* - `liked_movies`: a list of movie IDs liked by the current user
|
||||
* - `watched_movies`: a list of movie IDs watched by the current user
|
||||
*/
|
||||
getLikedAndWatchedMovies(): Promise<any> {
|
||||
return firstValueFrom(
|
||||
this.apiService.get(`/users/${this.currentUserId}/`, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the list of liked movies for the current user
|
||||
*
|
||||
* @param likedMovies a list of movie IDs liked by the current user
|
||||
* @returns a promise resolved when the update is successful
|
||||
*/
|
||||
updateLikedMovies(likedMovies: any): Promise<any> {
|
||||
return firstValueFrom(
|
||||
this.apiService.put(
|
||||
|
|
|
|||
|
|
@ -13,16 +13,29 @@ export class ErrorToastComponent implements OnInit {
|
|||
|
||||
constructor(private errorService: ErrorService) {}
|
||||
|
||||
/**
|
||||
* Listens to the errorText$ observable and updates the component's errorText
|
||||
* property with the latest error message.
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
this.errorService.errorText$.subscribe((message: string) => {
|
||||
this.errorText = message;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the propagation of an event to prevent the component from closing
|
||||
* when the user clicks on the error message.
|
||||
* @param event The MouseEvent to stop propagating.
|
||||
*/
|
||||
stopPropagation(event: MouseEvent) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the current error message from the error service when the user clicks
|
||||
* anywhere outside the error toast.
|
||||
*/
|
||||
closeError() {
|
||||
this.errorService.clearError();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,19 @@ export class HeaderComponent {
|
|||
private tokenService: TokenService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Emits the moviesChange event with the newMovies array as the payload.
|
||||
* This is used to reset the movies displayed in the movie-list component.
|
||||
* @param newMovies The new array of movies to be displayed.
|
||||
*/
|
||||
backToOverview(newMovies: any[]) {
|
||||
this.moviesChange.emit(newMovies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out the user by calling the logout method of AuthService and clears the session using TokenService.
|
||||
* If an error occurs during the process, it is logged to the console.
|
||||
*/
|
||||
async logout() {
|
||||
try {
|
||||
await this.authService.logout();
|
||||
|
|
|
|||
Loading…
Reference in a new issue