Compare commits
6 commits
33157758c3
...
096c25e33b
Author | SHA1 | Date | |
---|---|---|---|
|
096c25e33b | ||
|
79ab6f7f48 | ||
06360ad1c6 | |||
7fc105308a | |||
3dd06fbf0c | |||
ce038dc725 |
4 changed files with 198 additions and 5 deletions
106
api/pmt.yml
106
api/pmt.yml
|
@ -27,6 +27,31 @@ components:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: "#/components/schemas/ProjectInfo"
|
$ref: "#/components/schemas/ProjectInfo"
|
||||||
|
GetAllProjectInfoDTO:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
goal:
|
||||||
|
type: string
|
||||||
|
customerId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
administratorId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
start:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
plannedEnd:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
realEnd:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
CreateProjectDTO:
|
CreateProjectDTO:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
@ -87,6 +112,31 @@ components:
|
||||||
plannedEnd:
|
plannedEnd:
|
||||||
type: string
|
type: string
|
||||||
format: date-time
|
format: date-time
|
||||||
|
Project:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
goal:
|
||||||
|
type: string
|
||||||
|
customerId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
administratorId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
start:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
plannedEnd:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
realEnd:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
AddEmployeeDTO:
|
AddEmployeeDTO:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
@ -135,6 +185,13 @@ components:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: "#/components/schemas/Employee"
|
$ref: "#/components/schemas/Employee"
|
||||||
|
EmployeeProjectsDTO:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
projects:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Project'
|
||||||
responses:
|
responses:
|
||||||
Unauthorized:
|
Unauthorized:
|
||||||
description: "Unauthorized"
|
description: "Unauthorized"
|
||||||
|
@ -213,6 +270,31 @@ paths:
|
||||||
$ref: "#/components/responses/ServiceUnavailable"
|
$ref: "#/components/responses/ServiceUnavailable"
|
||||||
|
|
||||||
/project/{id}:
|
/project/{id}:
|
||||||
|
get:
|
||||||
|
operationId: "getProjectInfo"
|
||||||
|
description: "Get a list of all Project Informations"
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: id
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
required: true
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "Project Info recieved"
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/GetAllProjectInfoDTO"
|
||||||
|
401:
|
||||||
|
$ref: "#/components/responses/Unauthorized"
|
||||||
|
404:
|
||||||
|
$ref: "#/components/responses/NotFound"
|
||||||
|
500:
|
||||||
|
$ref: "#/components/responses/InternalError"
|
||||||
|
503:
|
||||||
|
$ref: "#/components/responses/ServiceUnavailable"
|
||||||
post:
|
post:
|
||||||
operationId: "addEmployee"
|
operationId: "addEmployee"
|
||||||
description: "Adds an employee to a specific Project"
|
description: "Adds an employee to a specific Project"
|
||||||
|
@ -366,3 +448,27 @@ paths:
|
||||||
$ref: '#/components/responses/NotFound'
|
$ref: '#/components/responses/NotFound'
|
||||||
500:
|
500:
|
||||||
$ref: "#/components/responses/InternalError"
|
$ref: "#/components/responses/InternalError"
|
||||||
|
/employye/{id}/projects:
|
||||||
|
get:
|
||||||
|
description: "getAllProjects"
|
||||||
|
operationId: "Get a List of all Projects from a specific Employee"
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: id
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
required: true
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/EmployeeProjectsDTO"
|
||||||
|
description: 'Get a List of all Projects from a specific Employee'
|
||||||
|
401:
|
||||||
|
$ref: "#/components/responses/Unauthorized"
|
||||||
|
404:
|
||||||
|
$ref: '#/components/responses/NotFound'
|
||||||
|
500:
|
||||||
|
$ref: '#/components/responses/InternalError'
|
||||||
|
|
|
@ -3,6 +3,7 @@ package de.hmmh.pmt;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import de.hmmh.pmt.db.*;
|
import de.hmmh.pmt.db.*;
|
||||||
|
import de.hmmh.pmt.db.Project;
|
||||||
import de.hmmh.pmt.dtos.*;
|
import de.hmmh.pmt.dtos.*;
|
||||||
import de.hmmh.pmt.employee.ApiClientFactory;
|
import de.hmmh.pmt.employee.ApiClientFactory;
|
||||||
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
||||||
|
@ -72,6 +73,18 @@ public class ApiController implements DefaultApi {
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<GetAllProjectInfoDTO> getProjectInfo(Long id){
|
||||||
|
Optional<Project> optionalProject = projectRepository.findById(id);
|
||||||
|
if (optionalProject.isEmpty()) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
Project project = optionalProject.get();
|
||||||
|
|
||||||
|
return ResponseEntity.ok(mapper.mapToGet(project));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Void> updateProject(Long id, UpdateProjectDTO body) {
|
public ResponseEntity<Void> updateProject(Long id, UpdateProjectDTO body) {
|
||||||
Optional<Project> optionalProject = projectRepository.findById(id);
|
Optional<Project> optionalProject = projectRepository.findById(id);
|
||||||
|
@ -225,4 +238,19 @@ public class ApiController implements DefaultApi {
|
||||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<EmployeeProjectsDTO> getAListOfAllProjectsFromASpecificEmployee(Long id) {
|
||||||
|
List<Allocation> allocationsByEmployee = allocationRepository.findAllByEmployeeId(id);
|
||||||
|
|
||||||
|
Set<Project> projects = allocationsByEmployee.stream()
|
||||||
|
.map(Allocation::getProject)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
EmployeeProjectsDTO response = new EmployeeProjectsDTO();
|
||||||
|
for (Project project : projects) {
|
||||||
|
response.addProjectsItem(mapper.mapProject(project));
|
||||||
|
}
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package de.hmmh.pmt.util;
|
package de.hmmh.pmt.util;
|
||||||
|
|
||||||
import de.hmmh.pmt.db.Project;
|
import de.hmmh.pmt.db.Project;
|
||||||
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
import de.hmmh.pmt.dtos.*;
|
||||||
import de.hmmh.pmt.dtos.CreatedProjectDTO;
|
|
||||||
import de.hmmh.pmt.dtos.Employee;
|
|
||||||
import de.hmmh.pmt.dtos.Qualification ;
|
|
||||||
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
||||||
import de.hmmh.pmt.employee.dtos.QualificationGetDTO;
|
import de.hmmh.pmt.employee.dtos.QualificationGetDTO;
|
||||||
import de.hmmh.pmt.dtos.UpdateProjectDTO;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -37,6 +34,19 @@ public class Mapper {
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GetAllProjectInfoDTO mapToGet(Project project) {
|
||||||
|
GetAllProjectInfoDTO dto = new GetAllProjectInfoDTO();
|
||||||
|
dto.setId(project.getId());
|
||||||
|
dto.setName(project.getName());
|
||||||
|
dto.setGoal(project.getGoal());
|
||||||
|
dto.setCustomerId(project.getCustomerId());
|
||||||
|
dto.setAdministratorId(project.getAdministratorId());
|
||||||
|
dto.setStart(project.getStart());
|
||||||
|
dto.setPlannedEnd(project.getPlannedEnd());
|
||||||
|
dto.setRealEnd(project.getRealEnd());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
public Employee map(EmployeeResponseDTO employeeResponseDTO) {
|
public Employee map(EmployeeResponseDTO employeeResponseDTO) {
|
||||||
Employee dto = new Employee();
|
Employee dto = new Employee();
|
||||||
dto.setId(employeeResponseDTO.getId());
|
dto.setId(employeeResponseDTO.getId());
|
||||||
|
@ -72,4 +82,16 @@ public class Mapper {
|
||||||
project.setPlannedEnd(dto.getPlannedEnd());
|
project.setPlannedEnd(dto.getPlannedEnd());
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
public de.hmmh.pmt.dtos.Project mapProject(Project project){
|
||||||
|
de.hmmh.pmt.dtos.Project dto = new de.hmmh.pmt.dtos.Project();
|
||||||
|
dto.setId(project.getId());
|
||||||
|
dto.setName(project.getName());
|
||||||
|
dto.setGoal(project.getGoal());
|
||||||
|
dto.setCustomerId(project.getCustomerId());
|
||||||
|
dto.setAdministratorId(project.getAdministratorId());
|
||||||
|
dto.setStart(project.getStart());
|
||||||
|
dto.setPlannedEnd(project.getPlannedEnd());
|
||||||
|
dto.setRealEnd(project.getRealEnd());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
37
src/test/java/de/hmmh/pmt/project/GetProjectInfoTest.java
Normal file
37
src/test/java/de/hmmh/pmt/project/GetProjectInfoTest.java
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package de.hmmh.pmt.project;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import de.hmmh.pmt.IntegrationTest;
|
||||||
|
import de.hmmh.pmt.db.Project;
|
||||||
|
|
||||||
|
public class GetProjectInfoTest extends IntegrationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void noProject() throws Exception {
|
||||||
|
mvc
|
||||||
|
.perform(get(baseUri + "/project/1"))
|
||||||
|
.andExpect(status().isNotFound());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getProjectInfo() throws Exception {
|
||||||
|
Map<String, Project> allProjects = createTestProjectData();
|
||||||
|
Project spaceStation = allProjects.get("space-station");
|
||||||
|
mvc
|
||||||
|
.perform(get(baseUri + "/project/" +spaceStation.getId()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.id").value(spaceStation.getId()))
|
||||||
|
.andExpect(jsonPath("$.name").value(spaceStation.getName()))
|
||||||
|
.andExpect(jsonPath("$.goal").value(spaceStation.getGoal()))
|
||||||
|
.andExpect(jsonPath("$.customerId").value(spaceStation.getCustomerId()))
|
||||||
|
.andExpect(jsonPath("$.administratorId").value(spaceStation.getAdministratorId()))
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue