diff --git a/frontend/src/app/services/api/api.service.ts b/frontend/src/app/services/api/api.service.ts index 7df548b..be43906 100644 --- a/frontend/src/app/services/api/api.service.ts +++ b/frontend/src/app/services/api/api.service.ts @@ -78,6 +78,13 @@ export class ApiService { }); } + public async postEmpty( + type: ZodDtoStatic, + url: string, + ): AsyncFailable> { + return this.fetchSafeJson(type, url, { method: 'POST' }); + } + public async postForm( receiveType: ZodDtoStatic, url: string, diff --git a/frontend/src/app/services/api/apikeys.service.ts b/frontend/src/app/services/api/apikeys.service.ts new file mode 100644 index 0000000..3909889 --- /dev/null +++ b/frontend/src/app/services/api/apikeys.service.ts @@ -0,0 +1,68 @@ +import { Injectable } from '@angular/core'; +import { + ApiKeyCreateResponse, + ApiKeyDeleteRequest, + ApiKeyDeleteResponse, + ApiKeyInfoRequest, + ApiKeyInfoResponse, + ApiKeyListRequest, + ApiKeyListResponse +} from 'picsur-shared/dist/dto/api/apikeys.dto'; +import { EApiKey } from 'picsur-shared/dist/entities/apikey.entity'; +import { AsyncFailable, Open } from 'picsur-shared/dist/types'; +import { ApiService } from './api.service'; + +@Injectable({ + providedIn: 'root', +}) +export class ApiKeysService { + constructor(private readonly api: ApiService) {} + + public async getApiKeys( + count: number, + page: number, + userID?: string, + ): AsyncFailable { + const response = await this.api.post( + ApiKeyListRequest, + ApiKeyListResponse, + '/api/apikeys/list', + { + count, + page, + user_id: userID, + }, + ); + + return Open(response, 'results'); + } + + public async getApiKey(key: string): AsyncFailable { + return await this.api.post( + ApiKeyInfoRequest, + ApiKeyInfoResponse, + '/api/apikeys/info', + { + key, + }, + ); + } + + public async createApiKey(): AsyncFailable { + return await this.api.postEmpty( + ApiKeyCreateResponse, + '/api/apikeys/create', + ); + } + + public async deleteApiKey(key: string): AsyncFailable { + return await this.api.post( + ApiKeyDeleteRequest, + ApiKeyDeleteResponse, + '/api/apikeys/delete', + { + key, + }, + ); + } +}