Added operation to request all agenda items in a body

This commit is contained in:
Jim Martens 2020-07-11 21:11:36 +02:00
parent c3c20d9ecf
commit d2b8ae5b6d
3 changed files with 40 additions and 0 deletions

View File

@ -252,6 +252,24 @@ public class OParlController {
});
}
@GetMapping("/body/{id}/agendaItems")
@Operation(summary = "List of all agenda items in body",
description = "returns a list of all agenda items in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<AgendaItem> agendaItemsInBody(
@PathVariable
@Parameter(description = "body ID", example = "0")
String id) {
log.info("invoked method /v1.1/body/{}/agendaItems", id);
return service.getAgendaItemsInBody(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
});
}
@GetMapping("/agendaItem/{id}")
@Operation(summary = "information about agenda item", description = "returns the requested agenda item", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",

View File

@ -16,6 +16,10 @@ public class OParlService {
this.properties = properties;
}
public Optional<ObjectList<AgendaItem>> getAgendaItemsInBody(String bodyID) {
return Optional.empty();
}
public Optional<AgendaItem> getAgendaItem(String id) {
return Optional.empty();
}

View File

@ -303,6 +303,24 @@ class OParlControllerTest {
.andReturn();
}
@Test
void shouldReturnAgendaItemsInBody() throws Exception {
BDDMockito.given(service.getAgendaItemsInBody("0"))
.willReturn(Optional.of(
ObjectList.<AgendaItem>builder().data(List.of(testItem)).pagination(testPagination).links(testLinks).build()
));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/agendaItems")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(11)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/AgendaItem")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnAgendaItem() throws Exception {
BDDMockito.given(service.getAgendaItem("0"))