diff --git a/api/pmt.yml b/api/pmt.yml index fbcab1e..8c70a51 100644 --- a/api/pmt.yml +++ b/api/pmt.yml @@ -51,4 +51,30 @@ paths: 401: $ref: "#/components/responses/UnAuthorized" 500: - $ref: "#/components/responses/InternalError" \ No newline at end of file + $ref: "#/components/responses/InternalError" + + /project/{id}: + delete: + operationId: "deleteProject" + description: "Delete a specific Project" + parameters: + - in: path + name: id + schema: + type: integer + format: int64 + required: true + responses: + 204: + description: "Deletes a specific Project" + 401: + $ref: "#/components/responses/UnAuthorized" + 404: + description: "Project not found" + content: + text/plain: + schema: + type: string + 500: + $ref: "#/components/responses/InternalError" + diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index 5031841..bc05059 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -35,6 +35,16 @@ public class ApiController implements DefaultApi { return Optional.empty(); } + @Override + public ResponseEntity deleteProject(Long id) { + if (!projectRepository.existsById(id)) { + return ResponseEntity.notFound().build(); + } + + projectRepository.deleteById(id); + return ResponseEntity.noContent().build(); + } + @Override public ResponseEntity getAllProjects() { GetAllProjectsDTO response = new GetAllProjectsDTO(); diff --git a/src/test/java/de/hmmh/pmt/project/DeleteTest.java b/src/test/java/de/hmmh/pmt/project/DeleteTest.java new file mode 100644 index 0000000..25a95ba --- /dev/null +++ b/src/test/java/de/hmmh/pmt/project/DeleteTest.java @@ -0,0 +1,31 @@ +package de.hmmh.pmt.project; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import de.hmmh.pmt.IntegrationTest; +import de.hmmh.pmt.db.Project; + +public class DeleteTest extends IntegrationTest { + @Test + void projectNotFound() throws Exception { + mvc + .perform(delete(baseUri + "/project/1")) + .andExpect(status().isNotFound()) + ; + } + + @Test + void deletedSuccessfully() throws Exception { + Map allProjects = createTestProjectData(); + mvc + .perform(delete(baseUri + "/project/" + allProjects.get("space-station").getId())) + .andExpect(status().isNoContent()) + ; + } +}