Compare commits
1 commit
078a17c1db
...
d84647f9e6
Author | SHA1 | Date | |
---|---|---|---|
|
d84647f9e6 |
5 changed files with 35 additions and 104 deletions
56
api/pmt.yml
56
api/pmt.yml
|
@ -30,16 +30,16 @@ components:
|
||||||
CreateProjectDTO:
|
CreateProjectDTO:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
goal:
|
|
||||||
type: string
|
|
||||||
customerId:
|
customerId:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
administratorId:
|
administratorId:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
|
title:
|
||||||
|
type: string
|
||||||
|
goal:
|
||||||
|
type: string
|
||||||
start:
|
start:
|
||||||
type: string
|
type: string
|
||||||
format: date-time
|
format: date-time
|
||||||
|
@ -52,16 +52,16 @@ components:
|
||||||
id:
|
id:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
goal:
|
|
||||||
type: string
|
|
||||||
customerId:
|
customerId:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
administratorId:
|
administratorId:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
|
title:
|
||||||
|
type: string
|
||||||
|
goal:
|
||||||
|
type: string
|
||||||
start:
|
start:
|
||||||
type: string
|
type: string
|
||||||
format: date-time
|
format: date-time
|
||||||
|
@ -69,8 +69,14 @@ components:
|
||||||
type: string
|
type: string
|
||||||
format: date-time
|
format: date-time
|
||||||
responses:
|
responses:
|
||||||
Unauthorized:
|
UnAuthorized:
|
||||||
description: "Unauthorized"
|
description: "Un Authorized"
|
||||||
|
InternalError:
|
||||||
|
description: "Internal Server Error"
|
||||||
|
content:
|
||||||
|
text/plain:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
NotFound:
|
NotFound:
|
||||||
description: "Not Found"
|
description: "Not Found"
|
||||||
content:
|
content:
|
||||||
|
@ -83,24 +89,6 @@ components:
|
||||||
text/plain:
|
text/plain:
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
UnprocessableContent:
|
|
||||||
description: "Unprocessable Content"
|
|
||||||
content:
|
|
||||||
text/plain:
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
InternalError:
|
|
||||||
description: "Internal Server Error"
|
|
||||||
content:
|
|
||||||
text/plain:
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
ServiceUnavailable:
|
|
||||||
description: "Service Unavailable"
|
|
||||||
content:
|
|
||||||
text/plain:
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
paths:
|
paths:
|
||||||
/project:
|
/project:
|
||||||
get:
|
get:
|
||||||
|
@ -114,7 +102,7 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/GetAllProjectsDTO"
|
$ref: "#/components/schemas/GetAllProjectsDTO"
|
||||||
401:
|
401:
|
||||||
$ref: "#/components/responses/Unauthorized"
|
$ref: "#/components/responses/UnAuthorized"
|
||||||
500:
|
500:
|
||||||
$ref: "#/components/responses/InternalError"
|
$ref: "#/components/responses/InternalError"
|
||||||
post:
|
post:
|
||||||
|
@ -133,14 +121,10 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/CreatedProjectDTO"
|
$ref: "#/components/schemas/CreatedProjectDTO"
|
||||||
401:
|
401:
|
||||||
$ref: "#/components/responses/Unauthorized"
|
$ref: "#/components/responses/UnAuthorized"
|
||||||
404:
|
404:
|
||||||
$ref: "#/components/responses/NotFound"
|
$ref: "#/components/responses/NotFound"
|
||||||
409:
|
409:
|
||||||
$ref: "#/components/responses/Conflict"
|
$ref: "#/components/responses/NotFound"
|
||||||
422:
|
|
||||||
$ref: "#/components/responses/UnprocessableContent"
|
|
||||||
500:
|
500:
|
||||||
$ref: "#/components/responses/InternalError"
|
$ref: "#/components/responses/InternalError"
|
||||||
503:
|
|
||||||
$ref: "#/components/responses/ServiceUnavailable"
|
|
|
@ -4,7 +4,7 @@
|
||||||
"invokerPackage": "de.hmmh.pmt",
|
"invokerPackage": "de.hmmh.pmt",
|
||||||
"java8": false,
|
"java8": false,
|
||||||
"java11": true,
|
"java11": true,
|
||||||
"dateLibrary": "java8-localdatetime",
|
"dateLibrary": "java11",
|
||||||
"library": "spring-boot3",
|
"library": "spring-boot3",
|
||||||
"defaultInterfaces": false,
|
"defaultInterfaces": false,
|
||||||
"serializableModel": true
|
"serializableModel": true
|
||||||
|
|
|
@ -1,22 +1,20 @@
|
||||||
package de.hmmh.pmt;
|
package de.hmmh.pmt;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import de.hmmh.pmt.db.Project;
|
|
||||||
import de.hmmh.pmt.db.ProjectRepository;
|
|
||||||
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
||||||
import de.hmmh.pmt.dtos.CreatedProjectDTO;
|
import de.hmmh.pmt.dtos.CreatedProjectDTO;
|
||||||
|
import de.hmmh.pmt.employee.ApiClientFactory;
|
||||||
|
import de.hmmh.pmt.db.Project;
|
||||||
|
import de.hmmh.pmt.db.ProjectRepository;
|
||||||
|
import de.hmmh.pmt.oas.DefaultApi;
|
||||||
import de.hmmh.pmt.dtos.GetAllProjectsDTO;
|
import de.hmmh.pmt.dtos.GetAllProjectsDTO;
|
||||||
import de.hmmh.pmt.dtos.ProjectInfo;
|
import de.hmmh.pmt.dtos.ProjectInfo;
|
||||||
import de.hmmh.pmt.employee.ApiClientFactory;
|
|
||||||
import de.hmmh.pmt.oas.DefaultApi;
|
|
||||||
import de.hmmh.pmt.util.Mapper;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
|
||||||
import org.springframework.web.client.RestClientException;
|
import org.springframework.web.client.RestClientException;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -24,8 +22,6 @@ import java.util.Optional;
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("${openapi.projectManagement.base-path:/api/v1}")
|
@RequestMapping("${openapi.projectManagement.base-path:/api/v1}")
|
||||||
public class ApiController implements DefaultApi {
|
public class ApiController implements DefaultApi {
|
||||||
@Autowired
|
|
||||||
private Mapper mapper;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApiClientFactory apiClientFactory;
|
private ApiClientFactory apiClientFactory;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -45,7 +41,7 @@ public class ApiController implements DefaultApi {
|
||||||
public ResponseEntity<GetAllProjectsDTO> getAllProjects() {
|
public ResponseEntity<GetAllProjectsDTO> getAllProjects() {
|
||||||
GetAllProjectsDTO response = new GetAllProjectsDTO();
|
GetAllProjectsDTO response = new GetAllProjectsDTO();
|
||||||
|
|
||||||
for (Project project : this.projectRepository.findAll()) {
|
for (Project project : this.projectRepository.findAll()){
|
||||||
ProjectInfo projectInfo = new ProjectInfo();
|
ProjectInfo projectInfo = new ProjectInfo();
|
||||||
projectInfo.setId(project.getId());
|
projectInfo.setId(project.getId());
|
||||||
projectInfo.setName(project.getName());
|
projectInfo.setName(project.getName());
|
||||||
|
@ -57,29 +53,17 @@ public class ApiController implements DefaultApi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<CreatedProjectDTO> createProject(CreateProjectDTO body) {
|
public ResponseEntity<CreatedProjectDTO> createProject(CreateProjectDTO body) {
|
||||||
if (projectRepository.existsByName(body.getName())) {
|
if (projectRepository.existsByName(body.getTitle())){
|
||||||
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
if (apiClientFactory.getEmployeeApi().findById(body.getAdministratorId()).getId() == body.getAdministratorId()){
|
||||||
|
|
||||||
try {
|
}
|
||||||
apiClientFactory.getEmployeeApi().findById(body.getAdministratorId());
|
} catch (RestClientException exception){
|
||||||
} catch (HttpClientErrorException exception) {
|
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
return new ResponseEntity<>(
|
}
|
||||||
exception.getStatusCode().equals(HttpStatus.NOT_FOUND)
|
|
||||||
? HttpStatus.NOT_FOUND
|
|
||||||
: HttpStatus.SERVICE_UNAVAILABLE
|
|
||||||
);
|
|
||||||
} catch (RestClientException exception) {
|
|
||||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
Project project = mapper.map(body);
|
return null;
|
||||||
if (!project.isValid()) {
|
|
||||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
|
||||||
}
|
|
||||||
projectRepository.save(project);
|
|
||||||
|
|
||||||
CreatedProjectDTO response = mapper.map(project);
|
|
||||||
return new ResponseEntity<>(response, HttpStatus.CREATED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import java.time.LocalDateTime;
|
||||||
@Table(name = "project")
|
@Table(name = "project")
|
||||||
public class Project {
|
public class Project {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
|
@ -43,10 +43,5 @@ public class Project {
|
||||||
private LocalDateTime plannedEnd;
|
private LocalDateTime plannedEnd;
|
||||||
|
|
||||||
private LocalDateTime realEnd; // Cant be named just "end" because it's and SQL Keyword
|
private LocalDateTime realEnd; // Cant be named just "end" because it's and SQL Keyword
|
||||||
|
|
||||||
|
|
||||||
public boolean isValid() {
|
|
||||||
return plannedEnd.isAfter(start) && (realEnd == null || realEnd.isAfter(start));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
package de.hmmh.pmt.util;
|
|
||||||
|
|
||||||
import de.hmmh.pmt.db.Project;
|
|
||||||
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
|
||||||
import de.hmmh.pmt.dtos.CreatedProjectDTO;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class Mapper {
|
|
||||||
public Project map(CreateProjectDTO dto) {
|
|
||||||
Project project = new Project();
|
|
||||||
project.setName(dto.getName());
|
|
||||||
project.setGoal(dto.getGoal());
|
|
||||||
project.setCustomerId(dto.getCustomerId());
|
|
||||||
project.setAdministratorId(dto.getAdministratorId());
|
|
||||||
project.setStart(dto.getStart());
|
|
||||||
project.setPlannedEnd(dto.getPlannedEnd());
|
|
||||||
return project;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CreatedProjectDTO map(Project project) {
|
|
||||||
CreatedProjectDTO dto = new CreatedProjectDTO();
|
|
||||||
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());
|
|
||||||
return dto;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue