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..151ddeb --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VoteWebsiteDTO.ts @@ -0,0 +1,13 @@ +export class VoteWebsiteDTO { + enumName: string; + 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 new file mode 100644 index 0000000..51a3e05 --- /dev/null +++ b/projects/funixproductions-requests/src/lib/services/pacifista-api/web/vote/dtos/VotesCountDTO.ts @@ -0,0 +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 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