From ba3aa68598efe56da6dfe0e7f013c1e845a0658c Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 31 Mar 2021 19:21:26 +0200 Subject: [PATCH] Avances validadores --- .../cheapy/model/TimeOffer.java | 2 + .../cheapy/service/NuOfferService.java | 5 + .../cheapy/web/NuOfferController.java | 29 ++-- .../jsp/offers/food/foodOffersShow.jsp | 116 +++++++------- .../offers/nu/createOrUpdateNuOfferForm.jsp | 82 +++++----- .../WEB-INF/jsp/offers/nu/nuOffersShow.jsp | 141 ++++++++++-------- .../jsp/offers/speed/speedOffersShow.jsp | 140 +++++++++-------- .../jsp/offers/time/timeOffersShow.jsp | 106 +++++++------ 8 files changed, 341 insertions(+), 280 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/model/TimeOffer.java b/src/main/java/org/springframework/cheapy/model/TimeOffer.java index a0684feaa..5fcfb28a1 100644 --- a/src/main/java/org/springframework/cheapy/model/TimeOffer.java +++ b/src/main/java/org/springframework/cheapy/model/TimeOffer.java @@ -6,6 +6,7 @@ import javax.persistence.Entity; import javax.persistence.Table; import javax.validation.constraints.NotNull; +import org.hibernate.validator.constraints.Range; import org.springframework.format.annotation.DateTimeFormat; @Entity @@ -25,6 +26,7 @@ public class TimeOffer extends Offer { private LocalTime finish; @NotNull(message = "Debe rellenar el descuento") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discount; public LocalTime getInit() { diff --git a/src/main/java/org/springframework/cheapy/service/NuOfferService.java b/src/main/java/org/springframework/cheapy/service/NuOfferService.java index b87093c3d..5268ac2db 100644 --- a/src/main/java/org/springframework/cheapy/service/NuOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/NuOfferService.java @@ -35,6 +35,11 @@ public class NuOfferService { this.nuOfferRepository.save(nuOffer); } + @Transactional + public void saveUpdateNuOffer(final NuOffer nuOfferNew, final NuOffer nuOfferOld) throws DataAccessException { + this.nuOfferRepository.save(nuOfferNew); + } + public List findActiveNuOffer() { return this.nuOfferRepository.findActiveNuOffer(StatusOffer.active); } diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index ec1b25dd4..10d506aba 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -15,7 +15,9 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; +import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -32,13 +34,18 @@ public class NuOfferController { this.clientService = clientService; } +// @InitBinder +// public void setAllowedFields(WebDataBinder dataBinder) { +// dataBinder.setDisallowedFields("id"); +// } + @GetMapping("/offers/nu/new") public String initCreationForm(Map model) { NuOffer nuOffer = new NuOffer(); 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(); @@ -62,11 +69,11 @@ public class NuOfferController { nuOffer.setClient(client); this.nuOfferService.saveNuOffer(nuOffer); - return "redirect:/offers/nu/"+nuOffer.getId(); + return "redirect:/offers/nu/" + nuOffer.getId(); } } - @GetMapping(value ="/offers/nu/{nuOfferId}/activate") + @GetMapping(value = "/offers/nu/{nuOfferId}/activate") public String activateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap modelMap) { Client client = this.clientService.getCurrentClient(); NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); @@ -74,11 +81,11 @@ public class NuOfferController { nuOffer.setStatus(StatusOffer.active); nuOffer.setCode("NU-" + nuOfferId); this.nuOfferService.saveNuOffer(nuOffer); - + } else { modelMap.addAttribute("message", "You don't have access to this number offer"); } - return "redirect:/offers/nu/"+ nuOffer.getId(); + return "redirect:/offers/nu/" + nuOffer.getId(); } @@ -94,7 +101,7 @@ 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"; } @@ -106,7 +113,7 @@ 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"; } @@ -122,7 +129,8 @@ 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"; @@ -134,12 +142,13 @@ public class NuOfferController { } @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); diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp index ce758a77c..3cf684f5a 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp @@ -1,63 +1,73 @@ -<%@ page session="false" trimDirectiveWhitespaces="true" %> -<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ 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" %> - +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> +<%@ 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"%> + -

+

+ +

- - - - - - - - - - - - - - - - - - +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
- - - - - - - -
- -
- - - - - Editar oferta - - - - - - - Desactivar oferta - - + + + + Editar + oferta + + + + + + + Desactivar + oferta + +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/nu/createOrUpdateNuOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/offers/nu/createOrUpdateNuOfferForm.jsp index cf33f90a8..2becba41c 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/createOrUpdateNuOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/createOrUpdateNuOfferForm.jsp @@ -1,42 +1,48 @@ -<%@ page session="false" trimDirectiveWhitespaces="true" %> -<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> -<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> -

- Nueva Oferta por número de comensales -

- -
- - - - - - - - - - - - +

+ Nueva + Oferta por número de comensales +

+ +
+ + + -
-
-
- - - - - - - - -
-
-
+ + + + + + + + + + +
+
+
+ + + + + + + + +
+
+
diff --git a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp index 50433e2da..529547e4a 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp @@ -1,74 +1,83 @@ -<%@ page session="false" trimDirectiveWhitespaces="true" %> -<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> -<%@ 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" %> - +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> +<%@ 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"%> + -

+

+ +

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- -
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ - - - - Editar oferta - - - - - - - Desactivar oferta - + + + + Editar + oferta + + + + + + + Desactivar + oferta +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp index fca775aec..26538b1e8 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp @@ -1,74 +1,84 @@ -<%@ page session="false" trimDirectiveWhitespaces="true" %> -<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> -<%@ 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" %> - +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> +<%@ 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"%> + -

+

+ +

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
- - - - Editar oferta - - - - - - - Desactivar oferta - + + + + Editar + oferta + + + + + + + Desactivar + oferta +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp index 892b592fe..bf25aa9e8 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp @@ -1,56 +1,66 @@ -<%@ page session="false" trimDirectiveWhitespaces="true" %> -<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> -<%@ 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" %> - +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> +<%@ 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"%> + -

+

+ +

- - - - - - - - - - - - - - - - - - - -
- + + + + + + + + + + + + + + + + + + + +
+ - - - - Editar oferta - - - - - - - Desactivar oferta - + + + + Editar + oferta + + + + + + + Desactivar + oferta + + +
+ +
-
- -
-