Removed thymeleaf endpoints
This commit is contained in:
+2
-2
@@ -3,6 +3,7 @@ package de.twomartens.wahlrecht.configuration;
|
|||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
@@ -23,8 +24,7 @@ public class WebSecurityConfiguration {
|
|||||||
http
|
http
|
||||||
.csrf().disable()
|
.csrf().disable()
|
||||||
.authorizeHttpRequests()
|
.authorizeHttpRequests()
|
||||||
.requestMatchers("/wahlrecht/v1/election", "/wahlrecht/v1/party/**",
|
.requestMatchers(HttpMethod.PUT, "/wahlrecht/v1/**")
|
||||||
"/wahlrecht/v1/nomination/**")
|
|
||||||
.authenticated()
|
.authenticated()
|
||||||
.and()
|
.and()
|
||||||
.authorizeHttpRequests()
|
.authorizeHttpRequests()
|
||||||
|
|||||||
-53
@@ -1,11 +1,8 @@
|
|||||||
package de.twomartens.wahlrecht.controller.v1;
|
package de.twomartens.wahlrecht.controller.v1;
|
||||||
|
|
||||||
import de.twomartens.wahlrecht.mapper.v1.ElectionMapper;
|
|
||||||
import de.twomartens.wahlrecht.mapper.v1.PartyInElectionMapper;
|
import de.twomartens.wahlrecht.mapper.v1.PartyInElectionMapper;
|
||||||
import de.twomartens.wahlrecht.model.dto.ErrorMessage;
|
import de.twomartens.wahlrecht.model.dto.ErrorMessage;
|
||||||
import de.twomartens.wahlrecht.model.dto.v1.Election;
|
|
||||||
import de.twomartens.wahlrecht.model.dto.v1.PartyInElection;
|
import de.twomartens.wahlrecht.model.dto.v1.PartyInElection;
|
||||||
import de.twomartens.wahlrecht.service.ElectionService;
|
|
||||||
import de.twomartens.wahlrecht.service.PartyService;
|
import de.twomartens.wahlrecht.service.PartyService;
|
||||||
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.Parameter;
|
||||||
@@ -24,11 +21,8 @@ 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.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
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;
|
||||||
@@ -41,9 +35,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
public class PartyController {
|
public class PartyController {
|
||||||
|
|
||||||
private final PartyInElectionMapper mapper = Mappers.getMapper(PartyInElectionMapper.class);
|
private final PartyInElectionMapper mapper = Mappers.getMapper(PartyInElectionMapper.class);
|
||||||
private final ElectionMapper electionMapper = Mappers.getMapper(ElectionMapper.class);
|
|
||||||
private final PartyService service;
|
private final PartyService service;
|
||||||
private final ElectionService electionService;
|
|
||||||
|
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Returns all stored parties for given election name",
|
summary = "Returns all stored parties for given election name",
|
||||||
@@ -97,49 +89,4 @@ public class PartyController {
|
|||||||
? new ResponseEntity<>(HttpStatus.CREATED)
|
? new ResponseEntity<>(HttpStatus.CREATED)
|
||||||
: new ResponseEntity<>(HttpStatus.OK);
|
: new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/party")
|
|
||||||
public String submitCreatePartyForm(@ModelAttribute PartyInElection party, Model model) {
|
|
||||||
service.storeParty(mapper.mapToDB(party));
|
|
||||||
model.addAttribute("party", party);
|
|
||||||
model.addAttribute("isCreate", false);
|
|
||||||
return "partyUpdate";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/party")
|
|
||||||
public String createPartyForm(Model model) {
|
|
||||||
model.addAttribute("party", new PartyInElection());
|
|
||||||
model.addAttribute("isCreate", true);
|
|
||||||
return "partyCreate";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/party/{electionName}/{abbreviation}")
|
|
||||||
public String submitUpdatePartyForm(
|
|
||||||
@PathVariable String electionName,
|
|
||||||
@PathVariable String abbreviation,
|
|
||||||
@ModelAttribute PartyInElection party,
|
|
||||||
Model model) {
|
|
||||||
return submitCreatePartyForm(party, model);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/party/{electionName}/{abbreviation}")
|
|
||||||
public String updatePartyForm(
|
|
||||||
@PathVariable String electionName,
|
|
||||||
@PathVariable String abbreviation,
|
|
||||||
Model model) {
|
|
||||||
PartyInElection party = mapper.mapToExternal(
|
|
||||||
service.getPartyByElectionNameAndAbbreviation(electionName, abbreviation));
|
|
||||||
model.addAttribute("party", party);
|
|
||||||
model.addAttribute("isCreate", false);
|
|
||||||
|
|
||||||
return "partyUpdate";
|
|
||||||
}
|
|
||||||
|
|
||||||
@ModelAttribute("elections")
|
|
||||||
Collection<Election> elections() {
|
|
||||||
return electionService.getElections().stream()
|
|
||||||
.map(electionMapper::mapToExternal)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" lang="de">
|
|
||||||
<head th:fragment="head">
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<title th:text="${party}"></title>
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
|
|
||||||
rel="stylesheet"
|
|
||||||
integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM"
|
|
||||||
crossorigin="anonymous">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<form action="#" th:action="@{/wahlrecht/v1/party}"
|
|
||||||
th:object="${party}" method="post">
|
|
||||||
<div>
|
|
||||||
<label for="electionName" class="form-label">Wahlname</label>
|
|
||||||
<select name="electionName" id="electionName" class="form-select"
|
|
||||||
th:field="*{electionName}">
|
|
||||||
<option th:each="election : ${elections}" th:text="${election.name()}"
|
|
||||||
th:value="${election.name()}"></option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="partyAbbreviation" class="form-label">Parteiabkürzung</label>
|
|
||||||
<input type="text" name="abbreviation" id="partyAbbreviation" class="form-control"
|
|
||||||
th:field="*{abbreviation}">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="partyName" class="form-label">Parteiname</label>
|
|
||||||
<input type="text" name="name" id="partyName" class="form-control"
|
|
||||||
th:field="*{name}">
|
|
||||||
</div>
|
|
||||||
<div class="mt-3">
|
|
||||||
<button type="submit" class="btn btn-primary"
|
|
||||||
th:text="${party.name} != null ? 'Aktualisieren' : 'Erstellen'">
|
|
||||||
Erstellen
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
|
|
||||||
integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
|
|
||||||
crossorigin="anonymous"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" lang="de">
|
|
||||||
<head th:fragment="head">
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<title th:text="${party}"></title>
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
|
|
||||||
rel="stylesheet"
|
|
||||||
integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM"
|
|
||||||
crossorigin="anonymous">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<form action="#" th:action="@{/wahlrecht/v1/party/{electionName}/{abbreviation}(electionName=${party.electionName}, abbreviation=${party.abbreviation})}"
|
|
||||||
th:object="${party}" method="post">
|
|
||||||
<div>
|
|
||||||
<label for="electionName" class="form-label">Wahlname</label>
|
|
||||||
<select name="electionName" id="electionName" class="form-select"
|
|
||||||
th:field="*{electionName}">
|
|
||||||
<option th:each="election : ${elections}" th:text="${election.name()}"
|
|
||||||
th:value="${election.name()}"></option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="partyAbbreviation" class="form-label">Parteiabkürzung</label>
|
|
||||||
<input type="text" name="abbreviation" id="partyAbbreviation" class="form-control"
|
|
||||||
th:field="*{abbreviation}">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="partyName" class="form-label">Parteiname</label>
|
|
||||||
<input type="text" name="name" id="partyName" class="form-control"
|
|
||||||
th:field="*{name}">
|
|
||||||
</div>
|
|
||||||
<div class="mt-3">
|
|
||||||
<button type="submit" class="btn btn-primary"
|
|
||||||
th:text="${party.name} != null ? 'Aktualisieren' : 'Erstellen'">
|
|
||||||
Erstellen
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
|
|
||||||
integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
|
|
||||||
crossorigin="anonymous"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user