Request
{
"first_name": "Hans",
"surname": "Kloss",
"country_code": "DE",
"identification_number": "12631904566"
}
Response
{
"id": "9c5ad870-9e43-4c49-a974-77165529ccb9",
"first_name": "Hans",
"surname": "Kloss",
"country_code": "DE",
"identification_number": "12631904566"
}
Error
{
"code": 422,
"message": "Validation Failed",
"errors": {
"identification_number": "Identification number is invalid"
}
}
Response
[
{
"id": "9c5ad870-9e43-4c49-a974-77165529ccb9",
"first_name": "Hans",
"surname": "Kloss",
"country_code": "DE",
"identification_number": "12631904566"
},
...
]
Your task is very simple:
- Prepare new endpoint „/api/v1/users” in REST API, which creates the user in the database.
- Prepare display all users (provided by endpoint) as a list "/users"
The user has following data:
- firstname
- surname
- country code (only PL or DE) in ISO 3166-1 alfa-2 standard - more info here: https://pl.wikipedia.org/wiki/ISO_3166-1_alfa-2
- identification number
- for PL will be a PESEL (11 digits) -> description of validation https://pl.wikipedia.org/wiki/PESEL
- for DE will be a die Identifikationsnummer (11 digits) -> description of validation https://de.wikipedia.org/wiki/Steuerliche_Identifikationsnummer#Aufbau_der_Identifikationsnummer
- All data (firstname, surname, country code, identification number) for user are required.
- We serve only users from Poland and Germany. If user comes from another country, we should receive an error from the response API.
- The endpoint „/api/v1/users” before writing new user to the database should check the identification number if it's correct, i.e. it has the correct check digit and control sum.
- If the identification number or country code is incorrect then response should return code 422 and contains an error messages. Example:
{
"code": 422,
"message": "Validation Failed";
"errors": {
„identificationNumber": "Invalid value for identificationNumber.",
„country": "Invalid value for country."
}
}
- If any field is empty in request then response should return code 422 and contains an error messages. Example:
{
"code": 422,
"message": "Validation Failed";
"errors": {
"firstName": "This value should not be blank.",
"country": "This value should not be blank."
}
}
- If the creation of a user in the database succeeds, then response should return code 201 and the unique ID of the new user that will be assigned in the application. Example:
{
"userId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
We would like to get a working code.
You're welcome to improve our code
If something is not specified or explained please do it according to your own idea! :)
You should send us a GitHub/BitBucket link to repository (remember to keep commits clean) or zip file with the whole project.
- Run
make install
- Add following lines to /etc/hosts (For MacOS with docker-machine if using different system change IP):
192.168.99.100 backed-recruitment-task.local
make start
- Website is accessible through
backed-recruitment-task.local
- To down
make down