From 30d8c49f709b7d750989c4adc8f1d215e68414fd Mon Sep 17 00:00:00 2001 From: FunixG Date: Mon, 15 Jul 2024 21:20:05 +0200 Subject: [PATCH 1/2] added vote lib V1 --- package.json | 2 +- .../funixproductions-requests/package.json | 2 +- .../pacifista-api/web/vote/dtos/VoteDTO.ts | 14 +++ .../web/vote/dtos/VoteWebsiteDTO.ts | 6 ++ .../web/vote/dtos/VotesCountDTO.ts | 4 + .../web/vote/services/VoteService.ts | 91 +++++++++++++++++++ .../src/public-api.ts | 7 +- 7 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteDTO.ts create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteWebsiteDTO.ts create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VotesCountDTO.ts create mode 100644 projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/services/VoteService.ts diff --git a/package.json b/package.json index 454f3c8..5ece89b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@funixproductions/angular-core", - "version": "0.2.3", + "version": "0.2.4", "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 be74afc..c0973d4 100644 --- a/projects/funixproductions-requests/package.json +++ b/projects/funixproductions-requests/package.json @@ -1,6 +1,6 @@ { "name": "@funixproductions/funixproductions-requests", - "version": "0.2.3", + "version": "0.2.4", "description": "Package used in all FunixProductions Angular projects", "peerDependencies": { "@angular/common": "^17.1.0", diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteDTO.ts new file mode 100644 index 0000000..5777714 --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteDTO.ts @@ -0,0 +1,14 @@ +import {ApiDTO} from "../../../../core/dtos/api-dto"; + +export class VoteDTO extends ApiDTO { + username: string; + voteWebsite: string; + voteValidationDate?: Date; + nextVoteDate?: Date; + + constructor(username: string, voteWebsite: string) { + super(); + this.username = username; + this.voteWebsite = voteWebsite; + } +} diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteWebsiteDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteWebsiteDTO.ts new file mode 100644 index 0000000..7fe602a --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteWebsiteDTO.ts @@ -0,0 +1,6 @@ +export class VoteWebsiteDTO { + enumName: string; + displayName: string; + urlVote: string; + coolDownInMinutes: number; +} diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VotesCountDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VotesCountDTO.ts new file mode 100644 index 0000000..99e0aa8 --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VotesCountDTO.ts @@ -0,0 +1,4 @@ +export class VotesCountDTO { + username: string; + votesCount: number; +} \ No newline at end of file diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/services/VoteService.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/services/VoteService.ts new file mode 100644 index 0000000..cada1da --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/services/VoteService.ts @@ -0,0 +1,91 @@ +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 {catchError, Observable, throwError} from "rxjs"; +import {Paginated} from "../../../../core/dtos/paginated"; +import {VoteDTO} from "../dtos/VoteDTO"; +import {VotesCountDTO} from "../dtos/VotesCountDTO"; +import {VoteWebsiteDTO} from "../dtos/VoteWebsiteDTO"; + +export class VoteService extends FunixprodHttpClient { + + private readonly domain: string; + private readonly path: string = 'web/vote'; + private readonly http: HttpClient; + + constructor(httpClient: HttpClient, productionEnv: boolean) { + super(); + this.http = httpClient; + + if (productionEnv) { + this.domain = environment.pacifistaApiUrl; + } else { + this.domain = environmentDev.pacifistaApiUrl; + } + } + + public getAll(page: number, username?: string, month?: number, year?: number): Observable> { + return this.http.get>(this.domain + this.path, { + headers: super.getHeaders(), + params: { + page: page.toString(), + username: username ?? "", + month: month?.toString() ?? "", + year: year?.toString() ?? "" + } + }).pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public getTopVoters(month: number, year: number): Observable { + return this.http.get(this.domain + this.path + "/check", { + headers: super.getHeaders(), + params: { + month: month.toString(), + year: year.toString() + } + }).pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public getVoteWebsites(): Observable { + return this.http.get(this.domain + this.path + "/websites", { + headers: super.getHeaders() + }).pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public checkVote(voteWebsite: string): Observable { + return this.http.get(this.domain + this.path + "/user/" + voteWebsite, { + headers: super.getHeaders() + }).pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + + public makeVote(voteWebsite: string, username: string): Observable { + return this.http.post(this.domain + this.path + "/user/" + voteWebsite, {}, { + headers: super.getHeaders(), + params: { + username: username + } + }).pipe( + catchError((error: HttpErrorResponse) => { + return throwError(() => this.buildErrorDto(error)); + }) + ); + } + +} \ No newline at end of file diff --git a/projects/funixproductions-requests/src/public-api.ts b/projects/funixproductions-requests/src/public-api.ts index d665fb6..91fefb5 100644 --- a/projects/funixproductions-requests/src/public-api.ts +++ b/projects/funixproductions-requests/src/public-api.ts @@ -83,4 +83,9 @@ export * from './lib/services/pacifista-api/server/players/data/service/Pacifist export * from './lib/services/pacifista-api/server/players/data/service/PacifistaPlayerChatMessagesService'; export * from './lib/services/pacifista-api/web/user/dtos/PacifistaWebUserLinkDTO'; -export * from './lib/services/pacifista-api/web/user/services/PacifistaWebUserLinkService'; \ No newline at end of file +export * from './lib/services/pacifista-api/web/user/services/PacifistaWebUserLinkService'; + +export * from './lib/services/pacifista-api/web/vote/dtos/VoteDTO'; +export * from './lib/services/pacifista-api/web/vote/dtos/VoteWebsiteDTO'; +export * from './lib/services/pacifista-api/web/vote/dtos/VotesCountDTO'; +export * from './lib/services/pacifista-api/web/vote/services/VoteService'; \ No newline at end of file From 9e157a4f3e618a95e744a23430f257bfea7dd9fd Mon Sep 17 00:00:00 2001 From: FunixG Date: Mon, 15 Jul 2024 21:28:34 +0200 Subject: [PATCH 2/2] fix build --- .../services/pacifista-api/web/vote/dtos/VoteWebsiteDTO.ts | 7 +++++++ .../services/pacifista-api/web/vote/dtos/VotesCountDTO.ts | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteWebsiteDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteWebsiteDTO.ts index 7fe602a..151ddeb 100644 --- a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteWebsiteDTO.ts +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteWebsiteDTO.ts @@ -3,4 +3,11 @@ export class VoteWebsiteDTO { displayName: string; urlVote: string; coolDownInMinutes: number; + + constructor(enumName: string, displayName: string, urlVote: string, coolDownInMinutes: number) { + this.enumName = enumName; + this.displayName = displayName; + this.urlVote = urlVote; + this.coolDownInMinutes = coolDownInMinutes; + } } diff --git a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VotesCountDTO.ts b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VotesCountDTO.ts index 99e0aa8..51a3e05 100644 --- a/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VotesCountDTO.ts +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VotesCountDTO.ts @@ -1,4 +1,9 @@ export class VotesCountDTO { username: string; votesCount: number; + + constructor(username: string, votesCount: number) { + this.username = username; + this.votesCount = votesCount; + } } \ No newline at end of file