- Copy
.sample.envinto.env. If you don't need no specific configuration you should be fine to go without any editing. - Run
docker-composeto create a PostgreSQL container. Make sure your5432port is not being used. If it is or you would like to use an existing PostgreSQL server - update the.envand either remap ports indocker-compose.ymlor create a database in your server accordingly - I've used node v.18 for this project and have no idea what's gonna happen with a different node version.
.nvmrcis in place. - Run
yarnto install dependencies - Run
yarn db migration:runto run migrations for the database. There's also a helpful shell script./db-re-create.shto recreate database structures from scratch any moment.
The database import will delete all records from all tables before inserting data from the dump.
To upload the dump file into the database using the command line interface do:
yarn cli LoadDumpWithFixedRatesCommand _pathToYourDumpFile_To upload the dump file into the database using the web interface:
- start the web server with
yarn start - the default web server port is 3000 and it can be changed in
.env - the swagger should be available at http://localhost:3000/api
- use the
POST /dump-loader/uploadendpoint to upload a dump and get it loaded it into the database. please selecttruefor thefixedRatesparameter
yarn cli ReportCommand _destinationPath_please use GET /reporting/report endpoint
Here is the implementation for the poor man's Abstract Syntax Tree Node capable of parsing lines of the dump in the current format. If the format changes are not dramatical and it is possible to stay within this approach it is possible to introduce another AstNode implementation descending from the same abstract ancestor class and make it possible to use that new file version updating the factory method accordingly. If structure changes are beyond this compatibility - that case should be considered separately. Probably more layers of implementation would get affected.
2. How the import system will change if data on exchange rates disappears from the file, and it will need to be received asynchronously (via API)?
I have changed your task a little bit. I've introduced a db entity to store that rates and it is possible to use it (requesting rates from the database still is asynchronous). There's no chance in real world you would be fetching those from API every time you need those. I've used a thirdparty API to get those rates. I've dumped a response I needed and mocked it, however, there's a really easy way to make it use real API.
To use the real API you can patch this place:
// replace this:
private readonly apilayerApi = new ApilayerApi();
// with this
private readonly apilayerApi = new ApilayerApi(false);Also, you would have to use an API key in .env for APILAYER_API_KEY parameter, here's mine free one: muLcN3qXtPQFSXRR4RW4IGi2wuSY0BWZ.
It has a 1000 requests per month limit.
Soooo - before trying you should fill in that rates into the database. You can do it with POST /rate-resolver/poll-and-update endpoint or UpdateCurrencyRatesCommand CLI command which has no parameters.
Once you did it you can load dump using that rates in the database like:
yarn cli LoadDumpWithApiRatesCommand _pathToYourDumpFile_It is still POST /dump-loader/upload endpoint, but fixedRates parameter should be set to false.
3. In the future the client may want to import files via the web interface, how can the system be modified to allow this?
Obviously it is already capable, see above.