Test task for backend developer by Natlex.
Features:
- Async Importing .XLS files;
- Async Exporting .XLS files;
- REST Endpoint API.
Example API Request and Response:
All requests must have an authorization token in the header.
'Authorization' : 'token'
GET http://localhost:8080/api/sections - Get a list of all Sections.
Json Response for api/sections
[ { "name": "Section 1", "geologicalClasses": [ { "name": "Geo Class 11", "code": "GC11" }, { "name": "Geo Class 12", "code": "GC12" } ] }, { "name": "Section 2", "geologicalClasses": [ { "name": "Geo Class 21", "code": "GC21" }, { "name": "Geo Class 22", "code": "GC22" } ] } }GET http://localhost:8080/api/sections/by-code?code=<code> - Get a list of all Sections that have geologicalClasses with the specified code.
`code` - specified code. Required field.
Json Response for api/sections/by-code?code=GCN2
[ { "name": "Section N", "geologicalClasses": [ { "name": "Geo Class N1", "code": "GCN1" }, { "name": "Geo Class N2", "code": "GCN2" }, { "name": "Geo Class NM", "code": "GCNM" } ] } }POST http://localhost:8080/api/import/ - POST request with .xls file. Returns ID of the Async Job and launches importing .xls file.
Content-Type : multipart/form-data;
Json Response for POST api/import
{ "id": 1 }GET http://localhost:8080/api/import/{id} - returns result of importing by Job ID ("DONE", "IN_PROGRESS", "ERROR")
Json Response for api/import/{id}
{ "id": 1, "type": "DONE" }GET http://localhost:8080/api/export/ - returns ID of the Async Job and launches exporting .xls file.
Json Response for api/api/export
{ "id": 2, "type": "IN_PROGRESS" }GET http://localhost:8080/api/export/{id} - returns status progress of exporting by Job ID ("DONE", "IN_PROGRESS", "ERROR")
Json Response for api/export/{id}
{ "id": 1, "type": "DONE" }GET http://localhost:8080/api/export/file/{id} - returns a file by Job ID (throw an exception with status 424(Failed Dependency) if exporting is in process or 404(Not Found) if Async Job was not launched)
Structure of file for importing and exporting:
- Clone this project;
- Open/Import project in IDEA;
- Create 'natlexservice' MySQL database for runtime;
- Select 'NatlexServiceApplication' in Run/Debug Configurations and run.
If your IDE didn't generate it on its own when importing the project create SpringBoot run configuration manually:
com.prototype.natlexservice.NatlexServiceApplication
Many settings, including database data, authorization token, can be found in application.properties
for runtime