Skip to content

Commit

Permalink
Fix File Downloads
Browse files Browse the repository at this point in the history
* Fix file downloads for all public documents
  • Loading branch information
Daniel Haselhan committed Oct 10, 2023
1 parent dc0c229 commit 22f8101
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ <h3>ALC Review and Decision</h3>
</div>
<div>
<app-public-decisions [applicationDecisions]="applicationDecisions"></app-public-decisions>
<app-submission-documents [applicationDocuments]="applicationDocuments"></app-submission-documents>
<app-submission-documents
[applicationSubmission]="applicationSubmission"
[applicationDocuments]="applicationDocuments"
></app-submission-documents>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PublicDocumentDto } from '../../../../../services/public/public.dto';
import { PublicService } from '../../../../../services/public/public.service';

@Component({
selector: 'app-submission-documents',
selector: 'app-submission-documents[applicationSubmission]',
templateUrl: './submission-documents.component.html',
styleUrls: ['./submission-documents.component.scss'],
})
Expand All @@ -30,14 +30,14 @@ export class PublicSubmissionDocumentsComponent implements OnInit, OnDestroy {
}

async openFile(uuid: string) {
const res = await this.publicService.getApplicationOpenFileUrl(this.applicationSubmission.fileNumber, uuid);
const res = await this.publicService.getApplicationDownloadFileUrl(this.applicationSubmission.fileNumber, uuid);
if (res) {
window.open(res.url, '_blank');
}
}

async downloadFile(uuid: string) {
const res = await this.publicService.getApplicationOpenFileUrl(this.applicationSubmission.fileNumber, uuid);
const res = await this.publicService.getApplicationDownloadFileUrl(this.applicationSubmission.fileNumber, uuid);
if (res) {
const downloadLink = document.createElement('a');
downloadLink.href = res.url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ <h3>ALC Review and Decision</h3>
</div>
<div>
<app-public-decisions [decisions]="decisions"></app-public-decisions>
<app-submission-documents [documents]="documents"></app-submission-documents>
<app-submission-documents [submission]="submission" [documents]="documents"></app-submission-documents>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class PublicSubmissionDocumentsComponent implements OnInit, OnDestroy {
}

async downloadFile(uuid: string) {
const res = await this.publicService.getNoticeOfIntentOpenFileUrl(this.submission.fileNumber, uuid);
const res = await this.publicService.getNoticeOfIntentDownloadFileUrl(this.submission.fileNumber, uuid);
if (res) {
const downloadLink = document.createElement('a');
downloadLink.href = res.url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ const routes: Routes = [
MatAutocompleteModule,
MatTreeModule,
],
exports: [PublicAlcReviewComponent],
})
export class PublicNoticeOfIntentModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<h3>ALC Review and Decision</h3>
</div>
<div>
<app-submission-documents [documents]="documents"></app-submission-documents>
<app-submission-documents [submission]="submission" [documents]="documents"></app-submission-documents>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PublicDocumentDto } from '../../../../services/public/public.dto';
styleUrls: ['./alc-review.component.scss'],
})
export class PublicAlcReviewComponent {
@Input() submission!: PublicNotificationSubmissionDto;
@Input() documents!: PublicDocumentDto[];

constructor() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { Subject } from 'rxjs';
import { PublicNoticeOfIntentSubmissionDto } from '../../../../../services/public/public-notice-of-intent.dto';
import { PublicNotificationSubmissionDto } from '../../../../../services/public/public-notification.dto';
import { PublicDocumentDto } from '../../../../../services/public/public.dto';
import { PublicService } from '../../../../../services/public/public.service';

Expand All @@ -16,7 +16,7 @@ export class PublicSubmissionDocumentsComponent implements OnInit, OnDestroy {

displayedColumns: string[] = ['type', 'fileName', 'source', 'uploadedAt', 'actions'];
@Input() documents!: PublicDocumentDto[];
@Input() submission!: PublicNoticeOfIntentSubmissionDto;
@Input() submission!: PublicNotificationSubmissionDto;

@ViewChild(MatSort) sort!: MatSort;
dataSource: MatTableDataSource<PublicDocumentDto> = new MatTableDataSource<PublicDocumentDto>();
Expand All @@ -28,14 +28,14 @@ export class PublicSubmissionDocumentsComponent implements OnInit, OnDestroy {
}

async openFile(uuid: string) {
const res = await this.publicService.getNoticeOfIntentOpenFileUrl(this.submission.fileNumber, uuid);
const res = await this.publicService.getNotificationOpenFileUrl(this.submission.fileNumber, uuid);
if (res) {
window.open(res.url, '_blank');
}
}

async downloadFile(uuid: string) {
const res = await this.publicService.getNoticeOfIntentOpenFileUrl(this.submission.fileNumber, uuid);
const res = await this.publicService.getNotificationDownloadFileUrl(this.submission.fileNumber, uuid);
if (res) {
const downloadLink = document.createElement('a');
downloadLink.href = res.url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h3>Applicant Submission</h3>
</mat-tab>
<mat-tab label="ALC Review and Decision">
<div *ngIf="submission" class="content">
<app-public-alc-review [documents]="documents"></app-public-alc-review>
<app-public-alc-review [submission]="submission" [documents]="documents"></app-public-alc-review>
</div>
</mat-tab>
</mat-tab-group>
Expand Down
65 changes: 64 additions & 1 deletion portal-frontend/src/app/services/public/public.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,75 @@ describe('PublicService', () => {
expect(res).toBeDefined();
});

it('should call get for loading application files', async () => {
it('should call get for opening application files', async () => {
mockHttpClient.get.mockReturnValue(of({}));

const res = await service.getApplicationOpenFileUrl('fileId', 'documentUuid');

expect(mockHttpClient.get).toHaveBeenCalledTimes(1);
expect(res).toBeDefined();
});

it('should call get for download application files', async () => {
mockHttpClient.get.mockReturnValue(of({}));

const res = await service.getApplicationDownloadFileUrl('fileId', 'documentUuid');

expect(mockHttpClient.get).toHaveBeenCalledTimes(1);
expect(res).toBeDefined();
});

it('should call get for loading Notice of Intent', async () => {
mockHttpClient.get.mockReturnValue(of({}));

const res = await service.getNoticeOfIntent('fileId');

expect(mockHttpClient.get).toHaveBeenCalledTimes(1);
expect(res).toBeDefined();
});

it('should call get for opening Notice of Intent files', async () => {
mockHttpClient.get.mockReturnValue(of({}));

const res = await service.getNoticeOfIntentOpenFileUrl('fileId', 'documentUuid');

expect(mockHttpClient.get).toHaveBeenCalledTimes(1);
expect(res).toBeDefined();
});

it('should call get for download Notice of Intent files', async () => {
mockHttpClient.get.mockReturnValue(of({}));

const res = await service.getNoticeOfIntentDownloadFileUrl('fileId', 'documentUuid');

expect(mockHttpClient.get).toHaveBeenCalledTimes(1);
expect(res).toBeDefined();
});

it('should call get for loading Notification', async () => {
mockHttpClient.get.mockReturnValue(of({}));

const res = await service.getNotification('fileId');

expect(mockHttpClient.get).toHaveBeenCalledTimes(1);
expect(res).toBeDefined();
});

it('should call get for opening Notification files', async () => {
mockHttpClient.get.mockReturnValue(of({}));

const res = await service.getNotificationOpenFileUrl('fileId', 'documentUuid');

expect(mockHttpClient.get).toHaveBeenCalledTimes(1);
expect(res).toBeDefined();
});

it('should call get for download Notification files', async () => {
mockHttpClient.get.mockReturnValue(of({}));

const res = await service.getNotificationDownloadFileUrl('fileId', 'documentUuid');

expect(mockHttpClient.get).toHaveBeenCalledTimes(1);
expect(res).toBeDefined();
});
});
36 changes: 36 additions & 0 deletions portal-frontend/src/app/services/public/public.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ export class PublicService {
}
}

async getApplicationDownloadFileUrl(fileId: string, uuid: string) {
try {
return await firstValueFrom(
this.httpClient.get<{ url: string }>(`${this.serviceUrl}/application/${fileId}/${uuid}/download`)
);
} catch (e) {
console.error(e);
this.toastService.showErrorToast('Failed to load Application File, please try again later');
return undefined;
}
}

async getNoticeOfIntent(fileId: string) {
try {
return await firstValueFrom(
Expand All @@ -63,6 +75,18 @@ export class PublicService {
}
}

async getNoticeOfIntentDownloadFileUrl(fileId: string, uuid: string) {
try {
return await firstValueFrom(
this.httpClient.get<{ url: string }>(`${this.serviceUrl}/notice-of-intent/${fileId}/${uuid}/download`)
);
} catch (e) {
console.error(e);
this.toastService.showErrorToast('Failed to load Notice of Intent File, please try again later');
return undefined;
}
}

async getNotification(fileId: string) {
try {
return await firstValueFrom(
Expand All @@ -86,4 +110,16 @@ export class PublicService {
return undefined;
}
}

async getNotificationDownloadFileUrl(fileId: string, uuid: string) {
try {
return await firstValueFrom(
this.httpClient.get<{ url: string }>(`${this.serviceUrl}/notification/${fileId}/${uuid}/download`)
);
} catch (e) {
console.error(e);
this.toastService.showErrorToast('Failed to load Notification, please try again later');
return undefined;
}
}
}
42 changes: 6 additions & 36 deletions services/apps/alcs/src/portal/public/public.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,15 @@ export class PublicController {
@Param('fileId') fileId: string,
@Param('uuid') documentUuid: string,
) {
const url = await this.publicAppService.getDownloadUrl(documentUuid);

return {
url,
};
return await this.publicAppService.getDownloadUrl(documentUuid);
}

@Get('/application/:fileId/:uuid/open')
async getApplicationDocumentOpen(
@Param('fileId') fileId: string,
@Param('uuid') documentUuid: string,
) {
const url = await this.publicAppService.getInlineUrl(documentUuid);

return {
url,
};
return await this.publicAppService.getInlineUrl(documentUuid);
}

@Get('/notice-of-intent/:fileId')
Expand All @@ -52,27 +44,15 @@ export class PublicController {
@Param('fileId') fileId: string,
@Param('uuid') documentUuid: string,
) {
const url = await this.publicNoticeOfIntentService.getDownloadUrl(
documentUuid,
);

return {
url,
};
return await this.publicNoticeOfIntentService.getDownloadUrl(documentUuid);
}

@Get('/notice-of-intent/:fileId/:uuid/open')
async getNoticeOfIntentDocumentOpen(
@Param('fileId') fileId: string,
@Param('uuid') documentUuid: string,
) {
const url = await this.publicNoticeOfIntentService.getInlineUrl(
documentUuid,
);

return {
url,
};
return await this.publicNoticeOfIntentService.getInlineUrl(documentUuid);
}

@Get('/notification/:fileId')
Expand All @@ -85,24 +65,14 @@ export class PublicController {
@Param('fileId') fileId: string,
@Param('uuid') documentUuid: string,
) {
const url = await this.publicNotificationService.getDownloadUrl(
documentUuid,
);

return {
url,
};
return await this.publicNotificationService.getDownloadUrl(documentUuid);
}

@Get('/notification/:fileId/:uuid/open')
async getNotificationDocumentOpen(
@Param('fileId') fileId: string,
@Param('uuid') documentUuid: string,
) {
const url = await this.publicNotificationService.getInlineUrl(documentUuid);

return {
url,
};
return await this.publicNotificationService.getInlineUrl(documentUuid);
}
}

0 comments on commit 22f8101

Please sign in to comment.