Skip to content
Merged
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
1 change: 0 additions & 1 deletion README.md

This file was deleted.

4 changes: 4 additions & 0 deletions employee-mgr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
<artifactId>springfox-bean-validators</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.hateoas.RepresentationModel;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel("This model is for employee information")
@Entity
@Table(name = "tb_employee")
public class Employee {
public class Employee extends RepresentationModel<Employee>{

@ApiModelProperty(notes = "Employee ID should have first name initial+ Gender initial + YYYYMMDDHHMM", required = true, example = "SM201104180925", position = 1)
@Id
Expand All @@ -27,9 +27,8 @@ public class Employee {
private String eMailId;
private Date joiningDate;

@ManyToMany
@JsonIgnore
private List<Technology> technology = new ArrayList<Technology>();
@ManyToMany(mappedBy = "employees")
private List<Technology> technologies = new ArrayList<Technology>();

public String getEmpId() {
return empId;
Expand All @@ -47,11 +46,11 @@ public void setEmpName(String empName) {
this.empName = empName;
}

public Integer getprojectCode() {
public Integer getProjectCode() {
return projectCode;
}

public void setprojectCode(Integer projectCode) {
public void setProjectCode(Integer projectCode) {
this.projectCode = projectCode;
}

Expand All @@ -71,12 +70,12 @@ public void setJoiningDate(Date joiningDate) {
this.joiningDate = joiningDate;
}

public List<Technology> getTechnology() {
return technology;
public List<Technology> getTechnologies() {
return technologies;
}

public void setTechnology(List<Technology> technology) {
this.technology = technology;
public void setTechnologies(List<Technology> technologies) {
this.technologies = technologies;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.springframework.hateoas.RepresentationModel;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel("This model is for technology information")
@Entity
@Table(name = "tb_technology")
public class Technology {
public class Technology extends RepresentationModel<Technology>{

@ApiModelProperty(notes="Autogenerated unique Identity",position=1)
@Id
Expand All @@ -24,7 +26,7 @@ public class Technology {
private String techName;
private String catagoty;

@ManyToMany(mappedBy = "technology")
@ManyToMany
private List<Employee> employee = new ArrayList<Employee>();

public Integer getTechId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import javax.validation.constraints.Min;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smallintro.springboot.entity.Employee;
import com.smallintro.springboot.repository.EmployeeRepo;
import com.smallintro.springboot.utils.ProjectConstants;

@Service
public class EmployeeService {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.server.ResponseStatusException;

import com.smallintro.springboot.entity.Technology;
import com.smallintro.springboot.repository.TechRepo;
import com.smallintro.springboot.utils.ProjectConstants;

@Service
public class TechService {

@Autowired
Expand Down
7 changes: 7 additions & 0 deletions employee-mgr/src/main/resources/TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1) Entity and request validation
2) Define column name and property
3) Test ManyToMany + Add Support for HATEOAS
4) Add i18n
5) Add DTOs and filters
6) Implement versioning and content negotiation

4 changes: 4 additions & 0 deletions project-mgr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
<artifactId>springfox-bean-validators</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -13,42 +17,72 @@
import org.springframework.web.bind.annotation.RestController;

import com.smallintro.springboot.entity.Department;
import com.smallintro.springboot.entity.Project;
import com.smallintro.springboot.service.DepartmentService;

import io.swagger.annotations.Api;


@Api(tags="Department management APIs",value="Project Controller")
@Api(tags = "Department management APIs", value = "Department Controller")
@RestController
@RequestMapping("department")
public class DepartmentController {

@Autowired
DepartmentService deptService;

@GetMapping(value="/{deptName}",produces = MediaType.APPLICATION_JSON_VALUE)
public Department getDepartmentByName(@PathVariable String deptName) {

return deptService.getDepartmentByName(deptName);

@GetMapping(value = "/{deptName}", produces = MediaType.APPLICATION_JSON_VALUE)
public EntityModel<Department> getDepartmentByName(@PathVariable String deptName) {

Department dept = deptService.getDepartmentByName(deptName);

Link selfLink = WebMvcLinkBuilder.linkTo(this.getClass()).slash(dept.getDeptName()).withSelfRel();
dept.add(selfLink);
EntityModel<Department> deptModel = EntityModel.of(dept);
return deptModel;
}

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public List<Department> getAllDepartments() {

return deptService.getAllDepartments();
public CollectionModel<Department> getAllDepartments() {

List<Department> departments = deptService.getAllDepartments();

for (Department dept : departments) {

Link selfLink = WebMvcLinkBuilder.linkTo(this.getClass()).slash(dept.getDeptName()).withSelfRel();
dept.add(selfLink);

CollectionModel<Project> projects = WebMvcLinkBuilder.methodOn(this.getClass())
.getProjects(dept.getDeptName());

Link projLink = WebMvcLinkBuilder.linkTo(projects).withRel("all-projects");

dept.add(projLink);

}
Link selfLink = WebMvcLinkBuilder.linkTo(this.getClass()).withSelfRel();

CollectionModel<Department> deptModels = CollectionModel.of(departments, selfLink);
return deptModels;
}

@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public Department createDepartment(@RequestBody Department dept) {

return deptService.createDepartment(dept);
}

@DeleteMapping("/{deptId}")
public void deleteDepartmentById(@PathVariable Long deptId) {

deptService.deleteDepartmentById(deptId);
}

@GetMapping("/{deptName}/projects")
public CollectionModel<Project> getProjects(@PathVariable String deptName) {
List<Project> projects = deptService.getProjects(deptName);

CollectionModel<Project> projectsModel = CollectionModel.of(projects);
return projectsModel;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;

import com.smallintro.springboot.entity.Department;
import com.smallintro.springboot.entity.Project;
import com.smallintro.springboot.exception.RecordNotFoundException;
import com.smallintro.springboot.service.DepartmentService;
import com.smallintro.springboot.service.ProjectService;
import com.smallintro.springboot.utils.ProjectConstants;

Expand All @@ -29,6 +31,9 @@ public class ProjectController {
@Autowired
ProjectService projectService;

@Autowired
DepartmentService deptService;

@GetMapping
public List<Project> getProjects() {
return projectService.findAllProjects();
Expand All @@ -43,14 +48,20 @@ public Project getProjectInfo(@PathVariable String projectName) {
}
}

@PostMapping
public String addProject(@RequestBody Project proj) {
@PostMapping(value = "/{deptId}/project")
public Project addProject(@PathVariable Long deptId, @RequestBody Project proj) {
Department dept = deptService.getDepartmentById(deptId);
if (null == dept) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
"No department found with department Id: " + deptId);
}
if (projectService.isProjectExistsByName(proj.getProjectName())) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
"Project with name " + proj.getProjectName() + " already exists");
}
projectService.saveProject(proj);
return ProjectConstants.OPERATION_SUCCESS;
proj.setDepartment(dept);
return projectService.saveProject(proj);

}

@PutMapping(value = "/{projectCode}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.springframework.hateoas.RepresentationModel;

import io.swagger.annotations.ApiModel;

@ApiModel("This model is for project information")
@ApiModel("This model is for department information")
@Entity
@Table(name = "tb_department")
public class Department {
public class Department extends RepresentationModel<Department>{

@Id
@GeneratedValue
private Long deptId;
private String deptName;
@OneToMany
@OneToMany(mappedBy="department")
private List<Project> projects;

public Department() {
super();
}

public Long getDeptId() {
return deptId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import java.sql.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.springframework.hateoas.RepresentationModel;

import com.fasterxml.jackson.annotation.JsonIgnore;

import io.swagger.annotations.ApiModel;

@ApiModel("This model is for project information")
@Entity
@Table(name = "tb_project")
public class Project {
public class Project extends RepresentationModel<Project>{

@Id
@GeneratedValue
Expand All @@ -22,9 +27,16 @@ public class Project {
private Date startDate;
private String projectStatus;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnore
private Department department;



public Project() {
super();
}

public Integer getProjectCode() {
return projectCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface DepartmentRepo extends JpaRepository<Department, Long> {

public Department findByDeptName(String deptName);

public Department findByDeptId(Long deptId);

}
Loading