Browse Source

Added pagination support to object list requests

master
Jim Martens 10 months ago
parent
commit
4022711f1a
  1. 480
      oparl-server/src/main/java/de/twomartens/oparlservice/control/OParlController.java
  2. 24
      oparl-server/src/main/java/de/twomartens/oparlservice/service/OParlService.java
  3. 56
      oparl-server/src/test/java/de/twomartens/oparlservice/control/OParlControllerTest.java

480
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<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(() -> {
@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<Body> 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<Consultation> 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<File> 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<LegislativeTerm> 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<Location> 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<Meeting> 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<Meeting> 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<Membership> 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<Membership> 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<Organization> 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<Paper> 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<Person> 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");

24
oparl-server/src/main/java/de/twomartens/oparlservice/service/OParlService.java

@ -16,7 +16,7 @@ public class OParlService {
this.properties = properties;
}
public Optional<ObjectList<AgendaItem>> getAgendaItemsInBody(String bodyID) {
public Optional<ObjectList<AgendaItem>> getAgendaItemsInBody(String bodyID, int pageNumber) {
return Optional.empty();
}
@ -32,7 +32,7 @@ public class OParlService {
return Optional.empty();
}
public Optional<ObjectList<Consultation>> getConsultationsInBody(String bodyID) {
public Optional<ObjectList<Consultation>> getConsultationsInBody(String bodyID, int pageNumber) {
return Optional.empty();
}
@ -40,7 +40,7 @@ public class OParlService {
return Optional.empty();
}
public Optional<ObjectList<File>> getFilesInBody(String bodyID) {
public Optional<ObjectList<File>> getFilesInBody(String bodyID, int pageNumber) {
return Optional.empty();
}
@ -48,7 +48,7 @@ public class OParlService {
return Optional.empty();
}
public Optional<ObjectList<LegislativeTerm>> getLegislativeTermsOfBody(String bodyID) {
public Optional<ObjectList<LegislativeTerm>> getLegislativeTermsOfBody(String bodyID, int pageNumber) {
return Optional.empty();
}
@ -56,7 +56,7 @@ public class OParlService {
return Optional.empty();
}
public Optional<ObjectList<Location>> getLocationsInBody(String bodyID) {
public Optional<ObjectList<Location>> getLocationsInBody(String bodyID, int pageNumber) {
return Optional.empty();
}
@ -68,11 +68,11 @@ public class OParlService {
return Optional.empty();
}
public Optional<ObjectList<Meeting>> getMeetingsInBody(String bodyID) {
public Optional<ObjectList<Meeting>> getMeetingsInBody(String bodyID, int pageNumber) {
return Optional.empty();
}
public Optional<ObjectList<Meeting>> getMeetingsInOrganization(String organizationID) {
public Optional<ObjectList<Meeting>> getMeetingsInOrganization(String organizationID, int pageNumber) {
return Optional.empty();
}
@ -80,15 +80,15 @@ public class OParlService {
return Optional.empty();
}
public Optional<ObjectList<Membership>> getMembershipsInBody(String bodyID) {
public Optional<ObjectList<Membership>> getMembershipsInBody(String bodyID, int pageNumber) {
return Optional.empty();
}
public Optional<ObjectList<Membership>> getMembershipsInOrganization(String organizationID) {
public Optional<ObjectList<Membership>> getMembershipsInOrganization(String organizationID, int pageNumber) {
return Optional.empty();
}
public Optional<ObjectList<Organization>> getOrganizationsInBody(String bodyID) {
public Optional<ObjectList<Organization>> getOrganizationsInBody(String bodyID, int pageNumber) {
return Optional.empty();
}
@ -96,7 +96,7 @@ public class OParlService {
return Optional.empty();
}
public Optional<ObjectList<Paper>> getPapersInBody(String bodyID) {
public Optional<ObjectList<Paper>> getPapersInBody(String bodyID, int pageNumber) {
return Optional.empty();
}
@ -104,7 +104,7 @@ public class OParlService {
return Optional.empty();
}
public Optional<ObjectList<Person>> getPersonsInBody(String bodyID) {
public Optional<ObjectList<Person>> getPersonsInBody(String bodyID, int pageNumber) {
return Optional.empty();
}

56
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.<AgendaItem>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.<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();
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.<Consultation>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.<File>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.<LegislativeTerm>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.<Location>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.<Meeting>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.<Meeting>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.<Membership>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.<Membership>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.<Organization>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.<Paper>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.<Person>builder().data(List.of(testPerson)).pagination(testPagination).links(testLinks).build()
));

Loading…
Cancel
Save