Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ A map of key/value pairs of properties assigned to an employee.
1. Create a Fork of the repository into your personal GitHub space.
2. Implement the feature as described above.
3. Create a Pull Request back to the original project.

## Swagger docs
The swagger documentation is in [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html)
30 changes: 30 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
Expand All @@ -31,6 +35,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>

<dependency>
<groupId>org.flywaydb</groupId>
Expand All @@ -49,6 +57,28 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.zoomcare.candidatechallenge.advice;

import com.zoomcare.candidatechallenge.exception.EmployeeNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class EmployeeNotFoundAdvice {

@ResponseBody
@ExceptionHandler(EmployeeNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
String employeeNotFoundHandler(EmployeeNotFoundException ex){
return ex.getMessage();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.zoomcare.candidatechallenge.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Collections;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket apiDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.zoomcare.candidatechallenge.controller"))
.paths(PathSelectors.any())
.build()
.apiInfo(getApiInfo());
}

private ApiInfo getApiInfo() {
return new ApiInfo("ZOOM CARE Code Challenge",
"Organization API Description",
"1.0",
null,
null,
"LICENSE",
"",
Collections.emptyList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.zoomcare.candidatechallenge.controller;

import com.zoomcare.candidatechallenge.dto.EmployeeDTO;
import com.zoomcare.candidatechallenge.exception.EmployeeNotFoundException;
import com.zoomcare.candidatechallenge.service.OrganizationService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* Organization Endpoint
*/
@RestController
@RequestMapping("/api/v1/organization")
public class OrganizationController {

private final OrganizationService organizationService;

public OrganizationController(OrganizationService organizationService) {
this.organizationService = organizationService;
}

/**
* Obtain the top-level employees
* @return
*/
@GetMapping("top")
List<EmployeeDTO> getAllTopLevelsEmployees(){
return organizationService.getAllTopLevelsEmployees();
}

/**
* Obtain employee by ID
* @param id the employee Identifieer
* @return the employee information requested.
*/
@GetMapping("/{id}")
EmployeeDTO getEmployeeById(@PathVariable("id") Long id){
return organizationService.findById(id)
.orElseThrow(()-> new EmployeeNotFoundException(id));
}
}
56 changes: 56 additions & 0 deletions src/main/java/com/zoomcare/candidatechallenge/dto/EmployeeDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.zoomcare.candidatechallenge.dto;

import java.util.List;
import java.util.Map;

public class EmployeeDTO {

private Long id;
private Long supervisorId;

private List<PropertyDTO> properties;

private List<EmployeeDTO> employees;

public EmployeeDTO() {
}

public EmployeeDTO(Long id, Long supervisorId, List<PropertyDTO> properties, List<EmployeeDTO> employees) {
this.id = id;
this.supervisorId = supervisorId;
this.properties = properties;
this.employees = employees;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Long getSupervisorId() {
return supervisorId;
}

public void setSupervisorId(Long supervisorId) {
this.supervisorId = supervisorId;
}

public List<EmployeeDTO> getEmployees() {
return employees;
}

public void setEmployees(List<EmployeeDTO> employees) {
this.employees = employees;
}

public List<PropertyDTO> getProperties() {
return properties;
}

public void setProperties(List<PropertyDTO> properties) {
this.properties = properties;
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/zoomcare/candidatechallenge/dto/PropertyDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.zoomcare.candidatechallenge.dto;

import java.io.Serializable;

public class PropertyDTO implements Serializable {
private String key;
private String value;

public PropertyDTO(String key, String value) {
this.key = key;
this.value = value;
}

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.zoomcare.candidatechallenge.exception;

public class EmployeeNotFoundException extends RuntimeException {
public EmployeeNotFoundException(Long id) {
super("Could not find employee " + id);
}
}
58 changes: 58 additions & 0 deletions src/main/java/com/zoomcare/candidatechallenge/model/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.zoomcare.candidatechallenge.model;

import javax.persistence.*;
import java.util.List;

/**
* Model for Employee table
*/
@Entity
public class Employee {

@Id
@GeneratedValue
private Long id;

@Column(name = "supervisor_id")
private Long supervisorId;

@OneToMany
@JoinColumn(name = "supervisor_id")
private List<Employee> employees;

@OneToMany
@JoinColumn(name = "employee_id")
private List<Property> properties;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Long getSupervisorId() {
return supervisorId;
}

public void setSupervisorId(Long supervisorId) {
this.supervisorId = supervisorId;
}

public List<Property> getProperties() {
return properties;
}

public void setProperties(List<Property> properties) {
this.properties = properties;
}

public List<Employee> getEmployees() {
return employees;
}

public void setEmployees(List<Employee> employees) {
this.employees = employees;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.zoomcare.candidatechallenge.model;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.io.Serializable;

@Embeddable
public class EntityPropertyPk implements Serializable {
@Column(name = "key")
private String key;

@ManyToOne
@JoinColumn(name = "employee_id")
private Employee employee;

public Employee getEmployee() {
return employee;
}

public void setEmployee(Employee employee) {
this.employee = employee;
}

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/zoomcare/candidatechallenge/model/Property.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.zoomcare.candidatechallenge.model;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.io.Serializable;

/**
* Model for Property table
*/
@Entity
public class Property implements Serializable {

@EmbeddedId
private EntityPropertyPk id;
private String value;

public EntityPropertyPk getId() {
return id;
}

public void setId(EntityPropertyPk id) {
this.id = id;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
Loading