Correciones menores

This commit is contained in:
Javier 2021-03-31 17:41:15 +02:00
parent 47eee25602
commit ce0ee43e79
8 changed files with 137 additions and 26 deletions

View file

@ -30,6 +30,17 @@ public class FoodOfferController {
this.foodOfferService = foodOfferService;
this.clientService = clientService;
}
private boolean checkIdentity(final int foodOfferId) {
boolean res = false;
Client client = this.clientService.getCurrentClient();
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
Client clientOffer = foodOffer.getClient();
if (client.equals(clientOffer)) {
res = true;
}
return res;
}
@GetMapping("/offers/food/new")
public String initCreationForm(Map<String, Object> model) {
@ -75,7 +86,6 @@ public class FoodOfferController {
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/food/foodOffersShow";
}
@ -83,14 +93,21 @@ public class FoodOfferController {
@GetMapping(value = "/offers/food/{foodOfferId}/edit")
public String updateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) {
if (!this.checkIdentity(foodOfferId)) {
return "error";
}
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
model.addAttribute("foodOffer", foodOffer);
return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
}
@PostMapping(value = "/offers/food/{foodOfferId}/edit")
public String updateFoodOffer(@Valid final FoodOffer foodOfferEdit, final BindingResult result,
final ModelMap model) {
public String updateFoodOffer(@Valid final FoodOffer foodOfferEdit, final BindingResult result, final ModelMap model) {
if (!this.checkIdentity(foodOfferEdit.getId())) {
return "error";
}
if (result.hasErrors()) {
model.addAttribute("foodOffer", foodOfferEdit);
@ -104,16 +121,22 @@ public class FoodOfferController {
@GetMapping(value = "/offers/food/{foodOfferId}/disable")
public String disableFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) {
if (!this.checkIdentity(foodOfferId)) {
return "error";
}
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
model.put("foodOffer", foodOffer);
return "foodOffers/foodOffersDisable";
return "offers/food/foodOffersDisable";
}
@PostMapping(value = "/offers/food/{foodOfferId}/disable")
public String disableFoodOfferForm(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) {
if (!this.checkIdentity(foodOfferId)) {
return "error";
}
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
@ -121,7 +144,7 @@ public class FoodOfferController {
this.foodOfferService.saveFoodOffer(foodOffer);
return "redirect:/offers";
return "redirect:/myOffers";
}
}

View file

@ -38,6 +38,17 @@ public class NuOfferController {
model.put("nuOffer", nuOffer);
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
}
private boolean checkIdentity(final int nuOfferId) {
boolean res = false;
Client client = this.clientService.getCurrentClient();
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
Client clientOffer = nuOffer.getClient();
if (client.equals(clientOffer)) {
res = true;
}
return res;
}
@PostMapping("/offers/nu/new")
public String processCreationForm(@Valid NuOffer nuOffer, BindingResult result) {
@ -83,7 +94,10 @@ public class NuOfferController {
@GetMapping(value = "/offers/nu/{nuOfferId}/edit")
public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap model) {
if (!this.checkIdentity(nuOfferId)) {
return "error";
}
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
model.addAttribute("nuOffer", nuOffer);
@ -92,6 +106,10 @@ public class NuOfferController {
@PostMapping(value = "/offers/nu/{nuOfferId}/edit")
public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final ModelMap model) {
if (!this.checkIdentity(nuOfferEdit.getId())) {
return "error";
}
if (result.hasErrors()) {
model.addAttribute("nuOffer", nuOfferEdit);
@ -104,24 +122,28 @@ public class NuOfferController {
}
@GetMapping(value = "/offers/nu/{nuOfferId}/disable")
public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal,
final ModelMap model) {
public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) {
if (!this.checkIdentity(nuOfferId)) {
return "error";
}
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
model.put("nuOffer", nuOffer);
return "nuOffers/nuOffersDisable";
return "offers/nu/nuOffersDisable";
}
@PostMapping(value = "/offers/nu/{nuOfferId}/disable")
public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal,
final ModelMap model) {
public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) {
if (!this.checkIdentity(nuOfferId)) {
return "error";
}
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
nuOffer.setStatus(StatusOffer.inactive);
this.nuOfferService.saveNuOffer(nuOffer);
return "redirect:/offers";
return "redirect:/myOffers";
}

View file

@ -29,7 +29,17 @@ public class SpeedOfferController {
this.speedOfferService = speedOfferService;
this.clientService = clientService;
}
private boolean checkIdentity(final int speedOfferId) {
boolean res = false;
Client client = this.clientService.getCurrentClient();
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
Client clientOffer = speedOffer.getClient();
if (client.equals(clientOffer)) {
res = true;
}
return res;
}
@GetMapping("/offers/speed/new")
public String initCreationForm(Map<String, Object> model) {
@ -79,6 +89,10 @@ public class SpeedOfferController {
@GetMapping(value = "/offers/speed/{speedOfferId}/edit")
public String updateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) {
if (!this.checkIdentity(speedOfferId)) {
return "error";
}
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
model.addAttribute("speedOffer", speedOffer);
return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
@ -87,6 +101,10 @@ public class SpeedOfferController {
@PostMapping(value = "/offers/speed/{speedOfferId}/edit")
public String updateSpeedOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, final ModelMap model) {
if (!this.checkIdentity(speedOfferEdit.getId())) {
return "error";
}
if (result.hasErrors()) {
model.addAttribute("speedOffer", speedOfferEdit);
return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
@ -100,16 +118,22 @@ public class SpeedOfferController {
@GetMapping(value = "/offers/speed/{speedOfferId}/disable")
public String disableSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) {
if (!this.checkIdentity(speedOfferId)) {
return "error";
}
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
model.put("speedOffer", speedOffer);
return "speedOffers/speedOffersDisable";
return "offers/speed/speedOffersDisable";
}
@PostMapping(value = "/offers/speed/{speedOfferId}/disable")
public String disableSpeedOfferForm(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) {
if (!this.checkIdentity(speedOfferId)) {
return "error";
}
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
@ -117,7 +141,7 @@ public class SpeedOfferController {
this.speedOfferService.saveSpeedOffer(speedOffer);
return "redirect:/offers";
return "redirect:/myOffers";
}
}

View file

@ -21,7 +21,6 @@ import org.springframework.web.bind.annotation.PostMapping;
@Controller
public class TimeOfferController {
private static final String VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM = "offers/time/createOrUpdateTimeOfferForm";
private final TimeOfferService timeOfferService;
private final ClientService clientService;
@ -30,6 +29,17 @@ public class TimeOfferController {
this.timeOfferService = timeOfferService;
this.clientService = clientService;
}
private boolean checkIdentity(final int timeOfferId) {
boolean res = false;
Client client = this.clientService.getCurrentClient();
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
Client clientOffer = timeOffer.getClient();
if (client.equals(clientOffer)) {
res = true;
}
return res;
}
@GetMapping("/offers/time/new")
public String initCreationForm(Map<String, Object> model) {
@ -88,6 +98,9 @@ public class TimeOfferController {
@GetMapping(value = "/offers/time/{timeOfferId}/edit")
public String updateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) {
if (!this.checkIdentity(timeOfferId)) {
return "error";
}
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
model.addAttribute("timeOffer", timeOffer);
@ -97,6 +110,9 @@ public class TimeOfferController {
@PostMapping(value = "/offers/time/{timeOfferId}/edit")
public String updateTimeOffer(@Valid final TimeOffer timeOfferEdit, final BindingResult result, final ModelMap model) {
if (!this.checkIdentity(timeOfferEdit.getId())) {
return "error";
}
if (result.hasErrors()) {
model.addAttribute("timeOffer", timeOfferEdit);
@ -111,16 +127,22 @@ public class TimeOfferController {
@GetMapping(value = "/offers/time/{timeOfferId}/disable")
public String disableTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) {
if (!this.checkIdentity(timeOfferId)) {
return "error";
}
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
model.put("timeOffer", timeOffer);
return "timeOffers/timeOffersDisable";
return "offers/time/timeOffersDisable";
}
@PostMapping(value = "/offers/time/{timeOfferId}/disable")
public String disableTimeOfferForm(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) {
if (!this.checkIdentity(timeOfferId)) {
return "error";
}
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
@ -128,7 +150,7 @@ public class TimeOfferController {
this.timeOfferService.saveTimeOffer(timeOffer);
return "redirect:/offers";
return "redirect:/myOffers";
}

View file

@ -4,6 +4,7 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
<cheapy:layout pageName="foodOffer">
@ -44,15 +45,19 @@
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true" style="padding: 5px"> </span>
<fmt:message key="return"/> </button>
</div>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{foodOfferId}/edit" var="editUrl">
<spring:param name="foodOfferId" value="${foodOffer.id}"/>
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar oferta</a>
</sec:authorize>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{foodOfferId}/disable" var="editUrl">
<spring:param name="foodOfferId" value="${foodOffer.id}"/>
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar oferta</a>
</sec:authorize>
</cheapy:layout>

View file

@ -4,6 +4,7 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
<cheapy:layout pageName="nuOffer">
@ -55,15 +56,19 @@
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true" style="padding: 5px"> </span>
<fmt:message key="return"/> </button>
</div>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{nuOfferId}/edit" var="editUrl">
<spring:param name="nuOfferId" value="${nuOffer.id}"/>
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar oferta</a>
</sec:authorize>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{nuOfferId}/disable" var="editUrl">
<spring:param name="nuOfferId" value="${nuOffer.id}"/>
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar oferta</a>
</sec:authorize>
</cheapy:layout>

View file

@ -4,6 +4,7 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
<cheapy:layout pageName="speedOffer">
@ -56,14 +57,18 @@
<fmt:message key="return"/> </button>
</div>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{speedOfferId}/edit" var="editUrl">
<spring:param name="speedOfferId" value="${speedOffer.id}"/>
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar oferta</a>
</sec:authorize>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{speedOfferId}/disable" var="editUrl">
<spring:param name="speedOfferId" value="${speedOffer.id}"/>
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar oferta</a>
</sec:authorize>
</cheapy:layout>

View file

@ -4,6 +4,7 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
<cheapy:layout pageName="timeOffer">
@ -31,16 +32,20 @@
</tr>
</thead>
</table>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{timeOfferId}/edit" var="editUrl">
<spring:param name="timeOfferId" value="${timeOffer.id}"/>
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar oferta</a>
</sec:authorize>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{timeOfferId}/disable" var="editUrl">
<spring:param name="timeOfferId" value="${timeOffer.id}"/>
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar oferta</a>
</sec:authorize>
<div class="btn-return">
<button type="button" role="link" onclick="window.location='/offers'" style="font-family: 'Lobster'; font-size: 20px;">