diff --git a/api/pmt.yml b/api/pmt.yml index fbcab1e..4640111 100644 --- a/api/pmt.yml +++ b/api/pmt.yml @@ -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" \ No newline at end of file diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index 5031841..b28479e 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -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 getObjectMapper() { @@ -48,4 +50,20 @@ public class ApiController implements DefaultApi { return ResponseEntity.ok(response); } + + @Override + public ResponseEntity 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; + } } diff --git a/src/main/java/de/hmmh/pmt/db/ProjectRepository.java b/src/main/java/de/hmmh/pmt/db/ProjectRepository.java index ef501dc..bb02ece 100644 --- a/src/main/java/de/hmmh/pmt/db/ProjectRepository.java +++ b/src/main/java/de/hmmh/pmt/db/ProjectRepository.java @@ -3,4 +3,5 @@ package de.hmmh.pmt.db; import org.springframework.data.jpa.repository.JpaRepository; public interface ProjectRepository extends JpaRepository { + boolean existsByName(String name); }