I have used H2 in-memory DB. During the Boot-up of application i'm creating the tables using the file data.sql
Get Employee By id
Url: http://localhost:8080/v1/bfs/employees/1
Method: GET
Response: {
"id": 1,
"first_name": "test-first-name",
"last_name": "chen",
"date_of_birth": "27-00-1993",
"address": {
"line1": "line1",
"line2": "line2",
"city": "Bangalore",
"state": "Karnataka",
"country": "india",
"zipcode": "560037"
}
}
Create Employee
Url: http://localhost:8080/v1/bfs/employees
Method: POST
Request: {
"first_name":"test-first-name",
"last_name": "test",
"date_of_birth":"20-04-1993",
"address":{
"line1":"line1",
"line2":"line2",
"city":"Bangalore",
"state":"Karnataka",
"country":"india",
"zipcode":"560037"
}
}
Response: {
"id": 3,
"first_name": "test-first-name",
"last_name": "test_1",
"date_of_birth": "27-04-1993",
"address": {
"line1": "line1",
"line2": "line2",
"city": "Bangalore",
"state": "Karnataka",
"country": "india",
"zipcode": "560037"
}
}
All the test cases are included in the module employeeservImplementation
even integration test cases.
I'm considering employees are same if both the first_name and last_name matches.
For any validation failures returning 400 Bad request
.
200
in case employee created successfully or employee object is returned successfully.
employeeserv is a spring boot rest application which would provide the CRUD operations for Employee
resource.
There are three modules in this application
- employeeservApi - This module contains the interface.
v1/schema/employee.json
defines the employee resource.jsonschema2pojo-maven-plugin
is being used to createEmployee POJO
from json file.EmployeeResource.java
is the interface for CRUD operations onEmployee
resource.- GET
/v1/bfs/employees/{id}
endpoint is defined to fetch the resource.
- GET
- employeeservImplementation - This module contains the implementation for the rest endpoints.
EmployeeResourceImpl.java
implements theEmployeeResource
interface.
- employeeservFunctionalTests - This module would have the functional tests.
- Please have Maven version
3.3.3
& Java 8 on your system. - Use command
mvn clean install
to build the project. - Use command
mvn spring-boot:run
fromemployeeservImplementation
folder to run the project. - Use postman or curl to access
http://localhost:8080/v1/bfs/employees/1
GET endpoint. It will return an Employee resource.
We would like you to enhance the existing project and see you complete the following requirements:
employee.json
has onlyname
, andid
elements. Please adddate of birth
andaddress
elements to theEmployee
resource. Address will haveline1
,line2
,city
,state
,country
andzip_code
elements.line2
is an optional element.- Add one more operation in
EmployeeResource
to create an employee.EmployeeResource
will have two operations, one to create, and another to retrieve the employee resource. - Implement create and retrieve operations in
EmployeeResourceImpl.java
. - Resource created using create endpoint should be retrieved using retrieve/get endpoint.
- Please add the unit tests to validate your implementation.
- Please use h2 in-memory database or any other in-memory database to persist the
Employee
resource. Dependency for h2 in-memory database is already added to the parent pom. - Please make sure the validations are done for the requests.
- Response codes are as per rest guidelines.
- Error handling in case of failures.
- Idempotency logic is implemented to avoid duplicate resource creation.
Thank you very much for your time to take this test. Please upload this complete solution in Github and send us the link to bfs-sor-interview@paypal.com
.