PMT-15: Projekte löschen #11
3 changed files with 68 additions and 1 deletions
28
api/pmt.yml
28
api/pmt.yml
|
@ -51,4 +51,30 @@ paths:
|
||||||
401:
|
401:
|
||||||
$ref: "#/components/responses/UnAuthorized"
|
$ref: "#/components/responses/UnAuthorized"
|
||||||
500:
|
500:
|
||||||
$ref: "#/components/responses/InternalError"
|
$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"
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,16 @@ public class ApiController implements DefaultApi {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> deleteProject(Long id) {
|
||||||
|
if (!projectRepository.existsById(id)) {
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
projectRepository.deleteById(id);
|
||||||
|
return ResponseEntity.noContent().build();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<GetAllProjectsDTO> getAllProjects() {
|
public ResponseEntity<GetAllProjectsDTO> getAllProjects() {
|
||||||
GetAllProjectsDTO response = new GetAllProjectsDTO();
|
GetAllProjectsDTO response = new GetAllProjectsDTO();
|
||||||
|
|
31
src/test/java/de/hmmh/pmt/project/DeleteTest.java
Normal file
31
src/test/java/de/hmmh/pmt/project/DeleteTest.java
Normal file
|
@ -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<String,Project> allProjects = createTestProjectData();
|
||||||
|
mvc
|
||||||
|
.perform(delete(baseUri + "/project/" + allProjects.get("space-station").getId()))
|
||||||
|
.andExpect(status().isNoContent())
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue