Skip to content

Aashishthakur10/Spring-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple Spring Boot web application has been created and bootstrapped with data. The application contains information about all employees at a company. On application start-up, an in-memory Mongo database is bootstrapped with a serialized snapshot of the database. While the application runs, the data may be accessed and mutated in the database without impacting the snapshot.

How to Run

The application may be executed by running gradle bootRun.

How to Use

The following endpoints are available to use:

* CREATE
    * HTTP Method: POST 
    * URL: localhost:8080/employee
    * PAYLOAD: Employee
    * RESPONSE: Employee
* READ
    * HTTP Method: GET 
    * URL: localhost:8080/employee/{id}
    * RESPONSE: Employee
* UPDATE
    * HTTP Method: PUT 
    * URL: localhost:8080/employee/{id}
    * PAYLOAD: Employee
    * RESPONSE: Employee

The Employee has a JSON schema of:

{
  "type":"Employee",
  "properties": {
    "employeeId": {
      "type": "string"
    },
    "firstName": {
      "type": "string"
    },
    "lastName": {
          "type": "string"
    },
    "position": {
          "type": "string"
    },
    "department": {
          "type": "string"
    },
    "directReports": {
      "type": "array",
      "items" : "string"
    }
  }
}

For all endpoints that require an "id" in the URL, this is the "employeeId" field.

What to Implement

Clone or download the repository, do not fork it.

Task 1

Create a new type, ReportingStructure, that has two properties: employee and numberOfReports.

For the field "numberOfReports", this should equal the total number of reports under a given employee. The number of reports is determined to be the number of directReports for an employee and all of their distinct reports. For example, given the following employee structure:

                    John Lennon
                /               \
         Paul McCartney         Ringo Starr
                               /        \
                          Pete Best     George Harrison

The numberOfReports for employee John Lennon (employeeId: 16a596ae-edd3-4847-99fe-c4518e82c86f) would be equal to 4.

This new type should have a new REST endpoint created for it. This new endpoint should accept an employeeId and return the fully filled out ReportingStructure for the specified employeeId. The values should be computed on the fly and will not be persisted.

Solution Task 1

The following endpoint is available to use:

* READ
    * HTTP Method: GET 
    * URL: localhost:8080/reportingstructure/{id}
    * RESPONSE: Reporting structure

The Reporting Structure has a JSON schema of:

{
   "employee": {
       "type": "Employee",
       "properties": {
           "employeeId": {
               "type": "string"
           },
           "firstName": {
               "type": "string"
           },
           "lastName": {
               "type": "string"
           },
           "position": {
               "type": "string"
           },
           "department": {
               "type": "string"
           },
           "directReports": {
               "type": "array",
               "items": "string"
           }
     },
    "numberOfReports": {
           "type": "int"
      }
}

Task 2

Create a new type, Compensation. A Compensation has the following fields: employee, salary, and effectiveDate. Create two new Compensation REST endpoints. One to create and one to read by employeeId. These should persist and query the Compensation from the persistence layer.

Solution Task 2

The following endpoint is available to use:

* CREATE
    * HTTP Method: POST 
    * URL: localhost:8080/compensation
    * PAYLOAD: compensation
    * RESPONSE: compensation
* READ
    * HTTP Method: GET 
    * URL: localhost:8080/compensation/{id}
    * RESPONSE: Compensation
 

The Compensation has a JSON schema of:

{
   "employee": {
       "type": "Employee",
       "properties": {
           "employeeId": {
               "type": "string"
           },
           "firstName": {
               "type": "string"
           },
           "lastName": {
               "type": "string"
           },
           "position": {
               "type": "string"
           },
           "department": {
               "type": "string"
           },
           "directReports": {
               "type": "array",
               "items": "string"
           }
     },
     "salary":{
           "type": "int"
      },
    "effectiveDate":  {
          "type": "string"
     }
}

About

Coding challenge for Mindex

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages