-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Currency entity; added Swagger
- Loading branch information
Showing
13 changed files
with
183 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS (SELECT 1 FROM pg_database WHERE datname = 'curex-db') THEN | ||
CREATE DATABASE "curex-db"; | ||
END IF; | ||
END $$; | ||
|
||
CREATE TABLE currency ( | ||
id serial PRIMARY KEY, | ||
code character varying(3) UNIQUE NOT NULL, | ||
title character varying(50) NOT NULL | ||
); | ||
|
||
INSERT INTO currency (code, title) VALUES | ||
('USD', 'United States Dollar'), | ||
('EUR', 'Euro'), | ||
('AUD', 'Australian Dollar'), | ||
('UAH', 'Ukrainian Hryvnia'), | ||
('CAD', 'Canadian Dollar'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Get, HttpCode, | ||
Post, | ||
Query, | ||
UploadedFile, | ||
UseInterceptors, | ||
} from '@nestjs/common'; | ||
import { ApiBody, ApiConsumes, ApiQuery, ApiTags } from '@nestjs/swagger'; | ||
import { FileInterceptor } from '@nestjs/platform-express'; | ||
import { Express } from 'express'; | ||
|
||
import { fileUploadOptions } from '../config'; | ||
import { DbImportService } from './db-import.service'; | ||
import { FileUploadDto, ImportResponseDto } from './io.dto'; | ||
|
||
@ApiTags('import') | ||
@Controller('db') | ||
export class DbController { | ||
constructor(private readonly dbImportService: DbImportService) {} | ||
|
||
@Get('import') | ||
async import(@Query('filename') fileName?: string) { | ||
@ApiQuery({ name: 'filename', required: false }) | ||
async import( | ||
@Query('filename') fileName?: string, | ||
): Promise<ImportResponseDto> { | ||
return this.dbImportService.importFileFromDiskToDb(fileName); | ||
} | ||
|
||
@Post('import-file') | ||
@HttpCode(200) | ||
@UseInterceptors(FileInterceptor('file', fileUploadOptions)) | ||
async handleFileImport(@UploadedFile() file: Express.Multer.File) { | ||
@ApiConsumes('multipart/form-data') | ||
@ApiBody({ | ||
description: 'File to import', | ||
type: FileUploadDto, | ||
}) | ||
async handleFileImport( | ||
@UploadedFile() file: Express.Multer.File, | ||
): Promise<ImportResponseDto> { | ||
return this.dbImportService.uploadFileToDb(file.buffer.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.