Files
library/apps/frontend/src/app/services/comments.service.ts
T

114 lines
4.4 KiB
TypeScript

/**
* @copyright 2026 NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ApiService } from './api.service';
import { Comment, CreateCommentDto } from '@library/shared-types';
@Injectable({
providedIn: 'root'
})
export class CommentsService {
constructor(private api: ApiService) {}
getCommentsForGame(gameId: string): Observable<Comment[]> {
return this.api.get<Comment[]>(`/games/${gameId}/comments`);
}
getCommentsForBook(bookId: string): Observable<Comment[]> {
return this.api.get<Comment[]>(`/books/${bookId}/comments`);
}
getCommentsForMusic(musicId: string): Observable<Comment[]> {
return this.api.get<Comment[]>(`/music/${musicId}/comments`);
}
addCommentToGame(gameId: string, comment: CreateCommentDto): Observable<Comment> {
return this.api.post<Comment>(`/games/${gameId}/comments`, comment);
}
addCommentToBook(bookId: string, comment: CreateCommentDto): Observable<Comment> {
return this.api.post<Comment>(`/books/${bookId}/comments`, comment);
}
addCommentToMusic(musicId: string, comment: CreateCommentDto): Observable<Comment> {
return this.api.post<Comment>(`/music/${musicId}/comments`, comment);
}
deleteCommentFromGame(gameId: string, commentId: string): Observable<{ success: boolean }> {
return this.api.delete<{ success: boolean }>(`/games/${gameId}/comments/${commentId}`);
}
deleteCommentFromBook(bookId: string, commentId: string): Observable<{ success: boolean }> {
return this.api.delete<{ success: boolean }>(`/books/${bookId}/comments/${commentId}`);
}
deleteCommentFromMusic(musicId: string, commentId: string): Observable<{ success: boolean }> {
return this.api.delete<{ success: boolean }>(`/music/${musicId}/comments/${commentId}`);
}
getCommentsForArt(artId: string): Observable<Comment[]> {
return this.api.get<Comment[]>(`/art/${artId}/comments`);
}
addCommentToArt(artId: string, comment: CreateCommentDto): Observable<Comment> {
return this.api.post<Comment>(`/art/${artId}/comments`, comment);
}
deleteCommentFromArt(artId: string, commentId: string): Observable<{ success: boolean }> {
return this.api.delete<{ success: boolean }>(`/art/${artId}/comments/${commentId}`);
}
getCommentsForShow(showId: string): Observable<Comment[]> {
return this.api.get<Comment[]>(`/shows/${showId}/comments`);
}
addCommentToShow(showId: string, comment: CreateCommentDto): Observable<Comment> {
return this.api.post<Comment>(`/shows/${showId}/comments`, comment);
}
deleteCommentFromShow(showId: string, commentId: string): Observable<{ success: boolean }> {
return this.api.delete<{ success: boolean }>(`/shows/${showId}/comments/${commentId}`);
}
getCommentsForManga(mangaId: string): Observable<Comment[]> {
return this.api.get<Comment[]>(`/manga/${mangaId}/comments`);
}
addCommentToManga(mangaId: string, comment: CreateCommentDto): Observable<Comment> {
return this.api.post<Comment>(`/manga/${mangaId}/comments`, comment);
}
deleteCommentFromManga(mangaId: string, commentId: string): Observable<{ success: boolean }> {
return this.api.delete<{ success: boolean }>(`/manga/${mangaId}/comments/${commentId}`);
}
updateCommentOnGame(gameId: string, commentId: string, content: string): Observable<Comment> {
return this.api.put<Comment>(`/games/${gameId}/comments/${commentId}`, { content });
}
updateCommentOnBook(bookId: string, commentId: string, content: string): Observable<Comment> {
return this.api.put<Comment>(`/books/${bookId}/comments/${commentId}`, { content });
}
updateCommentOnMusic(musicId: string, commentId: string, content: string): Observable<Comment> {
return this.api.put<Comment>(`/music/${musicId}/comments/${commentId}`, { content });
}
updateCommentOnArt(artId: string, commentId: string, content: string): Observable<Comment> {
return this.api.put<Comment>(`/art/${artId}/comments/${commentId}`, { content });
}
updateCommentOnShow(showId: string, commentId: string, content: string): Observable<Comment> {
return this.api.put<Comment>(`/shows/${showId}/comments/${commentId}`, { content });
}
updateCommentOnManga(mangaId: string, commentId: string, content: string): Observable<Comment> {
return this.api.put<Comment>(`/manga/${mangaId}/comments/${commentId}`, { content });
}
}