Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: service methods for platform file api endpoints #2893

Merged
merged 8 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/app/core/services/platform/v1/approver/file.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { TestBed } from '@angular/core/testing';
import { ApproverFileService } from './file.service';
import { ApproverPlatformApiService } from '../../../approver-platform-api.service';

describe('ApproverFileService', () => {
let service: ApproverFileService;
let approverPlatformApiService: jasmine.SpyObj<ApproverPlatformApiService>;

beforeEach(() => {
const approverPlatformApiServiceSpy = jasmine.createSpyObj('ApproverPlatformApiService', ['get', 'post']);
TestBed.configureTestingModule({
providers: [
{
provide: ApproverPlatformApiService,
useValue: approverPlatformApiServiceSpy,
},
],
});
service = TestBed.inject(ApproverFileService);
approverPlatformApiService = TestBed.inject(
ApproverPlatformApiService
) as jasmine.SpyObj<ApproverPlatformApiService>;
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
48 changes: 48 additions & 0 deletions src/app/core/services/platform/v1/approver/file.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Injectable } from '@angular/core';
import { Observable, map } from 'rxjs';
import { PlatformFileGenerateUrlsResponse } from 'src/app/core/models/platform/platform-file-generate-urls-response.model';
import { PlatformFilePostRequestPayload } from 'src/app/core/models/platform/platform-file-post-request-payload.model';
import { PlatformFile } from 'src/app/core/models/platform/platform-file.model';
import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-response.model';
import { ApproverPlatformApiService } from '../../../approver-platform-api.service';

@Injectable({
providedIn: 'root',
})
export class ApproverFileService {
constructor(private approverPlatformApiService: ApproverPlatformApiService) {}

createFile(payload: PlatformFilePostRequestPayload): Observable<PlatformFile> {
return this.approverPlatformApiService
.post<PlatformApiResponse<PlatformFile>>('/files', payload)
.pipe(map((response) => response.data));
}

createFilesBulk(payload: PlatformFilePostRequestPayload[]): Observable<PlatformFile[]> {
return this.approverPlatformApiService
.post<PlatformApiResponse<PlatformFile[]>>('/files/bulk', payload)
.pipe(map((response) => response.data));
}

generateUrls(id: string): Observable<PlatformFileGenerateUrlsResponse> {
const payload = {
data: { id },
};
return this.approverPlatformApiService
.post<PlatformApiResponse<PlatformFileGenerateUrlsResponse>>('/files/generate_urls', payload)
.pipe(map((response) => response.data));
}

generateUrlsBulk(fileIds: string[]): Observable<PlatformFileGenerateUrlsResponse[]> {
const payload = {
data: fileIds.map((id) => ({ id })),
};
return this.approverPlatformApiService
.post<PlatformApiResponse<PlatformFileGenerateUrlsResponse[]>>('/files/generate_urls/bulk', payload)
.pipe(map((response) => response.data));
}

downloadFile(id: string): {} {
return this.approverPlatformApiService.get('/files/download?id=' + id);
}
}
28 changes: 28 additions & 0 deletions src/app/core/services/platform/v1/spender/file.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { TestBed } from '@angular/core/testing';
import { SpenderFileService } from './file.service';
import { SpenderPlatformV1ApiService } from '../../../spender-platform-v1-api.service';

describe('SpenderFileService', () => {
let service: SpenderFileService;
let spenderPlatformV1ApiService: jasmine.SpyObj<SpenderPlatformV1ApiService>;

beforeEach(() => {
const spenderPlatformV1ApiServiceSpy = jasmine.createSpyObj('SpenderPlatformV1ApiService', ['get', 'post']);
TestBed.configureTestingModule({
providers: [
{
provide: SpenderPlatformV1ApiService,
useValue: spenderPlatformV1ApiServiceSpy,
},
],
});
service = TestBed.inject(SpenderFileService);
spenderPlatformV1ApiService = TestBed.inject(
SpenderPlatformV1ApiService
) as jasmine.SpyObj<SpenderPlatformV1ApiService>;
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
48 changes: 48 additions & 0 deletions src/app/core/services/platform/v1/spender/file.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Injectable } from '@angular/core';
import { Observable, map } from 'rxjs';
import { PlatformFileGenerateUrlsResponse } from 'src/app/core/models/platform/platform-file-generate-urls-response.model';
import { PlatformFilePostRequestPayload } from 'src/app/core/models/platform/platform-file-post-request-payload.model';
import { PlatformFile } from 'src/app/core/models/platform/platform-file.model';
import { SpenderPlatformV1ApiService } from '../../../spender-platform-v1-api.service';
import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-response.model';

@Injectable({
providedIn: 'root',
})
export class SpenderFileService {
constructor(private spenderPlatformV1ApiService: SpenderPlatformV1ApiService) {}

createFile(payload: PlatformFilePostRequestPayload): Observable<PlatformFile> {
return this.spenderPlatformV1ApiService
.post<PlatformApiResponse<PlatformFile>>('/files', payload)
.pipe(map((response) => response.data));
}

createFilesBulk(payload: PlatformFilePostRequestPayload[]): Observable<PlatformFile[]> {
return this.spenderPlatformV1ApiService
.post<PlatformApiResponse<PlatformFile[]>>('/files/bulk', payload)
.pipe(map((response) => response.data));
}

generateUrls(id: string): Observable<PlatformFileGenerateUrlsResponse> {
const payload = {
data: { id },
};
return this.spenderPlatformV1ApiService
.post<PlatformApiResponse<PlatformFileGenerateUrlsResponse>>('/files/generate_urls', payload)
.pipe(map((response) => response.data));
}

generateUrlsBulk(fileIds: string[]): Observable<PlatformFileGenerateUrlsResponse[]> {
const payload = {
data: fileIds.map((id) => ({ id })),
};
return this.spenderPlatformV1ApiService
.post<PlatformApiResponse<PlatformFileGenerateUrlsResponse[]>>('/files/generate_urls/bulk', payload)
.pipe(map((response) => response.data));
}

downloadFile(id: string): {} {
return this.spenderPlatformV1ApiService.get('/files/download?id=' + id);
}
}
Loading