.
Some checks failed
Quality Check / Validate OAS (push) Successful in 34s
Quality Check / Linting (push) Failing after 52s
Quality Check / Static Analysis (push) Failing after 1m0s
Quality Check / Testing (push) Successful in 1m4s

This commit is contained in:
Rajbir Singh 2024-10-07 14:27:22 +02:00
parent b31685b79d
commit d84647f9e6
3 changed files with 97 additions and 2 deletions

View file

@ -27,6 +27,47 @@ components:
type: array
items:
$ref: "#/components/schemas/ProjectInfo"
CreateProjectDTO:
type: object
properties:
customerId:
type: integer
format: int64
administratorId:
type: integer
format: int64
title:
type: string
goal:
type: string
start:
type: string
format: date-time
plannedEnd:
type: string
format: date-time
CreatedProjectDTO:
type: object
properties:
id:
type: integer
format: int64
customerId:
type: integer
format: int64
administratorId:
type: integer
format: int64
title:
type: string
goal:
type: string
start:
type: string
format: date-time
plannedEnd:
type: string
format: date-time
responses:
UnAuthorized:
description: "Un Authorized"
@ -36,6 +77,18 @@ components:
text/plain:
schema:
type: string
NotFound:
description: "Not Found"
content:
text/plain:
schema:
type: string
Conflict:
description: "Conflict"
content:
text/plain:
schema:
type: string
paths:
/project:
get:
@ -50,5 +103,28 @@ paths:
$ref: "#/components/schemas/GetAllProjectsDTO"
401:
$ref: "#/components/responses/UnAuthorized"
500:
$ref: "#/components/responses/InternalError"
post:
operationId: "CreateProject"
description: "Creates a new Project"
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/CreateProjectDTO"
responses:
201:
description: "Project created successfully"
content:
application/json:
schema:
$ref: "#/components/schemas/CreatedProjectDTO"
401:
$ref: "#/components/responses/UnAuthorized"
404:
$ref: "#/components/responses/NotFound"
409:
$ref: "#/components/responses/NotFound"
500:
$ref: "#/components/responses/InternalError"

View file

@ -1,6 +1,8 @@
package de.hmmh.pmt;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.hmmh.pmt.dtos.CreateProjectDTO;
import de.hmmh.pmt.dtos.CreatedProjectDTO;
import de.hmmh.pmt.employee.ApiClientFactory;
import de.hmmh.pmt.db.Project;
import de.hmmh.pmt.db.ProjectRepository;
@ -9,9 +11,11 @@ import de.hmmh.pmt.dtos.GetAllProjectsDTO;
import de.hmmh.pmt.dtos.ProjectInfo;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestClientException;
import java.util.Optional;
@ -22,8 +26,6 @@ public class ApiController implements DefaultApi {
private ApiClientFactory apiClientFactory;
@Autowired
private ProjectRepository projectRepository;
// apiClientFactory.getEmployeeApi().findAll1()
@Override
public Optional<ObjectMapper> getObjectMapper() {
@ -48,4 +50,20 @@ public class ApiController implements DefaultApi {
return ResponseEntity.ok(response);
}
@Override
public ResponseEntity<CreatedProjectDTO> createProject(CreateProjectDTO body) {
if (projectRepository.existsByName(body.getTitle())){
return new ResponseEntity<>(HttpStatus.CONFLICT);
}
try {
if (apiClientFactory.getEmployeeApi().findById(body.getAdministratorId()).getId() == body.getAdministratorId()){
}
} catch (RestClientException exception){
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
return null;
}
}

View file

@ -3,4 +3,5 @@ package de.hmmh.pmt.db;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ProjectRepository extends JpaRepository<Project, Long> {
boolean existsByName(String name);
}