From c609528eebc917143f854c166266f3b96afb4296 Mon Sep 17 00:00:00 2001 From: Antoine PRONNIER Date: Thu, 21 Nov 2024 01:07:31 +0100 Subject: [PATCH 1/6] WIP: Refacto news service --- .../web/news/dtos/PacifistaNewsDTO.ts | 22 ----- .../web/news/dtos/PacifistaNewsUserDataDTO.ts | 28 ++++++ .../web/news/dtos/ban/PacifistaNewsBanDTO.ts | 40 +++++++++ .../dtos/comments/PacifistaNewsCommentDTO.ts | 29 ++++++ .../comments/PacifistaNewsCommentLikeDTO.ts | 17 ++++ .../web/news/dtos/news/PacifistaNewsDTO.ts | 88 +++++++++++++++++++ .../news/dtos/news/PacifistaNewsImageDTO.ts | 21 +++++ .../news/dtos/news/PacifistaNewsLikeDTO.ts | 8 ++ .../news/services/PacifistaNewsBanClient.ts | 3 + .../services/PacifistaNewsCommentClient.ts | 3 + .../web/news/services/PacifistaNewsService.ts | 2 +- .../src/public-api.ts | 10 ++- 12 files changed, 247 insertions(+), 24 deletions(-) delete mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/PacifistaNewsDTO.ts create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/PacifistaNewsUserDataDTO.ts create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/ban/PacifistaNewsBanDTO.ts create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/comments/PacifistaNewsCommentDTO.ts create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/comments/PacifistaNewsCommentLikeDTO.ts create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsDTO.ts create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsImageDTO.ts create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsLikeDTO.ts create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsBanClient.ts create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsCommentClient.ts diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/PacifistaNewsDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/PacifistaNewsDTO.ts deleted file mode 100644 index 98d62c0..0000000 --- a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/PacifistaNewsDTO.ts +++ /dev/null @@ -1,22 +0,0 @@ -import {ApiDTO} from "../../../../core/dtos/api-dto"; - -export class PacifistaNewsDTO extends ApiDTO { - originalWriter?: string; - - updateWriter?: string; - - name?: string; - - title?: string; - - subtitle?: string; - - articleImageUrl?: string; - - body?: string; - - likesAmount?: number; - - commentsAmount?: number; - -} diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/PacifistaNewsUserDataDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/PacifistaNewsUserDataDTO.ts new file mode 100644 index 0000000..e5e00a5 --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/PacifistaNewsUserDataDTO.ts @@ -0,0 +1,28 @@ +import {ApiDTO} from "../../../../core/dtos/api-dto"; +import {PacifistaNewsDTO} from "./news/PacifistaNewsDTO"; + +export abstract class PacifistaNewsUserDataDTO extends ApiDTO { + + /** + * La news à laquelle ce commentaire répond + */ + news: PacifistaNewsDTO + + /** + * Nom d'utilisateur Minecraft du joueur + */ + minecraftUsername: string + + /** + * UUID du compte ID sur la funixproductions api + */ + funixProdUserId: string + + protected constructor(news: PacifistaNewsDTO) { + super(); + this.news = news; + this.minecraftUsername = ""; + this.funixProdUserId = ""; + } + +} \ No newline at end of file diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/ban/PacifistaNewsBanDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/ban/PacifistaNewsBanDTO.ts new file mode 100644 index 0000000..a434ab1 --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/ban/PacifistaNewsBanDTO.ts @@ -0,0 +1,40 @@ +import {ApiDTO} from "../../../../../core/dtos/api-dto"; + +export class PacifistaNewsBanDTO extends ApiDTO { + + /** + * La raison du ban + */ + reason?: string + + /** + * Nom d'utilisateur Minecraft du joueur banni + */ + minecraftUserNameBanned: string + + /** + * Le UUID du compte + */ + funixProdUserIdBanned: string + + /** + * Pseudo Minecraft de la personne qui sanctionne le joueur + */ + staffMinecraftUserName: string + + /** + * UUID funix prod account + */ + staffFunixProdUserId: string + + constructor(funixProdUserIdBanned: string, minecraftUserNameBanned: string, reason?: string) { + super(); + this.minecraftUserNameBanned = minecraftUserNameBanned; + this.funixProdUserIdBanned = funixProdUserIdBanned; + this.reason = reason; + + this.staffFunixProdUserId = ''; + this.staffMinecraftUserName = ''; + } + +} \ No newline at end of file diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/comments/PacifistaNewsCommentDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/comments/PacifistaNewsCommentDTO.ts new file mode 100644 index 0000000..60a04ab --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/comments/PacifistaNewsCommentDTO.ts @@ -0,0 +1,29 @@ +import {PacifistaNewsUserDataDTO} from "../PacifistaNewsUserDataDTO"; +import {PacifistaNewsDTO} from "../news/PacifistaNewsDTO"; + +export class PacifistaNewsCommentDTO extends PacifistaNewsUserDataDTO { + + /** + * Commentaire parent + */ + parent?: PacifistaNewsCommentDTO + + /** + * Contenu du commentaire en texte plein, pas de HTML + */ + content: string + + /** + * Nombre de likes sur ce commentaire + */ + likes: number + + constructor(news: PacifistaNewsDTO, content: string, parent?: PacifistaNewsCommentDTO) { + super(news); + this.content = content; + this.parent = parent; + + this.likes = 0; + } + +} \ No newline at end of file diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/comments/PacifistaNewsCommentLikeDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/comments/PacifistaNewsCommentLikeDTO.ts new file mode 100644 index 0000000..5f1a8f3 --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/comments/PacifistaNewsCommentLikeDTO.ts @@ -0,0 +1,17 @@ +import {PacifistaNewsUserDataDTO} from "../PacifistaNewsUserDataDTO"; +import {PacifistaNewsDTO} from "../news/PacifistaNewsDTO"; +import {PacifistaNewsCommentDTO} from "./PacifistaNewsCommentDTO"; + +export class PacifistaNewsCommentLikeDTO extends PacifistaNewsUserDataDTO { + + /** + * Le commentaire de la news qui a été liké + */ + comment: PacifistaNewsCommentDTO + + constructor(news: PacifistaNewsDTO, comment: PacifistaNewsCommentDTO) { + super(news); + this.comment = comment; + } + +} diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsDTO.ts new file mode 100644 index 0000000..fcdcd41 --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsDTO.ts @@ -0,0 +1,88 @@ +import {ApiDTO} from "../../../../../core/dtos/api-dto"; + +export class PacifistaNewsDTO extends ApiDTO { + + /** + * Nom d'utilisateur Minecraft du rédacteur d'origine + */ + originalWriter: string + + /** + * Nom d'utilisateur Minecraft de la personne qui l'a modifié + */ + updateWriter: string + + /** + * Nom de l'article présent dans l'url + */ + name: string + + /** + * Nom de l'article sur la page + */ + title: string + + /** + * Sous titre de l'article + */ + subtitle: string + + /** + * Image id pour l'image en taille réelle + */ + articleImageId: string + + /** + * Image id pour l'image en taille résuite pour l'affichage par liste + */ + articleImageIdLowRes: string + + /** + * Le contenu HTML de l'article + */ + bodyHtml: string + + /** + * Le contenu MarkDown de l'article pour la modification + */ + bodyMarkdown: string + + /** + * Si la news est publiée ou pas + */ + draft: boolean + + /** + * Nombre de likes + */ + likes: number + + /** + * Nombre de commentaires + */ + comments: number + + /** + * Nombre de vues + */ + views: number + + constructor(name: string, title: string, subtitle: string, bodyHtml: string, bodyMarkdown: string, draft: boolean) { + super(); + this.name = name; + this.title = title; + this.subtitle = subtitle; + this.bodyHtml = bodyHtml; + this.bodyMarkdown = bodyMarkdown; + this.draft = draft; + + this.originalWriter = ''; + this.updateWriter = ''; + this.articleImageId = ''; + this.articleImageIdLowRes = ''; + this.likes = 0; + this.comments = 0; + this.views = 0; + } + +} diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsImageDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsImageDTO.ts new file mode 100644 index 0000000..3986e43 --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsImageDTO.ts @@ -0,0 +1,21 @@ +import {ApiDTO} from "../../../../../core/dtos/api-dto"; + +export class PacifistaNewsImageDTO extends ApiDTO { + + /** + * Image rattachée à la news + */ + newsUuid: string + + /** + * Image en basse résolution pour l'affichage par liste + */ + isLowResolution: boolean + + constructor(newsUuid: string, isLowResolution: boolean) { + super(); + this.newsUuid = newsUuid; + this.isLowResolution = isLowResolution; + } + +} \ No newline at end of file diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsLikeDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsLikeDTO.ts new file mode 100644 index 0000000..bc422cc --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsLikeDTO.ts @@ -0,0 +1,8 @@ +import {PacifistaNewsUserDataDTO} from "../PacifistaNewsUserDataDTO"; +import {PacifistaNewsDTO} from "./PacifistaNewsDTO"; + +export class PacifistaNewsLikeDTO extends PacifistaNewsUserDataDTO { + constructor(news: PacifistaNewsDTO) { + super(news); + } +} diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsBanClient.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsBanClient.ts new file mode 100644 index 0000000..6459e68 --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsBanClient.ts @@ -0,0 +1,3 @@ +export class PacifistaNewsBanClient { + +} diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsCommentClient.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsCommentClient.ts new file mode 100644 index 0000000..26b1c9f --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsCommentClient.ts @@ -0,0 +1,3 @@ +export class PacifistaNewsCommentClient { + +} diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsService.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsService.ts index 3d41759..6640ea8 100644 --- a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsService.ts +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsService.ts @@ -2,7 +2,7 @@ import {CrudHttpClient, RequestParams} from "../../../../core/components/request import {environment} from "../../../../../../environments/environment"; import {environmentDev} from "../../../../../../environments/environment-dev"; import {HttpClient, HttpErrorResponse, HttpHeaders} from "@angular/common/http"; -import {PacifistaNewsDTO} from "../dtos/PacifistaNewsDTO"; +import {PacifistaNewsDTO} from "../dtos/news/PacifistaNewsDTO"; import {PageOption, Paginated} from "../../../../core/dtos/paginated"; import {QueryBuilder} from "../../../../core/components/query.builder"; import {catchError, Observable, throwError} from "rxjs"; diff --git a/projects/funixproductions-requests/src/public-api.ts b/projects/funixproductions-requests/src/public-api.ts index 1ea2f90..57b73e0 100644 --- a/projects/funixproductions-requests/src/public-api.ts +++ b/projects/funixproductions-requests/src/public-api.ts @@ -65,8 +65,16 @@ export * from './lib/services/pacifista-api/support/tickets/service/PacifistaSup export * from './lib/services/pacifista-api/support/tickets/service/PacifistaSupportTicketMessageService'; export * from './lib/services/pacifista-api/support/tickets/service/PacifistaSupportTicketMessageWebsocketService'; -export * from './lib/services/pacifista-api/web/news/dtos/PacifistaNewsDTO'; +export * from './lib/services/pacifista-api/web/news/dtos/PacifistaNewsUserDataDTO' +export * from './lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsDTO'; +export * from './lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsLikeDTO' +export * from './lib/services/pacifista-api/web/news/dtos/news/PacifistaNewsImageDTO' +export * from './lib/services/pacifista-api/web/news/dtos/comments/PacifistaNewsCommentLikeDTO' +export * from './lib/services/pacifista-api/web/news/dtos/comments/PacifistaNewsCommentDTO' +export * from './lib/services/pacifista-api/web/news/dtos/ban/PacifistaNewsBanDTO' export * from './lib/services/pacifista-api/web/news/services/PacifistaNewsService'; +export * from './lib/services/pacifista-api/web/news/services/PacifistaNewsBanClient'; +export * from './lib/services/pacifista-api/web/news/services/PacifistaNewsCommentClient'; export * from './lib/services/pacifista-api/web/shop/articles/dtos/PacifistaShopArticleDTO'; export * from './lib/services/pacifista-api/web/shop/articles/services/PacifistaShopArticleService'; export * from './lib/services/pacifista-api/web/shop/categories/services/PacifistaShopCategoryService'; From ed09fb2eac92cf3c4216c2cb2570b2678b48ef69 Mon Sep 17 00:00:00 2001 From: Antoine PRONNIER Date: Thu, 21 Nov 2024 01:36:14 +0100 Subject: [PATCH 2/6] Done news service --- .../web/news/services/PacifistaNewsService.ts | 169 ++++++++++++++---- 1 file changed, 139 insertions(+), 30 deletions(-) diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsService.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsService.ts index 6640ea8..d1a8531 100644 --- a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsService.ts +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsService.ts @@ -1,40 +1,149 @@ -import {CrudHttpClient, RequestParams} from "../../../../core/components/requests/crud-http-client"; import {environment} from "../../../../../../environments/environment"; import {environmentDev} from "../../../../../../environments/environment-dev"; -import {HttpClient, HttpErrorResponse, HttpHeaders} from "@angular/common/http"; +import {HttpClient, HttpErrorResponse, HttpHeaders, HttpParams} from "@angular/common/http"; import {PacifistaNewsDTO} from "../dtos/news/PacifistaNewsDTO"; -import {PageOption, Paginated} from "../../../../core/dtos/paginated"; -import {QueryBuilder} from "../../../../core/components/query.builder"; +import {Paginated} from "../../../../core/dtos/paginated"; import {catchError, Observable, throwError} from "rxjs"; +import {FunixprodHttpClient} from "../../../../core/components/requests/funixprod-http-client"; +import {PacifistaNewsLikeDTO} from "../dtos/news/PacifistaNewsLikeDTO"; -export class PacifistaNewsService extends CrudHttpClient { - - constructor(protected httpClient: HttpClient, production: boolean) { - super( - httpClient, - production ? environment.pacifistaApiUrl : environmentDev.pacifistaApiUrl, - 'web/news' - ); - } - - override find(options: PageOption, queryBuilder: QueryBuilder): Observable> { - const params: RequestParams = { - page: options.page, - elemsPerPage: options.elemsPerPage || 10, - sort: options.sort!, - search: (queryBuilder === null ? '' : queryBuilder.get()) - }; - - return this.http.get>(this.domain + this.path, - { - params: {...params}, - headers: new HttpHeaders({ - 'Content-Type': 'application/json' - }) +export class PacifistaNewsService extends FunixprodHttpClient { + + private readonly domain: string; + private readonly path: string; + + constructor(protected http: HttpClient, production: boolean) { + super(); + this.domain = production ? environment.pacifistaApiUrl : environmentDev.pacifistaApiUrl; + this.path = 'web/news'; + } + + public getAllNews(page: number, authed: boolean = false): Observable> { + return this.http.get>(this.domain + this.path, + { + params: { + page: page, + }, + headers: this.getHeadersForGetRequest(authed) + }).pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public getNewsById(id: string, authed: boolean = false): Observable { + return this.http.get(this.domain + this.path + '/' + id, + { + headers: this.getHeadersForGetRequest(authed) + }).pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public createNews(request: PacifistaNewsDTO, file: File): Observable { + let formData = new FormData(); + formData.append('dto', new Blob([JSON.stringify(request)], {type: 'application/json'})); + formData.append('image', file); + + return this.http.post(this.domain + this.path, formData, {headers: this.getHeadersForMultiPartRequest()}) + .pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public updateNews(request: PacifistaNewsDTO, file?: File): Observable { + if (!file) { + return this.http.put(this.domain + this.path, request, {headers: this.getHeaders()}) + .pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } else { + let formData = new FormData(); + formData.append('dto', new Blob([JSON.stringify(request)], {type: 'application/json'})); + formData.append('image', file); + + return this.http.post(this.domain + this.path + '/file', formData, {headers: this.getHeadersForMultiPartRequest()}) + .pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + } + + public deleteNews(id: string): Observable { + const httpParams: HttpParams = new HttpParams().set('id', id); + + return this.http.delete(this.domain + this.path, { + params: httpParams, + headers: this.getHeaders() }).pipe( catchError((error: HttpErrorResponse) => { - return throwError(() => this.buildErrorDto(error)); + return throwError(() => this.buildErrorDto(error)); + }) + ) + } + + public getLikesOnNews(newsId: string, page: number, authed: boolean = false): Observable> { + return this.http.get>(this.domain + this.path + '/likes/' + newsId, + { + params: { + page: page, + }, + headers: this.getHeadersForGetRequest(authed) + }).pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); }) ); - } + } + + public likeNews(newsId: string): Observable { + return this.http.post(this.domain + this.path + '/like/' + newsId, null, {headers: this.getHeaders()}) + .pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public removeLikeFromNews(newsId: string): Observable { + return this.http.delete(this.domain + this.path + '/like/' + newsId, {headers: this.getHeaders()}) + .pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + private getHeadersForGetRequest(authed: boolean = false): HttpHeaders { + let bearerToken: string | null = authed ? localStorage.getItem(FunixprodHttpClient.accessTokenLocalStorageName) : null; + let headersToSend = new HttpHeaders({ + 'Content-Type': 'application/json' + }); + + if (bearerToken !== null) { + headersToSend = headersToSend.append(FunixprodHttpClient.headerAuth, FunixprodHttpClient.bearerPrefix + ' ' + bearerToken); + } + + return headersToSend; + } + + private getHeadersForMultiPartRequest(): HttpHeaders { + let headersToSend = new HttpHeaders(); + const bearerToken: string | null = localStorage.getItem(FunixprodHttpClient.accessTokenLocalStorageName); + + if (bearerToken !== null) { + headersToSend = headersToSend.append(FunixprodHttpClient.headerAuth, FunixprodHttpClient.bearerPrefix + ' ' + bearerToken); + } + + return headersToSend + } } From 4516923819901b1446d27ce480f466f5937a2bc4 Mon Sep 17 00:00:00 2001 From: Antoine PRONNIER Date: Thu, 21 Nov 2024 01:38:23 +0100 Subject: [PATCH 3/6] Done bans service --- .../web/news/services/PacifistaNewsBanClient.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsBanClient.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsBanClient.ts index 6459e68..3eebf7b 100644 --- a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsBanClient.ts +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsBanClient.ts @@ -1,3 +1,17 @@ -export class PacifistaNewsBanClient { +import {CrudHttpClient} from "../../../../core/components/requests/crud-http-client"; +import {PacifistaNewsBanDTO} from "../dtos/ban/PacifistaNewsBanDTO"; +import {HttpClient} from "@angular/common/http"; +import {environment} from "../../../../../../environments/environment"; +import {environmentDev} from "../../../../../../environments/environment-dev"; + +export class PacifistaNewsBanClient extends CrudHttpClient { + + constructor(http: HttpClient, production: boolean) { + super( + http, + production ? environment.pacifistaApiUrl : environmentDev.pacifistaApiUrl, + 'web/news/bans' + ); + } } From ab04cc0cb34e05abf628d1f056b887d2d8100900 Mon Sep 17 00:00:00 2001 From: Antoine PRONNIER Date: Thu, 21 Nov 2024 01:49:30 +0100 Subject: [PATCH 4/6] Done comments service --- .../services/PacifistaNewsCommentClient.ts | 126 +++++++++++++++++- .../web/news/services/PacifistaNewsService.ts | 8 +- 2 files changed, 129 insertions(+), 5 deletions(-) diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsCommentClient.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsCommentClient.ts index 26b1c9f..08a07de 100644 --- a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsCommentClient.ts +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsCommentClient.ts @@ -1,3 +1,127 @@ -export class PacifistaNewsCommentClient { +import {FunixprodHttpClient} from "../../../../core/components/requests/funixprod-http-client"; +import {HttpClient, HttpErrorResponse} from "@angular/common/http"; +import {environment} from "../../../../../../environments/environment"; +import {environmentDev} from "../../../../../../environments/environment-dev"; +import {PacifistaNewsService} from "./PacifistaNewsService"; +import {catchError, Observable, throwError} from "rxjs"; +import {PacifistaNewsCommentDTO} from "../dtos/comments/PacifistaNewsCommentDTO"; +import {Paginated} from "../../../../core/dtos/paginated"; +import {PacifistaNewsCommentLikeDTO} from "../dtos/comments/PacifistaNewsCommentLikeDTO"; + +export class PacifistaNewsCommentClient extends FunixprodHttpClient { + + private readonly domain: string; + private readonly path: string; + + constructor(protected http: HttpClient, production: boolean) { + super(); + this.domain = production ? environment.pacifistaApiUrl : environmentDev.pacifistaApiUrl; + this.path = 'web/news/comments'; + } + + public getCommentsByNewsId(newsId: string, page: number, authed: boolean = false): Observable> { + return this.http.get>(this.domain + this.path, + { + params: { + page: page, + newsId: newsId + }, + headers: PacifistaNewsService.getHeadersForGetRequest(authed) + }).pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public getRepliesByCommentId(commentId: string, page: number, authed: boolean = false): Observable> { + return this.http.get>(this.domain + this.path + '/replies', + { + params: { + page: page, + commentId: commentId + }, + headers: PacifistaNewsService.getHeadersForGetRequest(authed) + }).pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public getCommentsByUser(minecraftUsername: string, page: number, authed: boolean = false): Observable> { + return this.http.get>(this.domain + this.path + '/user', + { + params: { + page: page, + minecraftUsername: minecraftUsername + }, + headers: PacifistaNewsService.getHeadersForGetRequest(authed) + }).pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public createComment(request: PacifistaNewsCommentDTO): Observable { + return this.http.post(this.domain + this.path, request, {headers: this.getHeaders()}) + .pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public updateComment(commentId: string, content: string): Observable { + return this.http.patch(this.domain + this.path + '/' + commentId, content, {headers: this.getHeaders()}) + .pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public deleteComment(commentId: string): Observable { + return this.http.delete(this.domain + this.path + '/' + commentId, {headers: this.getHeaders()}) + .pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public getLikesOnComment(commentId: string, page: number, authed: boolean = false): Observable> { + return this.http.get>(this.domain + this.path + '/likes', + { + params: { + page: page, + commentId: commentId + }, + headers: PacifistaNewsService.getHeadersForGetRequest(authed) + }).pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public likeComment(commentId: string): Observable { + return this.http.post(this.domain + this.path + '/like/' + commentId, null, {headers: this.getHeaders()}) + .pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public removeLikeFromComment(commentId: string): Observable { + return this.http.delete(this.domain + this.path + '/like/' + commentId, {headers: this.getHeaders()}) + .pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } } diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsService.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsService.ts index d1a8531..b2a7ac4 100644 --- a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsService.ts +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/news/services/PacifistaNewsService.ts @@ -24,7 +24,7 @@ export class PacifistaNewsService extends FunixprodHttpClient { params: { page: page, }, - headers: this.getHeadersForGetRequest(authed) + headers: PacifistaNewsService.getHeadersForGetRequest(authed) }).pipe( catchError((error: HttpErrorResponse) => { return throwError(() => this.buildErrorDto(error)); @@ -35,7 +35,7 @@ export class PacifistaNewsService extends FunixprodHttpClient { public getNewsById(id: string, authed: boolean = false): Observable { return this.http.get(this.domain + this.path + '/' + id, { - headers: this.getHeadersForGetRequest(authed) + headers: PacifistaNewsService.getHeadersForGetRequest(authed) }).pipe( catchError((error: HttpErrorResponse) => { return throwError(() => this.buildErrorDto(error)); @@ -97,7 +97,7 @@ export class PacifistaNewsService extends FunixprodHttpClient { params: { page: page, }, - headers: this.getHeadersForGetRequest(authed) + headers: PacifistaNewsService.getHeadersForGetRequest(authed) }).pipe( catchError((error: HttpErrorResponse) => { return throwError(() => this.buildErrorDto(error)); @@ -123,7 +123,7 @@ export class PacifistaNewsService extends FunixprodHttpClient { ); } - private getHeadersForGetRequest(authed: boolean = false): HttpHeaders { + static getHeadersForGetRequest(authed: boolean = false): HttpHeaders { let bearerToken: string | null = authed ? localStorage.getItem(FunixprodHttpClient.accessTokenLocalStorageName) : null; let headersToSend = new HttpHeaders({ 'Content-Type': 'application/json' From 317655da4f0457f5b94870814e322987dee10bd3 Mon Sep 17 00:00:00 2001 From: Antoine PRONNIER Date: Thu, 21 Nov 2024 01:50:22 +0100 Subject: [PATCH 5/6] clean code --- projects/funixproductions-requests/src/public-api.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/funixproductions-requests/src/public-api.ts b/projects/funixproductions-requests/src/public-api.ts index 57b73e0..1e5cb09 100644 --- a/projects/funixproductions-requests/src/public-api.ts +++ b/projects/funixproductions-requests/src/public-api.ts @@ -75,6 +75,7 @@ export * from './lib/services/pacifista-api/web/news/dtos/ban/PacifistaNewsBanDT export * from './lib/services/pacifista-api/web/news/services/PacifistaNewsService'; export * from './lib/services/pacifista-api/web/news/services/PacifistaNewsBanClient'; export * from './lib/services/pacifista-api/web/news/services/PacifistaNewsCommentClient'; + export * from './lib/services/pacifista-api/web/shop/articles/dtos/PacifistaShopArticleDTO'; export * from './lib/services/pacifista-api/web/shop/articles/services/PacifistaShopArticleService'; export * from './lib/services/pacifista-api/web/shop/categories/services/PacifistaShopCategoryService'; From 0d3b915d08301d9100bdafd3b542f46ba76c5f22 Mon Sep 17 00:00:00 2001 From: Antoine PRONNIER Date: Thu, 21 Nov 2024 01:50:54 +0100 Subject: [PATCH 6/6] 0.3.0 - Refacto news --- package.json | 2 +- projects/funixproductions-requests/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4a9194a..1ff85e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@funixproductions/angular-core", - "version": "0.2.12", + "version": "0.3.0", "description": "Package used in all FunixProductions Angular projects", "scripts": { "ng": "ng", diff --git a/projects/funixproductions-requests/package.json b/projects/funixproductions-requests/package.json index eeaf75c..cfe3e68 100644 --- a/projects/funixproductions-requests/package.json +++ b/projects/funixproductions-requests/package.json @@ -1,6 +1,6 @@ { "name": "@funixproductions/funixproductions-requests", - "version": "0.2.12", + "version": "0.3.0", "description": "Package used in all FunixProductions Angular projects", "peerDependencies": { "@angular/common": "^18.2.4",