Added endpoint to retrieve election by name
This commit is contained in:
+24
@@ -4,6 +4,7 @@ import de.twomartens.wahlrecht.mapper.v1.ElectionMapper;
|
|||||||
import de.twomartens.wahlrecht.model.dto.v1.Election;
|
import de.twomartens.wahlrecht.model.dto.v1.Election;
|
||||||
import de.twomartens.wahlrecht.service.ElectionService;
|
import de.twomartens.wahlrecht.service.ElectionService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
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.ArraySchema;
|
||||||
import io.swagger.v3.oas.annotations.media.Content;
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
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.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
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.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -55,6 +57,28 @@ public class ElectionController {
|
|||||||
.body(elections);
|
.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<Election> 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(
|
@Operation(
|
||||||
summary = "Stores a new election",
|
summary = "Stores a new election",
|
||||||
responses = {
|
responses = {
|
||||||
|
|||||||
Reference in New Issue
Block a user