From ef8f7262d3b569b1de75309d40d07dc10ff9a47f Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Fri, 28 Jul 2023 13:20:43 +0200 Subject: [PATCH] Added endpoint to retrieve election by name --- .../controller/v1/ElectionController.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/module-server/src/main/java/de/twomartens/wahlrecht/controller/v1/ElectionController.java b/module-server/src/main/java/de/twomartens/wahlrecht/controller/v1/ElectionController.java index 30d1bba..d7e691e 100644 --- a/module-server/src/main/java/de/twomartens/wahlrecht/controller/v1/ElectionController.java +++ b/module-server/src/main/java/de/twomartens/wahlrecht/controller/v1/ElectionController.java @@ -4,6 +4,7 @@ import de.twomartens.wahlrecht.mapper.v1.ElectionMapper; import de.twomartens.wahlrecht.model.dto.v1.Election; import de.twomartens.wahlrecht.service.ElectionService; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -19,6 +20,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -55,6 +57,28 @@ public class ElectionController { .body(elections); } + @Operation( + summary = "Returns election matching provided name", + responses = { + @ApiResponse(responseCode = "200", + description = "Returns matching election", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = Election.class))} + ) + } + ) + @GetMapping(value = "/elections/by-name/{electionName}", produces = MediaType.APPLICATION_JSON_VALUE) + @SecurityRequirement(name = "bearerAuth") + @SecurityRequirement(name = "oauth2") + public ResponseEntity getElectionByName( + @PathVariable @Parameter(description = "the election name", example = "Bezirkswahl 2019") String electionName) { + Election election = mapper.mapToExternal(service.getElection(electionName)); + return ResponseEntity.ok() + .contentType(MediaType.APPLICATION_JSON) + .body(election); + } + @Operation( summary = "Stores a new election", responses = {