diff --git a/oparl-server/src/main/java/de/twomartens/oparlservice/control/OParlController.java b/oparl-server/src/main/java/de/twomartens/oparlservice/control/OParlController.java index a322091..ca9fa9d 100644 --- a/oparl-server/src/main/java/de/twomartens/oparlservice/control/OParlController.java +++ b/oparl-server/src/main/java/de/twomartens/oparlservice/control/OParlController.java @@ -1,7 +1,7 @@ package de.twomartens.oparlservice.control; -import de.twomartens.oparlservice.entity.dto.*; import de.twomartens.oparlservice.entity.dto.System; +import de.twomartens.oparlservice.entity.dto.*; import de.twomartens.oparlservice.service.OParlService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -25,44 +25,50 @@ public class OParlController { @GetMapping("/agendaItem/{id}") @Operation(summary = "information about agenda item", description = "returns the requested agenda item", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = Body.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = Body.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public AgendaItem agendaItem( - @PathVariable - @Parameter(description = "agendaItem ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "agendaItem ID", example = "0") + String id) { log.info("invoked method /v1.1/agendaItem/{}", id); return service.getAgendaItem(id).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Kein Tagesordnungspunkt mit angefragter ID existiert"); }); } - @GetMapping("/body/{id}/agendaItems") + @GetMapping(value = {"/body/{id}/agendaItems", "/body/{id}/agendaItems/{pageNumber}"}) @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.ObjectListAgendaItem.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + 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.ObjectListAgendaItem.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public ObjectList agendaItemsInBody( - @PathVariable - @Parameter(description = "body ID", example = "0") - String id) { - log.info("invoked method /v1.1/body/{}/agendaItems", id); - return service.getAgendaItemsInBody(id).orElseThrow(() -> { + @PathVariable + @Parameter(description = "body ID", example = "0") + String id, + @PathVariable(required = false) + @Parameter(description = "page number", example = "1") + Integer pageNumber) { + log.info("invoked method /v1.1/body/{}/agendaItems/{}", id, pageNumber); + if (pageNumber == null) { + pageNumber = 1; + } + return service.getAgendaItemsInBody(id, pageNumber).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); }); } @GetMapping("/bodies") @Operation(summary = "List of available bodies", - description = "returns a list of available bodies in this OParl system", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListBody.class))) + description = "returns a list of available bodies in this OParl system", responses = { + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListBody.class))) }) public ObjectList bodies() { log.info("method invoked /v1.1/bodies"); @@ -71,15 +77,15 @@ public class OParlController { @GetMapping("/body/{id}") @Operation(summary = "information about body", description = "returns information about the requested body", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = Body.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = Body.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public Body body( - @PathVariable - @Parameter(description = "body ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "body ID", example = "0") + String id) { log.info("method invoked /v1.1/body/{}", id); return service.getBody(id).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Körperschaft mit angefragter ID existiert nicht"); @@ -88,244 +94,292 @@ public class OParlController { @GetMapping("/consultation/{id}") @Operation(summary = "information about consultation", description = "returns the requested consultation", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = Consultation.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = Consultation.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public Consultation consultation( - @PathVariable - @Parameter(description = "consultation ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "consultation ID", example = "0") + String id) { log.info("invoked method /v1.1/consultation/{}", id); return service.getConsultation(id).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Beratung mit angefragter ID existiert"); }); } - @GetMapping("/body/{id}/consultations") + @GetMapping(value = {"/body/{id}/consultations", "/body/{id}/consultations/{pageNumber}"}) @Operation(summary = "List of all consultations in body", - description = "returns a list of all consultations in requested body", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListConsultation.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + description = "returns a list of all consultations in requested body", responses = { + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListConsultation.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public ObjectList consultationsInBody( - @PathVariable - @Parameter(description = "body ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "body ID", example = "0") + String id, + @PathVariable(required = false) + @Parameter(description = "page number", example = "1") + Integer pageNumber) { log.info("invoked method /v1.1/body/{}/consultations", id); - return service.getConsultationsInBody(id).orElseThrow(() -> { + if (pageNumber == null) { + pageNumber = 1; + } + return service.getConsultationsInBody(id, pageNumber).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); }); } @GetMapping("/file/{id}") @Operation(summary = "information about file", description = "returns the requested file", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = File.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = File.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public File file( - @PathVariable - @Parameter(description = "file ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "file ID", example = "0") + String id) { log.info("invoked method /v1.1/file/{}", id); return service.getFile(id).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Datei mit angefragter ID existiert"); }); } - @GetMapping("/body/{id}/files") + @GetMapping(value = {"/body/{id}/files", "/body/{id}/files/{pageNumber}"}) @Operation(summary = "List of all files in body", - description = "returns a list of all files in requested body", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListFile.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + description = "returns a list of all files in requested body", responses = { + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListFile.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public ObjectList filesInBody( - @PathVariable - @Parameter(description = "body ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "body ID", example = "0") + String id, + @PathVariable(required = false) + @Parameter(description = "page number", example = "1") + Integer pageNumber) { log.info("invoked method /v1.1/body/{}/files", id); - return service.getFilesInBody(id).orElseThrow(() -> { + if (pageNumber == null) { + pageNumber = 1; + } + return service.getFilesInBody(id, pageNumber).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); }); } @GetMapping("/legislativeTerm/{id}") @Operation(summary = "information about legislative term", description = "returns information about the requested legislative term", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = LegislativeTerm.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = LegislativeTerm.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public LegislativeTerm legislativeTerm( - @PathVariable - @Parameter(description = "legislative term ID", example = "21") - String id) { + @PathVariable + @Parameter(description = "legislative term ID", example = "21") + String id) { log.info("method invoked /v1.1/legislativeTerm/{}", id); return service.getLegislativeTerm(id).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Legislaturperiode mit angefragter ID existiert nicht"); }); } - @GetMapping("/body/{id}/legislativeTerms") + @GetMapping(value = {"/body/{id}/legislativeTerms", "/body/{id}/legislativeTerms/{pageNumber}"}) @Operation(summary = "List of all legislative terms of a body", description = "returns a list of all legislative terms of requested body", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListLegislativeTerm.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListLegislativeTerm.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public ObjectList legislativeTermsOfBody( - @PathVariable - @Parameter(description = "body ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "body ID", example = "0") + String id, + @PathVariable(required = false) + @Parameter(description = "page number", example = "1") + Integer pageNumber) { log.info("invoked method /v1.1/body/{}/legislativeTerms", id); - return service.getLegislativeTermsOfBody(id).orElseThrow(() -> { + if (pageNumber == null) { + pageNumber = 1; + } + return service.getLegislativeTermsOfBody(id, pageNumber).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); }); } @GetMapping("/location/{id}") @Operation(summary = "information about location", description = "returns the requested location", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = Location.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = Location.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public Location location( - @PathVariable - @Parameter(description = "location ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "location ID", example = "0") + String id) { log.info("invoked method /v1.1/location/{}", id); return service.getLocation(id).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Kein Ort mit angefragter ID existiert"); }); } - @GetMapping("/body/{id}/locations") + @GetMapping(value = {"/body/{id}/locations", "/body/{id}/locations/{pageNumber}"}) @Operation(summary = "List of all locations in body", - description = "returns a list of all locations in requested body", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListLocation.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + description = "returns a list of all locations in requested body", responses = { + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListLocation.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public ObjectList locationsInBody( - @PathVariable - @Parameter(description = "body ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "body ID", example = "0") + String id, + @PathVariable(required = false) + @Parameter(description = "page number", example = "1") + Integer pageNumber) { log.info("invoked method /v1.1/body/{}/locations", id); - return service.getLocationsInBody(id).orElseThrow(() -> { + if (pageNumber == null) { + pageNumber = 1; + } + return service.getLocationsInBody(id, pageNumber).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); }); } @GetMapping("/meeting/{id}") @Operation(summary = "information about meeting", description = "returns the requested meeting", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = Meeting.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = Meeting.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public Meeting meeting( - @PathVariable - @Parameter(description = "meeting ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "meeting ID", example = "0") + String id) { log.info("invoked method /v1.1/meeting/{}", id); return service.getMeeting(id).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Sitzung mit angefragter ID existiert"); }); } - @GetMapping("/body/{id}/meetings") + @GetMapping(value = {"/body/{id}/meetings", "/body/{id}/meetings/{pageNumber}"}) @Operation(summary = "List of all meetings in body", - description = "returns a list of all meetings in requested body", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListMeeting.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + description = "returns a list of all meetings in requested body", responses = { + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListMeeting.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public ObjectList meetingsInBody( - @PathVariable - @Parameter(description = "body ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "body ID", example = "0") + String id, + @PathVariable(required = false) + @Parameter(description = "page number", example = "1") + Integer pageNumber) { log.info("invoked method /v1.1/body/{}/meetings", id); - return service.getMeetingsInBody(id).orElseThrow(() -> { + if (pageNumber == null) { + pageNumber = 1; + } + return service.getMeetingsInBody(id, pageNumber).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); }); } - @GetMapping("/organization/{id}/meetings") + @GetMapping(value = {"/organization/{id}/meetings", "/organization/{id}/meetings/{pageNumber}"}) @Operation(summary = "List of all meetings in organization", - description = "returns a list of all meetings in requested organization", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListMeeting.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + description = "returns a list of all meetings in requested organization", responses = { + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListMeeting.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public ObjectList meetingsInOrganization( - @PathVariable - @Parameter(description = "organization ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "organization ID", example = "0") + String id, + @PathVariable(required = false) + @Parameter(description = "page number", example = "1") + Integer pageNumber) { log.info("invoked method /v1.1/organization/{}/meetings", id); - return service.getMeetingsInOrganization(id).orElseThrow(() -> { + if (pageNumber == null) { + pageNumber = 1; + } + return service.getMeetingsInOrganization(id, pageNumber).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Organisation mit angefragter ID existiert"); }); } @GetMapping("/membership/{id}") @Operation(summary = "information about membership", description = "returns the requested membership", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = Membership.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = Membership.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public Membership membership( - @PathVariable - @Parameter(description = "membership ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "membership ID", example = "0") + String id) { log.info("invoked method /v1.1/membership/{}", id); return service.getMembership(id).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Mitgliedschaft mit angefragter ID existiert"); }); } - @GetMapping("/body/{id}/memberships") + @GetMapping(value = {"/body/{id}/memberships", "/body/{id}/memberships/{pageNumber}"}) @Operation(summary = "List of all memberships in body", description = "returns a list of all memberships in requested body", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListMembership.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListMembership.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public ObjectList membershipsInBody( - @PathVariable - @Parameter(description = "body ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "body ID", example = "0") + String id, + @PathVariable(required = false) + @Parameter(description = "page number", example = "1") + Integer pageNumber) { log.info("invoked method /v1.1/body/{}/memberships", id); - return service.getMembershipsInBody(id).orElseThrow(() -> { + if (pageNumber == null) { + pageNumber = 1; + } + return service.getMembershipsInBody(id, pageNumber).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); }); } - @GetMapping("/organization/{id}/memberships") + @GetMapping(value = {"/organization/{id}/memberships", "/organization/{id}/memberships/{pageNumber}"}) @Operation(summary = "List of all memberships in organization", - description = "returns a list of all memberships in requested organization", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListMembership.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + description = "returns a list of all memberships in requested organization", responses = { + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListMembership.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public ObjectList membershipsInOrganization( - @PathVariable - @Parameter(description = "organization ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "organization ID", example = "0") + String id, + @PathVariable(required = false) + @Parameter(description = "page number", example = "1") + Integer pageNumber) { log.info("invoked method /v1.1/organization/{}/memberships", id); - return service.getMembershipsInOrganization(id).orElseThrow(() -> { + if (pageNumber == null) { + pageNumber = 1; + } + return service.getMembershipsInOrganization(id, pageNumber).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Organisation mit angefragter ID existiert"); }); } @@ -334,119 +388,137 @@ public class OParlController { @ResponseStatus(HttpStatus.NOT_FOUND) public ErrorObject notFound(ResponseStatusException exception) { return ErrorObject.builder() - .message(exception.getReason()) - .debug(exception.getLocalizedMessage()) - .build(); + .message(exception.getReason()) + .debug(exception.getLocalizedMessage()) + .build(); } @GetMapping("/organization/{id}") @Operation(summary = "information about organization", description = "returns the requested organization", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = Organization.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = Organization.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public Organization organization( - @PathVariable - @Parameter(description = "organization ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "organization ID", example = "0") + String id) { log.info("invoked method /v1.1/organization/{}", id); return service.getOrganization(id).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Organisation mit angefragter ID existiert"); }); } - @GetMapping("/body/{id}/organizations") + @GetMapping(value = {"/body/{id}/organizations", "/body/{id}/organizations/{pageNumber}"}) @Operation(summary = "List of all organizations in body", description = "returns a list of all organizations in requested body", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListOrganization.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListOrganization.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public ObjectList organizationsInBody( - @PathVariable - @Parameter(description = "body ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "body ID", example = "0") + String id, + @PathVariable(required = false) + @Parameter(description = "page number", example = "1") + Integer pageNumber) { log.info("invoked method /v1.1/body/{}/organizations", id); - return service.getOrganizationsInBody(id).orElseThrow(() -> { + if (pageNumber == null) { + pageNumber = 1; + } + return service.getOrganizationsInBody(id, pageNumber).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); }); } @GetMapping("/paper/{id}") @Operation(summary = "information about paper", description = "returns the requested paper", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = Paper.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = Paper.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public Paper paper( - @PathVariable - @Parameter(description = "paper ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "paper ID", example = "0") + String id) { log.info("invoked method /v1.1/paper/{}", id); return service.getPaper(id).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Drucksache mit angefragter ID existiert"); }); } - @GetMapping("/body/{id}/papers") + @GetMapping(value = {"/body/{id}/papers", "/body/{id}/papers/{pageNumber}"}) @Operation(summary = "List of all papers in body", - description = "returns a list of all papers in requested body", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListPaper.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + description = "returns a list of all papers in requested body", responses = { + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListPaper.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public ObjectList papersInBody( - @PathVariable - @Parameter(description = "body ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "body ID", example = "0") + String id, + @PathVariable(required = false) + @Parameter(description = "page number", example = "1") + Integer pageNumber) { log.info("invoked method /v1.1/body/{}/papers", id); - return service.getPapersInBody(id).orElseThrow(() -> { + if (pageNumber == null) { + pageNumber = 1; + } + return service.getPapersInBody(id, pageNumber).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); }); } @GetMapping("/person/{id}") @Operation(summary = "information about person", description = "returns the requested person", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = Person.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = Person.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public Person person( - @PathVariable - @Parameter(description = "person ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "person ID", example = "0") + String id) { log.info("invoked method /v1.1/person/{}", id); return service.getPerson(id).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Person mit angefragter ID existiert"); }); } - @GetMapping("/body/{id}/persons") + @GetMapping(value = {"/body/{id}/persons", "/body/{id}/persons/{pageNumber}"}) @Operation(summary = "List of all persons in body", description = "returns a list of all persons in requested body", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListPerson.class))), - @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", - schema = @Schema(implementation = ErrorObject.class))) + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListPerson.class))), + @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ErrorObject.class))) }) public ObjectList persons( - @PathVariable - @Parameter(description = "body ID", example = "0") - String id) { + @PathVariable + @Parameter(description = "body ID", example = "0") + String id, + @PathVariable(required = false) + @Parameter(description = "page number", example = "1") + Integer pageNumber) { log.info("invoked method /v1.1/body/{}/persons", id); - return service.getPersonsInBody(id).orElseThrow(() -> { + if (pageNumber == null) { + pageNumber = 1; + } + return service.getPersonsInBody(id, pageNumber).orElseThrow(() -> { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); }); } @GetMapping("/") @Operation(summary = "System information", description = "returns information about the OParl system", responses = { - @ApiResponse(description = "Successful Operation", responseCode = "200", content = @Content( - mediaType = "application/json", schema = @Schema(implementation = System.class) - )) + @ApiResponse(description = "Successful Operation", responseCode = "200", content = @Content( + mediaType = "application/json", schema = @Schema(implementation = System.class) + )) }) public System system() { log.info("method invoked /v1.1"); diff --git a/oparl-server/src/main/java/de/twomartens/oparlservice/service/OParlService.java b/oparl-server/src/main/java/de/twomartens/oparlservice/service/OParlService.java index c5c0d1b..09ca5c1 100644 --- a/oparl-server/src/main/java/de/twomartens/oparlservice/service/OParlService.java +++ b/oparl-server/src/main/java/de/twomartens/oparlservice/service/OParlService.java @@ -16,7 +16,7 @@ public class OParlService { this.properties = properties; } - public Optional> getAgendaItemsInBody(String bodyID) { + public Optional> getAgendaItemsInBody(String bodyID, int pageNumber) { return Optional.empty(); } @@ -32,7 +32,7 @@ public class OParlService { return Optional.empty(); } - public Optional> getConsultationsInBody(String bodyID) { + public Optional> getConsultationsInBody(String bodyID, int pageNumber) { return Optional.empty(); } @@ -40,7 +40,7 @@ public class OParlService { return Optional.empty(); } - public Optional> getFilesInBody(String bodyID) { + public Optional> getFilesInBody(String bodyID, int pageNumber) { return Optional.empty(); } @@ -48,7 +48,7 @@ public class OParlService { return Optional.empty(); } - public Optional> getLegislativeTermsOfBody(String bodyID) { + public Optional> getLegislativeTermsOfBody(String bodyID, int pageNumber) { return Optional.empty(); } @@ -56,7 +56,7 @@ public class OParlService { return Optional.empty(); } - public Optional> getLocationsInBody(String bodyID) { + public Optional> getLocationsInBody(String bodyID, int pageNumber) { return Optional.empty(); } @@ -68,11 +68,11 @@ public class OParlService { return Optional.empty(); } - public Optional> getMeetingsInBody(String bodyID) { + public Optional> getMeetingsInBody(String bodyID, int pageNumber) { return Optional.empty(); } - public Optional> getMeetingsInOrganization(String organizationID) { + public Optional> getMeetingsInOrganization(String organizationID, int pageNumber) { return Optional.empty(); } @@ -80,15 +80,15 @@ public class OParlService { return Optional.empty(); } - public Optional> getMembershipsInBody(String bodyID) { + public Optional> getMembershipsInBody(String bodyID, int pageNumber) { return Optional.empty(); } - public Optional> getMembershipsInOrganization(String organizationID) { + public Optional> getMembershipsInOrganization(String organizationID, int pageNumber) { return Optional.empty(); } - public Optional> getOrganizationsInBody(String bodyID) { + public Optional> getOrganizationsInBody(String bodyID, int pageNumber) { return Optional.empty(); } @@ -96,7 +96,7 @@ public class OParlService { return Optional.empty(); } - public Optional> getPapersInBody(String bodyID) { + public Optional> getPapersInBody(String bodyID, int pageNumber) { return Optional.empty(); } @@ -104,7 +104,7 @@ public class OParlService { return Optional.empty(); } - public Optional> getPersonsInBody(String bodyID) { + public Optional> getPersonsInBody(String bodyID, int pageNumber) { return Optional.empty(); } diff --git a/oparl-server/src/test/java/de/twomartens/oparlservice/control/OParlControllerTest.java b/oparl-server/src/test/java/de/twomartens/oparlservice/control/OParlControllerTest.java index d76c715..458f7eb 100644 --- a/oparl-server/src/test/java/de/twomartens/oparlservice/control/OParlControllerTest.java +++ b/oparl-server/src/test/java/de/twomartens/oparlservice/control/OParlControllerTest.java @@ -67,7 +67,7 @@ class OParlControllerTest { @Test void shouldReturnAgendaItemsInBody() throws Exception { - BDDMockito.given(service.getAgendaItemsInBody("0")) + BDDMockito.given(service.getAgendaItemsInBody("0", 1)) .willReturn(Optional.of( ObjectList.builder().data(List.of(testItem)).pagination(testPagination).links(testLinks).build() )); @@ -83,6 +83,34 @@ class OParlControllerTest { .andReturn(); } + @Test + void shouldAssumeFirstPage_WhenNoPageNumberGiven() throws Exception { + BDDMockito.given(service.getAgendaItemsInBody("0", 1)) + .willReturn(Optional.of( + ObjectList.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(); + + mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/agendaItems/1") + .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 shouldReturnBody() throws Exception { BDDMockito.given(service.getBody("0")) @@ -116,7 +144,7 @@ class OParlControllerTest { @Test void shouldReturnConsultationsInBody() throws Exception { - BDDMockito.given(service.getConsultationsInBody("0")) + BDDMockito.given(service.getConsultationsInBody("0", 1)) .willReturn(Optional.of( ObjectList.builder().data(List.of(testConsultation)).pagination(testPagination).links(testLinks).build() )); @@ -137,7 +165,7 @@ class OParlControllerTest { BDDMockito.given(service.getBody("2")) .willReturn(Optional.empty()); - BDDMockito.given(service.getMembershipsInBody("2")) + BDDMockito.given(service.getMembershipsInBody("2", 1)) .willReturn(Optional.empty()); mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/2") @@ -172,7 +200,7 @@ class OParlControllerTest { @Test void shouldReturnFilesInBody() throws Exception { - BDDMockito.given(service.getFilesInBody("0")) + BDDMockito.given(service.getFilesInBody("0", 1)) .willReturn(Optional.of( ObjectList.builder().data(List.of(testFile)).pagination(testPagination).links(testLinks).build() )); @@ -205,8 +233,8 @@ class OParlControllerTest { } @Test - void shouldReturnLegislativeTermsOFBody() throws Exception { - BDDMockito.given(service.getLegislativeTermsOfBody("0")) + void shouldReturnLegislativeTermsOfBody() throws Exception { + BDDMockito.given(service.getLegislativeTermsOfBody("0", 1)) .willReturn(Optional.of( ObjectList.builder().data(List.of(testTerm)).pagination(testPagination).links(testLinks).build() )); @@ -258,7 +286,7 @@ class OParlControllerTest { @Test void shouldReturnLocationsInBody() throws Exception { - BDDMockito.given(service.getLocationsInBody("0")) + BDDMockito.given(service.getLocationsInBody("0", 1)) .willReturn(Optional.of( ObjectList.builder().data(List.of(testLocation)).pagination(testPagination).links(testLinks).build() )); @@ -290,7 +318,7 @@ class OParlControllerTest { @Test void shouldReturnMeetingsInBody() throws Exception { - BDDMockito.given(service.getMeetingsInBody("0")) + BDDMockito.given(service.getMeetingsInBody("0", 1)) .willReturn(Optional.of( ObjectList.builder().data(List.of(testMeeting)).pagination(testPagination).links(testLinks).build() )); @@ -308,7 +336,7 @@ class OParlControllerTest { @Test void shouldReturnMeetingsInOrganization() throws Exception { - BDDMockito.given(service.getMeetingsInOrganization("0")) + BDDMockito.given(service.getMeetingsInOrganization("0", 1)) .willReturn(Optional.of( ObjectList.builder().data(List.of(testMeeting)).pagination(testPagination).links(testLinks).build() )); @@ -341,7 +369,7 @@ class OParlControllerTest { @Test void shouldReturnMembershipsInBody() throws Exception { - BDDMockito.given(service.getMembershipsInBody("0")) + BDDMockito.given(service.getMembershipsInBody("0", 1)) .willReturn(Optional.of( ObjectList.builder().data(List.of(testMembership)).pagination(testPagination).links(testLinks).build() )); @@ -359,7 +387,7 @@ class OParlControllerTest { @Test void shouldReturnMembershipsInOrganization() throws Exception { - BDDMockito.given(service.getMembershipsInOrganization("0")) + BDDMockito.given(service.getMembershipsInOrganization("0", 1)) .willReturn(Optional.of( ObjectList.builder().data(List.of(testMembership)).pagination(testPagination).links(testLinks).build() )); @@ -391,7 +419,7 @@ class OParlControllerTest { @Test void shouldReturnOrganizationsInBody() throws Exception { - BDDMockito.given(service.getOrganizationsInBody("0")) + BDDMockito.given(service.getOrganizationsInBody("0", 1)) .willReturn(Optional.of( ObjectList.builder().data(List.of(testOrganization, testPartyOrganization)).pagination(testPagination).links(testLinks).build() )); @@ -423,7 +451,7 @@ class OParlControllerTest { @Test void shouldReturnPapersInBody() throws Exception { - BDDMockito.given(service.getPapersInBody("0")) + BDDMockito.given(service.getPapersInBody("0", 1)) .willReturn(Optional.of( ObjectList.builder().data(List.of(testPaper)).pagination(testPagination).links(testLinks).build() )); @@ -455,7 +483,7 @@ class OParlControllerTest { @Test void shouldReturnPersonsInBody() throws Exception { - BDDMockito.given(service.getPersonsInBody("0")) + BDDMockito.given(service.getPersonsInBody("0", 1)) .willReturn(Optional.of( ObjectList.builder().data(List.of(testPerson)).pagination(testPagination).links(testLinks).build() ));