From e3c9228185414e69e832ab828c0151a9ac614798 Mon Sep 17 00:00:00 2001 From: Angel Caballero Dominguez Date: Sun, 28 Mar 2021 15:27:46 +0200 Subject: [PATCH 01/22] Avance en las vistas de modificacion de las ofertas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se ha realizado la mayor parte de las vistas de modificacion de las ofertas, así como algunos cambios menores en las vistas de mostrar detalles --- src/main/less/cheapy.less | 73 ++++++++++++++++++- .../resources/messages/messages_es.properties | 4 + .../createOrUpdateFoodOfferForm.jsp | 27 ++++--- .../WEB-INF/jsp/foodOffers/foodOffersShow.jsp | 38 ++++++---- .../nuOffers/createOrUpdateNuOfferForm.jsp | 27 ++++--- .../WEB-INF/jsp/nuOffers/nuOffersShow.jsp | 36 +++++---- .../createOrUpdateSpeedOfferForm.jsp | 27 ++++--- .../jsp/speedOffers/speedOffersShow.jsp | 35 +++++---- .../createOrUpdateTimeOfferForm.jsp | 27 ++++--- .../WEB-INF/jsp/timeOffers/timeOffersShow.jsp | 36 +++++---- 10 files changed, 232 insertions(+), 98 deletions(-) diff --git a/src/main/less/cheapy.less b/src/main/less/cheapy.less index 2ad446686..17d012e1f 100644 --- a/src/main/less/cheapy.less +++ b/src/main/less/cheapy.less @@ -240,6 +240,30 @@ img.img-responsive{ background-color: rgb(40, 140, 215); } +.btn-mod{ + display: table; + margin: 0 auto; + float:left; +} + +.btn-mod button { + background-color: rgb(0, 64, 128); + border: 1px solid rgb(0, 0, 160); + color: white; + padding: 10px 24px; + cursor: pointer; + display: block; +} + +.btn-mod button:not(:last-child) { + border-bottom: none; +} + + +.btn-mod button:hover { + background-color: rgb(40, 140, 215); +} + #foodOfferTable th { width: 25%; } @@ -278,7 +302,52 @@ img.img-responsive{ .btn-return{ display: table; margin: 0 auto; - width: 100%; + float:left; +} + +.btns-edit{ + display: table; + margin: 0 auto; + float:right; +} + +.btns-edit button{ + background-color: rgb(0, 64, 128); + border: 1px solid rgb(0, 0, 160); + color: white; + padding: 10px 24px; + cursor: pointer; +} + +.btns-edit button:not(:last-child) { + border-bottom: none; +} + + +.btns-edit button:hover { + background-color: rgb(40, 140, 215); +} + +.btns-delete{ + display: table; + margin: 0 auto; + float:left; +} + +.btns-delete button{ + background-color: rgb(0, 64, 128); + border: 1px solid rgb(0, 0, 160); + color: white; + padding: 10px 24px; + cursor: pointer; +} + +.btns-delete button:not(:last-child) { + border-bottom: none; +} + +.btns-delete button:hover { + background-color: rgb(40, 140, 215); } .btn-return button { @@ -288,14 +357,12 @@ img.img-responsive{ padding: 10px 24px; cursor: pointer; display: block; - left: 0%; } .btn-return button:not(:last-child) { border-bottom: none; } - .btn-return button:hover { background-color: rgb(40, 140, 215); } diff --git a/src/main/resources/messages/messages_es.properties b/src/main/resources/messages/messages_es.properties index 81b71314d..f17c6626b 100644 --- a/src/main/resources/messages/messages_es.properties +++ b/src/main/resources/messages/messages_es.properties @@ -1,4 +1,8 @@ welcome=Bienvenido a +new=Nueva +deleteOffer=Eliminar Oferta +cancel=Cancelar +deleteOfferMessage=Confirme que quiere eliminar su oferta listOffers=Ver Ofertas foodOffers=Ofertas por plato especifico foodOffer=Oferta por plato especifico diff --git a/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp index daeeec363..5c636d761 100644 --- a/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp @@ -5,10 +5,11 @@ <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> + -

- New FoodOffer +

+

@@ -22,14 +23,20 @@
- - - - - - - - +
+ + + + + + + + +
diff --git a/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp index 44b10a7f0..211212e0c 100644 --- a/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp @@ -29,7 +29,7 @@ - + @@ -39,20 +39,28 @@ -
- -
+
+
+ +
- - - - Editar oferta - - - - - Desactivar oferta +
+ + + + + + + + + +
+
diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp index 904bbfffb..26707db2c 100644 --- a/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp @@ -5,10 +5,11 @@ <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> + -

- New NuOffer +

+

@@ -28,14 +29,20 @@
- - - - - - - - +
+ + + + + + + + +
diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp index f5a351168..565d2bd43 100644 --- a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp @@ -50,20 +50,28 @@ -
- +
+
+ +
+ +
+ + + + + + + + + +
- - - - Editar oferta - - - - - Desactivar oferta - diff --git a/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp index 3327373db..2011952d6 100644 --- a/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp @@ -5,10 +5,11 @@ <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> + -

- New SpeedOffer +

+

@@ -26,14 +27,20 @@
- - - - - - - - +
+ + + + + + + + +
diff --git a/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp index de2a32a80..8659f8097 100644 --- a/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp @@ -50,20 +50,29 @@ -
- +
+
+ +
+ +
+ + + + + + + + + +
- - - - Editar oferta - - - - - Desactivar oferta diff --git a/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp index e483ed81b..770fb5428 100644 --- a/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp @@ -5,10 +5,11 @@ <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> + -

- New TimeOffer +

+

@@ -25,14 +26,20 @@
- - - - - - - - +
+ + + + + + + + +
diff --git a/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp index 3db0c885a..b0ffd00a6 100644 --- a/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp @@ -32,20 +32,30 @@ - - - - Editar oferta - - - - - Desactivar oferta +
+
+ +
-
- +
+ + + + + + + + + +
+ + From 0ba60d4ab972f438b35641942330cc890e9af7eb Mon Sep 17 00:00:00 2001 From: Antonio Vidal Date: Tue, 30 Mar 2021 18:47:55 +0200 Subject: [PATCH 02/22] Solo Ofertas activas y Mis ofertas --- .../springframework/cheapy/model/Client.java | 25 +-- .../repository/FoodOfferRepository.java | 11 +- .../cheapy/repository/NuOfferRepository.java | 13 +- .../repository/SpeedOfferRepository.java | 12 +- .../repository/TimeOfferRepository.java | 12 +- .../cheapy/service/FoodOfferService.java | 11 +- .../cheapy/service/NuOfferService.java | 9 + .../cheapy/service/SpeedOfferService.java | 10 ++ .../cheapy/service/TimeOfferService.java | 11 +- .../cheapy/web/OfertaController.java | 37 +++- src/main/resources/db/mysql/data.sql | 2 +- .../WEB-INF/jsp/offers/myOffersList.jsp | 158 ++++++++++++++++++ src/main/webapp/WEB-INF/tags/menu.tag | 8 +- 13 files changed, 292 insertions(+), 27 deletions(-) create mode 100644 src/main/webapp/WEB-INF/jsp/offers/myOffersList.jsp diff --git a/src/main/java/org/springframework/cheapy/model/Client.java b/src/main/java/org/springframework/cheapy/model/Client.java index 23fa89b80..e3f939728 100644 --- a/src/main/java/org/springframework/cheapy/model/Client.java +++ b/src/main/java/org/springframework/cheapy/model/Client.java @@ -1,5 +1,6 @@ package org.springframework.cheapy.model; +import java.util.List; import java.util.Set; import javax.persistence.CascadeType; @@ -57,16 +58,16 @@ public class Client extends BaseEntity { private User usuar; @OneToMany - private Set foodOffers; + private List foodOffers; @OneToMany - private Set nuOffers; + private List nuOffers; @OneToMany - private Set speedOffers; + private List speedOffers; @OneToMany - private Set timeOffers; + private List timeOffers; public String getName() { return name; @@ -148,35 +149,35 @@ public class Client extends BaseEntity { this.usuar = usuar; } - public Set getFoodOffers() { + public List getFoodOffers() { return foodOffers; } - public void setFoodOffers(Set foodOffers) { + public void setFoodOffers(List foodOffers) { this.foodOffers = foodOffers; } - public Set getNuOffers() { + public List getNuOffers() { return nuOffers; } - public void setNuOffers(Set nuOffers) { + public void setNuOffers(List nuOffers) { this.nuOffers = nuOffers; } - public Set getSpeedOffers() { + public List getSpeedOffers() { return speedOffers; } - public void setSpeedOffers(Set speedOffers) { + public void setSpeedOffers(List speedOffers) { this.speedOffers = speedOffers; } - public Set getTimeOffers() { + public List getTimeOffers() { return timeOffers; } - public void setTimeOffers(Set timeOffers) { + public void setTimeOffers(List timeOffers) { this.timeOffers = timeOffers; } diff --git a/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java index 80fadc686..2e9ca093b 100644 --- a/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java @@ -1,6 +1,8 @@ package org.springframework.cheapy.repository; import org.springframework.cheapy.model.FoodOffer; +import org.springframework.cheapy.model.StatusOffer; + import java.util.List; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; @@ -18,5 +20,12 @@ public interface FoodOfferRepository extends Repository { FoodOffer findById(@Param("id") Integer id); void save(FoodOffer foodOffer); - + + @Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.status =:status") + @Transactional(readOnly = true) + List findActiveFoodOffer(StatusOffer status); + + @Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.id =:id") + @Transactional(readOnly = true) + List findByUserId(@Param("id") Integer id); } diff --git a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java index 42d437fdb..8e59df4dc 100644 --- a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java @@ -1,8 +1,12 @@ package org.springframework.cheapy.repository; import java.util.List; + +import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.NuOffer; +import org.springframework.cheapy.model.StatusOffer; import org.springframework.data.repository.Repository; +import org.springframework.data.repository.query.Param; import org.springframework.data.jpa.repository.Query; import org.springframework.transaction.annotation.Transactional; @@ -15,5 +19,12 @@ public interface NuOfferRepository extends Repository { List findAllNuOffer(); void save(NuOffer nuOffer); - + + @Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.status =:status") + @Transactional(readOnly = true) + List findActiveNuOffer(StatusOffer status); + + @Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.id =:id") + @Transactional(readOnly = true) + List findByUserId(@Param("id") Integer id); } diff --git a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java index aef04d36d..e4df0426c 100644 --- a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java @@ -1,7 +1,10 @@ package org.springframework.cheapy.repository; import java.util.List; + +import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.SpeedOffer; +import org.springframework.cheapy.model.StatusOffer; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; import org.springframework.data.repository.query.Param; @@ -18,5 +21,12 @@ public interface SpeedOfferRepository extends Repository { List findAllSpeedOffer(); void save(SpeedOffer speedOffer); - + + @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.status =:status") + @Transactional(readOnly = true) + List findActiveSpeedOffer(StatusOffer status); + + @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.id =:id") + @Transactional(readOnly = true) + List findByUserId(@Param("id") Integer id); } diff --git a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java index b663057a7..1cd4c5e34 100644 --- a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java @@ -1,8 +1,11 @@ package org.springframework.cheapy.repository; import java.util.List; + +import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; import org.springframework.data.repository.Repository; +import org.springframework.data.repository.query.Param; import org.springframework.data.jpa.repository.Query; import org.springframework.transaction.annotation.Transactional; @@ -15,5 +18,12 @@ public interface TimeOfferRepository extends Repository { List findAllTimeOffer(); void save(TimeOffer timeOffer); - + + @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.status =:status") + @Transactional(readOnly = true) + List findActiveTimeOffer(StatusOffer status); + + @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.id =:id") + @Transactional(readOnly = true) + List findByUserId(@Param("id") Integer id); } diff --git a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java index d23ffc321..c11c9e8a6 100644 --- a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java @@ -2,6 +2,7 @@ package org.springframework.cheapy.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.FoodOffer; +import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.repository.FoodOfferRepository; import java.util.List; import org.springframework.dao.DataAccessException; @@ -20,12 +21,20 @@ public class FoodOfferService { public FoodOffer findFoodOfferById(final int id) { return this.foodOfferRepository.findById(id); } + public List findAllFoodOffer() { // return this.foodOfferRepository.findAllFoodOffer(); } public void saveFoodOffer(final FoodOffer foodOffer) throws DataAccessException { this.foodOfferRepository.save(foodOffer); - + } + + public List findActiveFoodOffer() { + return this.foodOfferRepository.findActiveFoodOffer(StatusOffer.active); + } + + public List findFoodOfferByUserId(final int id) { + return this.foodOfferRepository.findByUserId(id); } } diff --git a/src/main/java/org/springframework/cheapy/service/NuOfferService.java b/src/main/java/org/springframework/cheapy/service/NuOfferService.java index d09255d64..b87093c3d 100644 --- a/src/main/java/org/springframework/cheapy/service/NuOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/NuOfferService.java @@ -3,6 +3,7 @@ package org.springframework.cheapy.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.NuOffer; +import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.repository.NuOfferRepository; import java.util.List; import org.springframework.dao.DataAccessException; @@ -33,4 +34,12 @@ public class NuOfferService { public void saveNuOffer(final NuOffer nuOffer) throws DataAccessException { this.nuOfferRepository.save(nuOffer); } + + public List findActiveNuOffer() { + return this.nuOfferRepository.findActiveNuOffer(StatusOffer.active); + } + + public List findNuOfferByUserId(final int id) { + return this.nuOfferRepository.findByUserId(id); + } } diff --git a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java index 121874247..6063b7426 100644 --- a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java @@ -3,7 +3,9 @@ package org.springframework.cheapy.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.SpeedOffer; +import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.repository.SpeedOfferRepository; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -34,4 +36,12 @@ public class SpeedOfferService { public void saveSpeedOffer(final SpeedOffer speedOffer) throws DataAccessException { // this.speedOfferRepository.save(speedOffer); } + + public List findActiveSpeedOffer() { + return this.speedOfferRepository.findActiveSpeedOffer(StatusOffer.active); + } + + public List findSpeedOfferByUserId(final int id) { + return this.speedOfferRepository.findByUserId(id); + } } diff --git a/src/main/java/org/springframework/cheapy/service/TimeOfferService.java b/src/main/java/org/springframework/cheapy/service/TimeOfferService.java index b7d5904ef..e23fa5151 100644 --- a/src/main/java/org/springframework/cheapy/service/TimeOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/TimeOfferService.java @@ -3,6 +3,7 @@ package org.springframework.cheapy.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.repository.TimeOfferRepository; @@ -30,7 +31,13 @@ public class TimeOfferService { public void saveTimeOffer(final TimeOffer TimeOffer) throws DataAccessException { this.timeOfferRepository.save(TimeOffer); - - + } + + public List findActiveTimeOffer() { + return this.timeOfferRepository.findActiveTimeOffer(StatusOffer.active); + } + + public List findTimeOfferByUserId(final int id) { + return this.timeOfferRepository.findByUserId(id); } } diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index c7cb3de71..73b3553cd 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -8,6 +8,7 @@ import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.TimeOffer; +import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.FoodOfferService; import org.springframework.cheapy.service.NuOfferService; import org.springframework.cheapy.service.SpeedOfferService; @@ -17,14 +18,17 @@ import org.springframework.web.bind.annotation.GetMapping; @Controller public class OfertaController { - + + private final ClientService clientService; + private final FoodOfferService foodOfferService; private final NuOfferService nuOfferService; private final SpeedOfferService speedOfferService; private final TimeOfferService timeOfferService; public OfertaController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, - final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) { + final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService, ClientService clientService) { + this.clientService = clientService; this.foodOfferService = foodOfferService; this.nuOfferService = nuOfferService; this.speedOfferService = speedOfferService; @@ -34,10 +38,10 @@ public class OfertaController { @GetMapping("/offers") public String processFindForm( Map model) { - List foodOfferLs=this.foodOfferService.findAllFoodOffer(); - List nuOfferLs=this.nuOfferService.findAllNuOffer(); - List speedOfferLs=this.speedOfferService.findAllSpeedOffer(); - List timeOfferLs=this.timeOfferService.findAllTimeOffer(); + List foodOfferLs=this.foodOfferService.findActiveFoodOffer(); + List nuOfferLs=this.nuOfferService.findActiveNuOffer(); + List speedOfferLs=this.speedOfferService.findActiveSpeedOffer(); + List timeOfferLs=this.timeOfferService.findActiveTimeOffer(); model.put("foodOfferLs", foodOfferLs); model.put("nuOfferLs", nuOfferLs); @@ -50,7 +54,28 @@ public class OfertaController { return "offers/offersList"; } + + @GetMapping("/myOffers") + public String processMyOffersForm( Map model) { + + int actual = this.clientService.getCurrentClient().getId(); + + List foodOfferLs = this.foodOfferService.findFoodOfferByUserId(actual); + List nuOfferLs = this.nuOfferService.findNuOfferByUserId(actual); + List speedOfferLs = this.speedOfferService.findSpeedOfferByUserId(actual); + List timeOfferLs = this.timeOfferService.findTimeOfferByUserId(actual); + + model.put("foodOfferLs", foodOfferLs); + model.put("nuOfferLs", nuOfferLs); + model.put("speedOfferLs", speedOfferLs); + model.put("timeOfferLs", timeOfferLs); + + //Se añade formateador de fecha al modelo + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + + return "offers/myOffersList"; + } // @GetMapping("/owners/{ownerId}/edit") // public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { // Owner owner = this.ownerService.findOwnerById(ownerId); diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index baa9d8384..39f0ca7b1 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -32,7 +32,7 @@ INSERT INTO usuarios VALUES (4, 'Pepe', 'Lopez', '12456776V', 'C/Macarena', '690 INSERT INTO clients (id, name, email, address, init, finish, telephone, description, code, food, username) VALUES (1,'bar manoli','manoli@gmail.com','C/Betis','10:00','22:00','608726190', 'description 1', 'code1', 'ESPAÑOLA','manoli'); INSERT INTO clients (id, name, email, address, init, finish, telephone, description, code, food, username) VALUES (2,'bar david','david@gmail.com','C/Sevilla','09:30','22:00','608726190', 'description 2', 'code2', 'americana','david'); -INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'FO-1', 'active', 1, 'macarrones', 15); +INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'FO-1', 'inactive', 1, 'macarrones', 15); INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'T-1', 'active', 1, '12:00:00', '13:00:00', 10); INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'SP-1', 'active',1,5,25,10,15,15,10); INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'NU-1', 'active',1,15,25,10,15,5,10); diff --git a/src/main/webapp/WEB-INF/jsp/offers/myOffersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/myOffersList.jsp new file mode 100644 index 000000000..201065542 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/offers/myOffersList.jsp @@ -0,0 +1,158 @@ +<%@ 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" %> + + + +

+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ +
+
+ +

+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+ +
+
+

+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+ +
+
+

+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+ +
+
+
diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index daa63faa2..10a512467 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -25,7 +25,7 @@ - Home + Inicio Ver ofertas + + + + Mis ofertas + +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp index daeeec363..e808c1d9b 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp @@ -8,15 +8,15 @@

- New FoodOffer + Nueva Oferta de plato específico

- - + +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp index 14a7519e0..9c6b92a7d 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp @@ -8,7 +8,7 @@ -

¿Esta seguro de que quiere eliminar su oferta?

+

¿Está seguro de que quiere eliminar su 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 904bbfffb..6291fa5c9 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/createOrUpdateNuOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/createOrUpdateNuOfferForm.jsp @@ -8,18 +8,18 @@

- New NuOffer + Nueva Oferta por número de comensales

- - + + - + diff --git a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp index 83fa94c10..23e372718 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp @@ -8,7 +8,7 @@ -

¿Esta seguro de que quiere dar de baja su offer?

+

¿Está seguro de que quiere dar de baja su oferta?

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 f5a351168..361d7e147 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp @@ -37,7 +37,7 @@ - Meta bronce + diff --git a/src/main/webapp/WEB-INF/jsp/offers/speed/createOrUpdateSpeedOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/offers/speed/createOrUpdateSpeedOfferForm.jsp index 3327373db..404d46d91 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/createOrUpdateSpeedOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/createOrUpdateSpeedOfferForm.jsp @@ -8,21 +8,21 @@

- New SpeedOffer + Nueva Oferta por velocidad

- - - - - - - - + + + + + + + +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp index 0e2febbf0..d29c8b953 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp @@ -8,7 +8,7 @@ -

¿Esta seguro de que quiere dar de baja su offer?

+

¿Está seguro de que quiere dar de baja su oferta?

diff --git a/src/main/webapp/WEB-INF/jsp/offers/time/createOrUpdateTimeOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/offers/time/createOrUpdateTimeOfferForm.jsp index cd12ad6fc..7afef4905 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/createOrUpdateTimeOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/createOrUpdateTimeOfferForm.jsp @@ -8,15 +8,15 @@

- New TimeOffer + Nueva Oferta por tiempo

- - + + @@ -28,10 +28,10 @@
- + - +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp index 0baaaabcc..7b970906b 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp @@ -8,7 +8,7 @@ -

¿Esta seguro de que quiere eliminar su oferta?

+

¿Está seguro de que quiere eliminar su oferta?

From dac94b8a42fb12b3b33a347d16a2172a2bcb5ad7 Mon Sep 17 00:00:00 2001 From: Martinagr32 Date: Wed, 31 Mar 2021 14:04:27 +0200 Subject: [PATCH 04/22] Views fixed and error message entities --- readme.md | 133 ------------------ .../cheapy/model/FoodOffer.java | 9 +- .../springframework/cheapy/model/NuOffer.java | 20 +-- .../springframework/cheapy/model/Offer.java | 8 +- .../cheapy/model/SpeedOffer.java | 26 ++-- .../cheapy/model/TimeOffer.java | 2 +- .../cheapy/service/AuthoritiesService.java | 6 - .../cheapy/web/FoodOfferController.java | 1 - src/main/resources/banner.txt | 5 +- .../food/createOrUpdateFoodOfferForm.jsp | 14 +- .../jsp/offers/food/foodOffersDisable.jsp | 6 +- .../jsp/offers/food/foodOffersShow.jsp | 2 +- .../offers/nu/createOrUpdateNuOfferForm.jsp | 22 +-- .../WEB-INF/jsp/offers/nu/nuOffersDisable.jsp | 6 +- .../WEB-INF/jsp/offers/nu/nuOffersShow.jsp | 6 +- .../speed/createOrUpdateSpeedOfferForm.jsp | 22 +-- .../jsp/offers/speed/speedOffersDisable.jsp | 6 +- .../jsp/offers/speed/speedOffersShow.jsp | 6 +- .../time/createOrUpdateTimeOfferForm.jsp | 16 +-- .../jsp/offers/time/timeOffersDisable.jsp | 6 +- .../jsp/offers/time/timeOffersShow.jsp | 2 +- src/main/webapp/WEB-INF/tags/htmlHeader.tag | 2 +- src/main/webapp/WEB-INF/tags/inputField.tag | 2 + src/main/webapp/WEB-INF/tags/menu.tag | 20 ++- 24 files changed, 111 insertions(+), 237 deletions(-) diff --git a/readme.md b/readme.md index ff6d2be15..e69de29bb 100644 --- a/readme.md +++ b/readme.md @@ -1,133 +0,0 @@ -# Spring PetClinic Sample Application [![Build Status](https://travis-ci.org/spring-projects/spring-petclinic.png?branch=main)](https://travis-ci.org/spring-projects/spring-petclinic/) - -## Understanding the Spring Petclinic application with a few diagrams -See the presentation here - -## Running petclinic locally -Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/). You can build a jar file and run it from the command line: - - -``` -git clone https://github.com/spring-projects/spring-petclinic.git -cd spring-petclinic -./mvnw package -java -jar target/*.jar -``` - -You can then access petclinic here: http://localhost:8080/ - -petclinic-screenshot - -Or you can run it from Maven directly using the Spring Boot Maven plugin. If you do this it will pick up changes that you make in the project immediately (changes to Java source files require a compile as well - most people use an IDE for this): - -``` -./mvnw spring-boot:run -``` - -## In case you find a bug/suggested improvement for Spring Petclinic -Our issue tracker is available here: https://github.com/spring-projects/spring-petclinic/issues - - -## Database configuration - -In its default configuration, Petclinic uses an in-memory database (H2) which -gets populated at startup with data. The h2 console is automatically exposed at `http://localhost:8080/h2-console` -and it is possible to inspect the content of the database using the `jdbc:h2:mem:testdb` url. - -A similar setup is provided for MySql in case a persistent database configuration is needed. Note that whenever the database type is changed, the app needs to be run with a different profile: `spring.profiles.active=mysql` for MySql. - -You could start MySql locally with whatever installer works for your OS, or with docker: - -``` -docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8 -``` - -Further documentation is provided [here](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt). - -## Working with Petclinic in your IDE - -### Prerequisites -The following items should be installed in your system: -* Java 8 or newer. -* git command line tool (https://help.github.com/articles/set-up-git) -* Your preferred IDE - * Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in `Help -> About` dialog. If m2e is - not there, just follow the install process here: https://www.eclipse.org/m2e/ - * [Spring Tools Suite](https://spring.io/tools) (STS) - * IntelliJ IDEA - * [VS Code](https://code.visualstudio.com) - -### Steps: - -1) On the command line - ``` - git clone https://github.com/spring-projects/spring-petclinic.git - ``` -2) Inside Eclipse or STS - ``` - File -> Import -> Maven -> Existing Maven project - ``` - - Then either build on the command line `./mvnw generate-resources` or using the Eclipse launcher (right click on project and `Run As -> Maven install`) to generate the css. Run the application main method by right clicking on it and choosing `Run As -> Java Application`. - -3) Inside IntelliJ IDEA - In the main menu, choose `File -> Open` and select the Petclinic [pom.xml](pom.xml). Click on the `Open` button. - - CSS files are generated from the Maven build. You can either build them on the command line `./mvnw generate-resources` or right click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`. - - A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application by right clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`. - -4) Navigate to Petclinic - - Visit [http://localhost:8080](http://localhost:8080) in your browser. - - -## Looking for something in particular? - -|Spring Boot Configuration | Class or Java property files | -|--------------------------|---| -|The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) | -|Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources) | -|Caching | [CacheConfiguration](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) | - -## Interesting Spring Petclinic branches and forks - -The Spring Petclinic "main" branch in the [spring-projects](https://github.com/spring-projects/spring-petclinic) -GitHub org is the "canonical" implementation, currently based on Spring Boot and Thymeleaf. There are -[quite a few forks](https://spring-petclinic.github.io/docs/forks.html) in a special GitHub org -[spring-petclinic](https://github.com/spring-petclinic). If you have a special interest in a different technology stack -that could be used to implement the Pet Clinic then please join the community there. - - -## Interaction with other open source projects - -One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found some bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days. -Here is a list of them: - -| Name | Issue | -|------|-------| -| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://jira.springsource.org/browse/SPR-10256) and [SPR-10257](https://jira.springsource.org/browse/SPR-10257) | -| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility |[HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) | -| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://jira.springsource.org/browse/DATAJPA-292) | - - -# Contributing - -The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, features requests and submitting pull requests. - -For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at . If you have not previously done so, please fill out and submit the [Contributor License Agreement](https://cla.pivotal.io/sign/spring). - -# License - -The Spring PetClinic sample application is released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0). - -[spring-petclinic]: https://github.com/spring-projects/spring-petclinic -[spring-framework-petclinic]: https://github.com/spring-petclinic/spring-framework-petclinic -[spring-petclinic-angularjs]: https://github.com/spring-petclinic/spring-petclinic-angularjs -[javaconfig branch]: https://github.com/spring-petclinic/spring-framework-petclinic/tree/javaconfig -[spring-petclinic-angular]: https://github.com/spring-petclinic/spring-petclinic-angular -[spring-petclinic-microservices]: https://github.com/spring-petclinic/spring-petclinic-microservices -[spring-petclinic-reactjs]: https://github.com/spring-petclinic/spring-petclinic-reactjs -[spring-petclinic-graphql]: https://github.com/spring-petclinic/spring-petclinic-graphql -[spring-petclinic-kotlin]: https://github.com/spring-petclinic/spring-petclinic-kotlin -[spring-petclinic-rest]: https://github.com/spring-petclinic/spring-petclinic-rest diff --git a/src/main/java/org/springframework/cheapy/model/FoodOffer.java b/src/main/java/org/springframework/cheapy/model/FoodOffer.java index 3cb6a1e56..ad45ad09f 100644 --- a/src/main/java/org/springframework/cheapy/model/FoodOffer.java +++ b/src/main/java/org/springframework/cheapy/model/FoodOffer.java @@ -17,10 +17,11 @@ package org.springframework.cheapy.model; import javax.persistence.Entity; import javax.persistence.Table; -import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import org.hibernate.validator.constraints.Range; + @Entity @Table(name = "food_offers") public class FoodOffer extends Offer { @@ -28,11 +29,11 @@ public class FoodOffer extends Offer { private static final long serialVersionUID = 1L; //Plato específico - @NotBlank + @NotBlank(message = "Debe rellenar la comida a ofertar") private String food; - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento que proporciona") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discount; public String getFood() { diff --git a/src/main/java/org/springframework/cheapy/model/NuOffer.java b/src/main/java/org/springframework/cheapy/model/NuOffer.java index 6f250737d..d4cf72456 100644 --- a/src/main/java/org/springframework/cheapy/model/NuOffer.java +++ b/src/main/java/org/springframework/cheapy/model/NuOffer.java @@ -6,6 +6,8 @@ import javax.persistence.Table; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; +import org.hibernate.validator.constraints.Range; + @Entity @Table(name = "nu_offers") public class NuOffer extends Offer { @@ -13,31 +15,31 @@ public class NuOffer extends Offer { //Oferta por numero de comensales private static final long serialVersionUID = 1L; - @NotNull + @NotNull(message = "Debe rellenar el tiempo del rango oro") @Min(1) private Integer gold; @Column(name = "discount_gold") - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento del rango oro") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discountGold; - @NotNull + @NotNull(message = "Debe rellenar el tiempo del rango plata") @Min(1) private Integer silver; @Column(name = "discount_silver") - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento del rango plata") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discountSilver; - @NotNull + @NotNull(message = "Debe rellenar el tiempo del rango bronce") @Min(1) private Integer bronze; @Column(name = "discount_bronze") - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento del rango bronce") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discountBronze; public Integer getGold() { diff --git a/src/main/java/org/springframework/cheapy/model/Offer.java b/src/main/java/org/springframework/cheapy/model/Offer.java index 5ae64feba..fa6dd0622 100644 --- a/src/main/java/org/springframework/cheapy/model/Offer.java +++ b/src/main/java/org/springframework/cheapy/model/Offer.java @@ -35,13 +35,13 @@ public class Offer extends BaseEntity { // Clase padre @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") - @NotNull - @Future + @NotNull(message = "Debe introducir una fecha de inicio.") + @Future(message = "La fecha debe debe ser futura") private LocalDateTime start; @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") - @NotNull - @Future + @NotNull(message = "Debe introducir una fecha de fin.") + @Future(message = "La fecha debe debe ser futura") private LocalDateTime end; private String code; diff --git a/src/main/java/org/springframework/cheapy/model/SpeedOffer.java b/src/main/java/org/springframework/cheapy/model/SpeedOffer.java index 84b551829..e9aa4d0e4 100644 --- a/src/main/java/org/springframework/cheapy/model/SpeedOffer.java +++ b/src/main/java/org/springframework/cheapy/model/SpeedOffer.java @@ -6,6 +6,8 @@ import javax.persistence.Table; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; +import org.hibernate.validator.constraints.Range; + @Entity @Table(name = "speed_offers") public class SpeedOffer extends Offer { @@ -13,31 +15,31 @@ public class SpeedOffer extends Offer { // Ofertar por rapidez comiendo private static final long serialVersionUID = 1L; - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el tiempo del rango oro") + @Min(1) private Integer gold; @Column(name = "discount_gold") - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento del rango oro") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discountGold; - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el tiempo del rango plata") + @Min(1) private Integer silver; @Column(name = "discount_silver") - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento del rango plata") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discountSilver; - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el tiempo del rango bronce") + @Min(1) private Integer bronze; @Column(name = "discount_bronze") - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento del rango bronce") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discountBronze; public Integer getGold() { diff --git a/src/main/java/org/springframework/cheapy/model/TimeOffer.java b/src/main/java/org/springframework/cheapy/model/TimeOffer.java index 44ae5e3d6..6aeff7b88 100644 --- a/src/main/java/org/springframework/cheapy/model/TimeOffer.java +++ b/src/main/java/org/springframework/cheapy/model/TimeOffer.java @@ -24,7 +24,7 @@ public class TimeOffer extends Offer { @NotNull private LocalTime finish; - @NotNull + @NotNull(message = "Debe rellenar el descuento") private Integer discount; public LocalTime getInit() { diff --git a/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java b/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java index 5307beeb1..7d0f8d7a8 100644 --- a/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java +++ b/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java @@ -26,12 +26,6 @@ import org.springframework.cheapy.repository.AuthoritiesRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -/** - * Mostly used as a facade for all Petclinic controllers Also a placeholder - * for @Transactional and @Cacheable annotations - * - * @author Michael Isvy - */ @Service public class AuthoritiesService { /* diff --git a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java index b2870d93b..0af5a857c 100644 --- a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java @@ -31,7 +31,6 @@ public class FoodOfferController { this.clientService = clientService; } - @GetMapping("/offers/food/new") public String initCreationForm(Map model) { FoodOffer foodOffer = new FoodOffer(); diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt index da0aacccf..b4c3b6769 100644 --- a/src/main/resources/banner.txt +++ b/src/main/resources/banner.txt @@ -1,3 +1,5 @@ + + __^__ __^__ ( ___ )------------------------------------( ___ ) | / | | \ | @@ -5,5 +7,4 @@ |___| |___| (_____)------------------------------------(_____) -:: Built with Spring Boot :: ${spring-boot.version} - +-- Built with Spring Boot -- (${spring-boot.version}) diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp index e808c1d9b..b3a319d5c 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp @@ -4,9 +4,9 @@ <%@ 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="petclinic" tagdir="/WEB-INF/tags" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +

Nueva Oferta de plato específico

@@ -15,10 +15,10 @@ - - - - + + + +
@@ -33,4 +33,4 @@
-
+ diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp index 9c6b92a7d..d2012045b 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp @@ -2,10 +2,10 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> -<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> - +

¿Está seguro de que quiere eliminar su oferta?

@@ -20,4 +20,4 @@ Volver
-
+ 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 44b10a7f0..ec9e21931 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp @@ -29,7 +29,7 @@ - + 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 6291fa5c9..cf33f90a8 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/createOrUpdateNuOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/createOrUpdateNuOfferForm.jsp @@ -4,9 +4,9 @@ <%@ 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="petclinic" tagdir="/WEB-INF/tags" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +

Nueva Oferta por número de comensales

@@ -15,15 +15,15 @@ - - + + - - - - - - + + + + + +
@@ -39,4 +39,4 @@
-
+ diff --git a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp index 23e372718..97068ef27 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp @@ -2,10 +2,10 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> -<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> - +

¿Está seguro de que quiere dar de baja su oferta?

@@ -24,4 +24,4 @@ Volver
-
+ 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 361d7e147..5fa0f146b 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp @@ -26,7 +26,7 @@ - + @@ -34,7 +34,7 @@ - + @@ -42,7 +42,7 @@ - + diff --git a/src/main/webapp/WEB-INF/jsp/offers/speed/createOrUpdateSpeedOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/offers/speed/createOrUpdateSpeedOfferForm.jsp index 404d46d91..53953ef65 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/createOrUpdateSpeedOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/createOrUpdateSpeedOfferForm.jsp @@ -4,9 +4,9 @@ <%@ 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="petclinic" tagdir="/WEB-INF/tags" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +

Nueva Oferta por velocidad

@@ -15,14 +15,14 @@ - - - - - - - - + + + + + + + +
@@ -37,4 +37,4 @@
-
+ diff --git a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp index d29c8b953..0a786416f 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp @@ -2,10 +2,10 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> -<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> - +

¿Está seguro de que quiere dar de baja su oferta?

@@ -24,4 +24,4 @@ Volver
-
+ 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 de2a32a80..2d6a1c59d 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp @@ -26,7 +26,7 @@ - + @@ -34,7 +34,7 @@ - + @@ -42,7 +42,7 @@ - + diff --git a/src/main/webapp/WEB-INF/jsp/offers/time/createOrUpdateTimeOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/offers/time/createOrUpdateTimeOfferForm.jsp index 7afef4905..b612edf62 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/createOrUpdateTimeOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/createOrUpdateTimeOfferForm.jsp @@ -4,9 +4,9 @@ <%@ 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="petclinic" tagdir="/WEB-INF/tags" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +

Nueva Oferta por tiempo

@@ -15,12 +15,12 @@ - - + + - - - + + +
@@ -37,4 +37,4 @@
-
+ diff --git a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp index 7b970906b..020d3023f 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp @@ -2,10 +2,10 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> -<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> - +

¿Está seguro de que quiere eliminar su oferta?

@@ -21,4 +21,4 @@ Volver
-
+ 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 3db0c885a..52cb38763 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp @@ -23,7 +23,7 @@ - + diff --git a/src/main/webapp/WEB-INF/tags/htmlHeader.tag b/src/main/webapp/WEB-INF/tags/htmlHeader.tag index a259211ab..4fa699628 100644 --- a/src/main/webapp/WEB-INF/tags/htmlHeader.tag +++ b/src/main/webapp/WEB-INF/tags/htmlHeader.tag @@ -14,7 +14,7 @@ Cheapy :: a Spring Framework demonstration - Cheapy : eat fast, eat cheapy + Cheapy: Eat fast, eat cheapy <%-- CSS generated from LESS --%> diff --git a/src/main/webapp/WEB-INF/tags/inputField.tag b/src/main/webapp/WEB-INF/tags/inputField.tag index 0db10f39d..8983bd5f7 100644 --- a/src/main/webapp/WEB-INF/tags/inputField.tag +++ b/src/main/webapp/WEB-INF/tags/inputField.tag @@ -5,6 +5,8 @@ description="Name of corresponding property in bean object" %> <%@ attribute name="label" required="true" rtexprvalue="true" description="Label appears in red color if input is considered as invalid after submission" %> +<%@ attribute name="placeholder" required="false" rtexprvalue="true" + description="Example for input field" %> diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index 10a512467..df3b03161 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -28,17 +28,23 @@ Inicio - + Ver ofertas - - - Mis ofertas - + + + Mis ofertas + + + + + + + Valóranos + From 47eee25602e3e1b2f8465ff9efaf11420b48d7b2 Mon Sep 17 00:00:00 2001 From: Martinagr32 Date: Wed, 31 Mar 2021 14:48:20 +0200 Subject: [PATCH 05/22] More error message --- src/main/java/org/springframework/cheapy/model/Offer.java | 4 ++-- src/main/java/org/springframework/cheapy/model/TimeOffer.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/model/Offer.java b/src/main/java/org/springframework/cheapy/model/Offer.java index fa6dd0622..fd72e2989 100644 --- a/src/main/java/org/springframework/cheapy/model/Offer.java +++ b/src/main/java/org/springframework/cheapy/model/Offer.java @@ -35,12 +35,12 @@ public class Offer extends BaseEntity { // Clase padre @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") - @NotNull(message = "Debe introducir una fecha de inicio.") + @NotNull(message = "Debe introducir una fecha de inicio") @Future(message = "La fecha debe debe ser futura") private LocalDateTime start; @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") - @NotNull(message = "Debe introducir una fecha de fin.") + @NotNull(message = "Debe introducir una fecha de fin") @Future(message = "La fecha debe debe ser futura") private LocalDateTime end; diff --git a/src/main/java/org/springframework/cheapy/model/TimeOffer.java b/src/main/java/org/springframework/cheapy/model/TimeOffer.java index 6aeff7b88..a0684feaa 100644 --- a/src/main/java/org/springframework/cheapy/model/TimeOffer.java +++ b/src/main/java/org/springframework/cheapy/model/TimeOffer.java @@ -17,11 +17,11 @@ public class TimeOffer extends Offer { // Oferta por franja horaria @DateTimeFormat(pattern = "HH:mm") - @NotNull + @NotNull(message = "Debe introducir una hora de inicio") private LocalTime init; @DateTimeFormat(pattern = "HH:mm") - @NotNull + @NotNull(message = "Debe introducir una hora de fin") private LocalTime finish; @NotNull(message = "Debe rellenar el descuento") From ce0ee43e7921e736007b2ff407f98674c3014f50 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 31 Mar 2021 17:41:15 +0200 Subject: [PATCH 06/22] Correciones menores --- .../cheapy/web/FoodOfferController.java | 37 ++++++++++++++---- .../cheapy/web/NuOfferController.java | 38 +++++++++++++++---- .../cheapy/web/SpeedOfferController.java | 32 ++++++++++++++-- .../cheapy/web/TimeOfferController.java | 30 +++++++++++++-- .../jsp/offers/food/foodOffersShow.jsp | 7 +++- .../WEB-INF/jsp/offers/nu/nuOffersShow.jsp | 7 +++- .../jsp/offers/speed/speedOffersShow.jsp | 5 +++ .../jsp/offers/time/timeOffersShow.jsp | 7 +++- 8 files changed, 137 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java index 0af5a857c..187d27e62 100644 --- a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java @@ -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 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"; } } diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index d8533842d..ec1b25dd4 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -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"; } diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java index 2162e8558..8739479d4 100644 --- a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -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 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"; } } diff --git a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java index 41fcb27ce..eb795cf35 100644 --- a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java @@ -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 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"; } 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 ec9e21931..ce758a77c 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp @@ -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" %> @@ -44,15 +45,19 @@ - + + Editar oferta + + Desactivar oferta + 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 5fa0f146b..50433e2da 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp @@ -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" %> @@ -55,15 +56,19 @@ - + + 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 2d6a1c59d..fca775aec 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp @@ -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" %> @@ -56,14 +57,18 @@ + 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 52cb38763..892b592fe 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp @@ -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" %> @@ -31,16 +32,20 @@ - + + Editar oferta + + Desactivar oferta +
+
+ + + + + Editar opinión + + +
diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index 10a512467..3a9437e1b 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -35,7 +35,7 @@
- + Mis ofertas @@ -47,7 +47,16 @@ Contáctanos --> - + + + + Opiniones + + + + Valóranos + + From ba3aa68598efe56da6dfe0e7f013c1e845a0658c Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 31 Mar 2021 19:21:26 +0200 Subject: [PATCH 08/22] 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 + + +
+ +
-
- -
-
From 7070ca6414421ef3f8b5c05c70507305527994fb Mon Sep 17 00:00:00 2001 From: Flor Date: Wed, 31 Mar 2021 19:42:53 +0200 Subject: [PATCH 09/22] =?UTF-8?q?Version=202=20(abrir):=20solo=20puedes=20?= =?UTF-8?q?modificar=20tu=20rese=C3=B1a=20aparece=20el=20username=20en=20l?= =?UTF-8?q?a=20lista?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springframework/cheapy/model/Review.java | 11 +++++++ .../cheapy/repository/UserRepository.java | 15 +++++++++ .../cheapy/repository/UsuarioRepository.java | 11 ------- .../cheapy/service/UserService.java | 29 +++++++++++++++++ .../cheapy/web/ReviewController.java | 31 +++++++++++++++++-- .../resources/messages/messages_es.properties | 3 +- .../WEB-INF/jsp/reviews/reviewsList.jsp | 4 +++ 7 files changed, 89 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/springframework/cheapy/repository/UserRepository.java delete mode 100644 src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java create mode 100644 src/main/java/org/springframework/cheapy/service/UserService.java diff --git a/src/main/java/org/springframework/cheapy/model/Review.java b/src/main/java/org/springframework/cheapy/model/Review.java index 9bf152071..b8259eb20 100644 --- a/src/main/java/org/springframework/cheapy/model/Review.java +++ b/src/main/java/org/springframework/cheapy/model/Review.java @@ -23,7 +23,18 @@ public class Review extends BaseEntity{ @Range(min = 1, max = 5) private Integer stars; + @ManyToOne + @JoinColumn(name = "username", referencedColumnName = "username") + private User escritor; + public User getEscritor() { + return escritor; + } + + public void setEscritor(User escritor) { + this.escritor = escritor; + } + public String getOpinion() { return opinion; } diff --git a/src/main/java/org/springframework/cheapy/repository/UserRepository.java b/src/main/java/org/springframework/cheapy/repository/UserRepository.java new file mode 100644 index 000000000..0c29a7bf6 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/repository/UserRepository.java @@ -0,0 +1,15 @@ + +package org.springframework.cheapy.repository; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.cheapy.model.User; +import org.springframework.cheapy.model.Usuario; + +public interface UserRepository extends CrudRepository { + + @Query("SELECT u FROM User u WHERE username =:username") + @Transactional(readOnly = true) + User findByUsername(String username); +} diff --git a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java deleted file mode 100644 index 1bd7c8ee2..000000000 --- a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java +++ /dev/null @@ -1,11 +0,0 @@ - -package org.springframework.cheapy.repository; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.cheapy.model.Usuario; - -public interface UsuarioRepository extends CrudRepository { - - //Usuario findByUsername(String currentPrincipalName); - -} diff --git a/src/main/java/org/springframework/cheapy/service/UserService.java b/src/main/java/org/springframework/cheapy/service/UserService.java new file mode 100644 index 000000000..92b896e7f --- /dev/null +++ b/src/main/java/org/springframework/cheapy/service/UserService.java @@ -0,0 +1,29 @@ +package org.springframework.cheapy.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cheapy.model.User; +import org.springframework.cheapy.repository.UserRepository; +import org.springframework.dao.DataAccessException; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class UserService { + + private UserRepository userRepository; + + @Autowired + public UserService(final UserRepository userRepository) { + this.userRepository = userRepository; + } + + @Transactional + public User getCurrentUser() throws DataAccessException { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + String username = authentication.getName(); + return this.userRepository.findByUsername(username); + } + +} diff --git a/src/main/java/org/springframework/cheapy/web/ReviewController.java b/src/main/java/org/springframework/cheapy/web/ReviewController.java index d51b851e5..34ad021a5 100644 --- a/src/main/java/org/springframework/cheapy/web/ReviewController.java +++ b/src/main/java/org/springframework/cheapy/web/ReviewController.java @@ -6,8 +6,11 @@ import java.util.Map; import javax.validation.Valid; +import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.Review; +import org.springframework.cheapy.model.User; import org.springframework.cheapy.service.ReviewService; +import org.springframework.cheapy.service.UserService; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; @@ -21,9 +24,21 @@ public class ReviewController { private static final String VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM = "reviews/createOrUpdateReviewForm"; private final ReviewService reviewService; + private final UserService userService; - public ReviewController(final ReviewService reviewService) { + public ReviewController(final ReviewService reviewService, final UserService userService) { this.reviewService = reviewService; + this.userService = userService; + } + private boolean checkIdentity(final int reviewId) { + boolean res = false; + User user = this.userService.getCurrentUser(); + Review review = this.reviewService.findReviewById(reviewId); + User reviewsAuthor = review.getEscritor(); + if (user.equals(reviewsAuthor)) { + res = true; + } + return res; } @GetMapping("/reviews") public String processFindForm( Map model) { @@ -47,6 +62,9 @@ public class ReviewController { if (result.hasErrors()) { return VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM; } else { + User escritor = this.userService.getCurrentUser(); + review.setEscritor(escritor); + this.reviewService.saveReview(review); return "redirect:/reviews/" + review.getId(); } @@ -68,7 +86,9 @@ public class ReviewController { @GetMapping(value = "/reviews/{reviewId}/edit") public String updateReview(@PathVariable("reviewId") final int reviewId, final ModelMap model) { - + if (!this.checkIdentity(reviewId)) { + return "error"; + } Review review = this.reviewService.findReviewById(reviewId); model.addAttribute("review", review); @@ -77,12 +97,17 @@ public class ReviewController { @PostMapping(value = "/reviews/{reviewId}/edit") public String updateReview(@Valid final Review reviewEdit, final BindingResult result, final ModelMap model) { - + if (!this.checkIdentity(reviewEdit.getId())) { + return "error"; + } if (result.hasErrors()) { model.addAttribute("review", reviewEdit); return ReviewController.VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM; } else { + User escritor = this.userService.getCurrentUser(); + reviewEdit.setEscritor(escritor); + this.reviewService.saveReview(reviewEdit); return "redirect:/reviews/" + reviewEdit.getId(); } diff --git a/src/main/resources/messages/messages_es.properties b/src/main/resources/messages/messages_es.properties index ccf24729e..6a54b70ec 100644 --- a/src/main/resources/messages/messages_es.properties +++ b/src/main/resources/messages/messages_es.properties @@ -35,4 +35,5 @@ typeMismatch.birthDate=Fecha inválida review= Reseña reviews= Reseñas stars= Estrellas -opinion= Opinión \ No newline at end of file +opinion= Opinión +user = Nombre de usuario \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/reviews/reviewsList.jsp b/src/main/webapp/WEB-INF/jsp/reviews/reviewsList.jsp index 2bd848cd9..3f91077ca 100644 --- a/src/main/webapp/WEB-INF/jsp/reviews/reviewsList.jsp +++ b/src/main/webapp/WEB-INF/jsp/reviews/reviewsList.jsp @@ -13,6 +13,7 @@ + @@ -24,6 +25,9 @@ <%-- --%> + + + From d482751b98d65f4059395b756567cb0362104524 Mon Sep 17 00:00:00 2001 From: Martinagr32 Date: Thu, 1 Apr 2021 00:40:42 +0200 Subject: [PATCH 10/22] Little changes --- .../springframework/cheapy/model/Review.java | 2 +- .../cheapy/web/ReviewController.java | 2 -- .../resources/messages/messages_es.properties | 14 +++++------ .../jsp/reviews/createOrUpdateReviewForm.jsp | 3 +-- src/main/webapp/WEB-INF/tags/menu.tag | 25 ++++++++----------- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/model/Review.java b/src/main/java/org/springframework/cheapy/model/Review.java index b8259eb20..b69a1f179 100644 --- a/src/main/java/org/springframework/cheapy/model/Review.java +++ b/src/main/java/org/springframework/cheapy/model/Review.java @@ -16,7 +16,7 @@ public class Review extends BaseEntity{ private static final long serialVersionUID = 1L; - @NotBlank + @NotBlank(message = "Debe rellenar la valoración de Cheapy") private String opinion; @NotNull diff --git a/src/main/java/org/springframework/cheapy/web/ReviewController.java b/src/main/java/org/springframework/cheapy/web/ReviewController.java index 34ad021a5..1ac9e93d4 100644 --- a/src/main/java/org/springframework/cheapy/web/ReviewController.java +++ b/src/main/java/org/springframework/cheapy/web/ReviewController.java @@ -1,12 +1,10 @@ package org.springframework.cheapy.web; - import java.util.List; import java.util.Map; import javax.validation.Valid; -import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.Review; import org.springframework.cheapy.model.User; import org.springframework.cheapy.service.ReviewService; diff --git a/src/main/resources/messages/messages_es.properties b/src/main/resources/messages/messages_es.properties index 6a54b70ec..d2c3b9aa6 100644 --- a/src/main/resources/messages/messages_es.properties +++ b/src/main/resources/messages/messages_es.properties @@ -1,9 +1,9 @@ welcome=Bienvenido a listOffers=Ver Ofertas -foodOffers=Ofertas por plato específico -foodOffer=Oferta por plato específico -nuOffers=Ofertas por número de comensales -nuOffer=Oferta por número de comensales +foodOffers=Ofertas por plato espec�fico +foodOffer=Oferta por plato espec�fico +nuOffers=Ofertas por n�mero de comensales +nuOffer=Oferta por n�mero de comensales speedOffers=Ofertas por tiempo empleado en comer speedOffer=Oferta por tiempo empleado en comer timeOffers=Ofertas por franja horaria @@ -32,8 +32,8 @@ nonNumeric=Solo debe contener números duplicateFormSubmission=No se permite el envío de formularios duplicados typeMismatch.date=Fecha inválida typeMismatch.birthDate=Fecha inválida -review= Reseña -reviews= Reseñas +review= Reseña +reviews= Reseñas stars= Estrellas -opinion= Opinión +opinion= Opinión user = Nombre de usuario \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/reviews/createOrUpdateReviewForm.jsp b/src/main/webapp/WEB-INF/jsp/reviews/createOrUpdateReviewForm.jsp index 94e5a9e3e..52ca88dcb 100644 --- a/src/main/webapp/WEB-INF/jsp/reviews/createOrUpdateReviewForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/reviews/createOrUpdateReviewForm.jsp @@ -13,9 +13,8 @@
- - +
diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index c9132fe1e..76de4b87b 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -47,27 +47,25 @@ --> - - - Opiniones - - - - Val�ranos - + + + Opiniones + + + + Valóranos + - -
- - -
From 342a157e692d86a02704957526a5bc36b61cd6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADnAGR?= <56026685+Martinagr32@users.noreply.github.com> Date: Thu, 1 Apr 2021 01:06:19 +0200 Subject: [PATCH 11/22] Update messages_es.properties --- src/main/resources/messages/messages_es.properties | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/resources/messages/messages_es.properties b/src/main/resources/messages/messages_es.properties index d2c3b9aa6..a4d3a0ddf 100644 --- a/src/main/resources/messages/messages_es.properties +++ b/src/main/resources/messages/messages_es.properties @@ -1,9 +1,9 @@ welcome=Bienvenido a listOffers=Ver Ofertas -foodOffers=Ofertas por plato espec�fico -foodOffer=Oferta por plato espec�fico -nuOffers=Ofertas por n�mero de comensales -nuOffer=Oferta por n�mero de comensales +foodOffers=Ofertas por plato específico +foodOffer=Oferta por plato específico +nuOffers=Ofertas por número de comensales +nuOffer=Oferta por número de comensales speedOffers=Ofertas por tiempo empleado en comer speedOffer=Oferta por tiempo empleado en comer timeOffers=Ofertas por franja horaria @@ -36,4 +36,4 @@ review= Reseña reviews= Reseñas stars= Estrellas opinion= Opinión -user = Nombre de usuario \ No newline at end of file +user = Nombre de usuario From e5340de5aadde66958588c70ddec47a98cd8d1f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADnAGR?= <56026685+Martinagr32@users.noreply.github.com> Date: Thu, 1 Apr 2021 01:07:02 +0200 Subject: [PATCH 12/22] Update application.properties --- src/main/resources/application.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c93d5eac7..97ef60ff4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -16,7 +16,7 @@ spring.jpa.properties.javax.persistence.schema-generation.drop-script-source=dro # Internationalization spring.messages.basename=messages/messages - +spring.messages.encoding=UTF-8 # Views spring.mvc.view.prefix: /WEB-INF/jsp/ @@ -33,4 +33,4 @@ logging.level.org.springframework=INFO # logging.level.org.springframework.context.annotation=TRACE # Maximum time static resources should be cached -spring.resources.cache.cachecontrol.max-age=12h \ No newline at end of file +spring.resources.cache.cachecontrol.max-age=12h From d26a7582e5d0193c4d161f446bcb3437874e659f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADnAGR?= <56026685+Martinagr32@users.noreply.github.com> Date: Thu, 1 Apr 2021 01:43:52 +0200 Subject: [PATCH 13/22] Reviews and login/logout security fixed --- .../cheapy/configuration/SecurityConfiguration.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index 7189740f2..d9c57cdce 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -37,7 +37,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers("/users/new").permitAll() .antMatchers("/login/**").anonymous() - .antMatchers("/logout").permitAll() + .antMatchers("/logout").authenticated() .antMatchers("/usuarios/new").permitAll() .antMatchers("/admin/**").hasAnyAuthority("admin") @@ -50,11 +50,12 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers("/clients/new").permitAll() .antMatchers("/offers/**").permitAll() + .antMatchers("/reviews/**").authenticated() .and().formLogin() - .loginPage("/login").permitAll() + .loginPage("/login") .failureUrl("/login?error") - .and().logout().logoutSuccessUrl("/login"); + .and().logout().logoutSuccessUrl("/"); // Configuración para que funcione la consola de administración // de la BD H2 (deshabilitar las cabeceras de protección contra From dcfb78ec2ae6081efce3d6a86e2e74f986a3c283 Mon Sep 17 00:00:00 2001 From: Flor Date: Thu, 1 Apr 2021 14:13:11 +0200 Subject: [PATCH 14/22] =?UTF-8?q?Renombrado=20opini=C3=B3n=20por=20rese?= =?UTF-8?q?=C3=B1a=20en=20jsp=20y=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webapp/WEB-INF/jsp/reviews/createOrUpdateReviewForm.jsp | 6 +++--- src/main/webapp/WEB-INF/tags/menu.tag | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/webapp/WEB-INF/jsp/reviews/createOrUpdateReviewForm.jsp b/src/main/webapp/WEB-INF/jsp/reviews/createOrUpdateReviewForm.jsp index 52ca88dcb..a413cb8e5 100644 --- a/src/main/webapp/WEB-INF/jsp/reviews/createOrUpdateReviewForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/reviews/createOrUpdateReviewForm.jsp @@ -8,7 +8,7 @@

- Nueva Opinión + Nueva Reseña

@@ -20,10 +20,10 @@
- + - +
diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index 76de4b87b..40f426e7e 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -49,7 +49,7 @@ - Opiniones + Reseñas From d5ded1d809dcc83abfd3c9bf4afb909c44e498e7 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 1 Apr 2021 16:53:19 +0200 Subject: [PATCH 15/22] =?UTF-8?q?A=C3=B1adido=20placeholders=20a=20los=20f?= =?UTF-8?q?ormularios,=20arreglo=20del=20login=20y=20m=C3=A1s=20cambios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/SecurityConfiguration.java | 4 +-- .../cheapy/web/OfertaController.java | 9 +++++ src/main/less/cheapy.less | 32 +++++++++++++++++ .../resources/messages/messages_es.properties | 25 +++++++------ .../createOrUpdateFoodOfferForm.jsp | 8 ++--- src/main/webapp/WEB-INF/jsp/login.jsp | 19 ++++++---- .../nuOffers/createOrUpdateNuOfferForm.jsp | 16 ++++----- .../WEB-INF/jsp/offers/offersCreate.jsp | 36 +++++++++++++++++++ .../createOrUpdateSpeedOfferForm.jsp | 16 ++++----- .../createOrUpdateTimeOfferForm.jsp | 10 +++--- src/main/webapp/WEB-INF/jsp/welcome.jsp | 16 +++++++-- src/main/webapp/WEB-INF/tags/inputField.tag | 6 ++-- src/main/webapp/WEB-INF/tags/menu.tag | 2 +- 13 files changed, 150 insertions(+), 49 deletions(-) create mode 100644 src/main/webapp/WEB-INF/jsp/offers/offersCreate.jsp diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index 9435b1b30..747947a5a 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -47,10 +47,10 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers("/offers/speed/**").hasAnyAuthority("admin", "cliente") .antMatchers("/offers/food/**").hasAnyAuthority("admin", "cliente") .antMatchers("/owners/**").hasAnyAuthority("owner", "admin") - + .antMatchers("/clients/new").permitAll() .antMatchers("/offers").permitAll() - + .antMatchers("/offersCreate").hasAuthority("cliente") .and().formLogin() diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index c7cb3de71..d1fc6a407 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -12,6 +12,9 @@ import org.springframework.cheapy.service.FoodOfferService; import org.springframework.cheapy.service.NuOfferService; import org.springframework.cheapy.service.SpeedOfferService; import org.springframework.cheapy.service.TimeOfferService; +import org.springframework.security.authentication.AnonymousAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @@ -50,6 +53,12 @@ public class OfertaController { return "offers/offersList"; } + + @GetMapping("/offersCreate") + public String createOffers() { + + return "offers/offersCreate"; + } // @GetMapping("/owners/{ownerId}/edit") // public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { diff --git a/src/main/less/cheapy.less b/src/main/less/cheapy.less index 17d012e1f..52ebdf6ab 100644 --- a/src/main/less/cheapy.less +++ b/src/main/less/cheapy.less @@ -240,6 +240,38 @@ img.img-responsive{ background-color: rgb(40, 140, 215); } +.btn-home{ + display: table; + margin: 0 auto; +} + +.btn-create button { + background-color: rgb(40, 140, 215); + border: 1px solid rgb(0, 0, 160); + color: white; + padding: 10px 24px; + cursor: pointer; + width: 70%; + display: block; + +} + +.btn-create button:not(:last-child) { + border-bottom: none; +} + + +.btn-create button:hover { + background-color: rgb(0, 64, 128) +} + +.btn-create-max button { + padding: 20px; + margin-left:auto; + margin-right: auto; + margin-bottom: 20px; +} + .btn-mod{ display: table; margin: 0 auto; diff --git a/src/main/resources/messages/messages_es.properties b/src/main/resources/messages/messages_es.properties index f17c6626b..52ca403e5 100644 --- a/src/main/resources/messages/messages_es.properties +++ b/src/main/resources/messages/messages_es.properties @@ -4,10 +4,11 @@ deleteOffer=Eliminar Oferta cancel=Cancelar deleteOfferMessage=Confirme que quiere eliminar su oferta listOffers=Ver Ofertas -foodOffers=Ofertas por plato especifico -foodOffer=Oferta por plato especifico -nuOffers=Ofertas por numero de comensales -nuOffer=Oferta por numero de comensales +createOffers=Crear Ofertas +foodOffers=Ofertas por plato específico +foodOffer=Oferta por plato específico +nuOffers=Ofertas por número de comensales +nuOffer=Oferta por número de comensales speedOffers=Ofertas rapidez comiendo speedOffer=Oferta por comer veloz timeOffers=Ofertas por franja horaria @@ -27,12 +28,16 @@ offerBeginning=Inicio de la oferta endDate=Fecha fin offerEnding=Fin de la oferta details=Detalles -offerCode=Codigo de la oferta +offerCode=Código de la oferta return=Volver -required=Es requeridOfertas por franja horariao +required=Es requerido Ofertas por franja horaria notFound=No ha sido encontrado duplicate=Ya se encuentra en uso -nonNumeric=Sólo debe contener numeros -duplicateFormSubmission=No se permite el envío de formularios duplicados -typeMismatch.date=Fecha invalida -typeMismatch.birthDate=Fecha invalida \ No newline at end of file +nonNumeric=Sólo debe contener números +duplicateFormSubmission=No se permite el envío de formularios duplicados +typeMismatch.date=Fecha inválida +typeMismatch.birthDate=Fecha inválida +createFoodOffers= Crear ofertas por plato específico +createNuOffers= Crear ofertas por número de comensales +createSpeedOffers= Crear ofertas por rapidez comiendo +createTimeOffers= Crear ofertas por franja horaria \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp index 5c636d761..b5e5dcfaa 100644 --- a/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp @@ -16,10 +16,10 @@ - - - - + + + +
diff --git a/src/main/webapp/WEB-INF/jsp/login.jsp b/src/main/webapp/WEB-INF/jsp/login.jsp index 796cdceeb..89f886557 100644 --- a/src/main/webapp/WEB-INF/jsp/login.jsp +++ b/src/main/webapp/WEB-INF/jsp/login.jsp @@ -1,6 +1,8 @@ <%@ 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" %> @@ -275,20 +277,23 @@
- +
+ +

El usuario y/o la contraseña son incorrectos

+ +
-
-

Invalid username or password

-
+ +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersCreate.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersCreate.jsp new file mode 100644 index 000000000..51fc8d8b1 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/offers/offersCreate.jsp @@ -0,0 +1,36 @@ +<%@ 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" %> + + + +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
diff --git a/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp index 2011952d6..8f76164d5 100644 --- a/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp @@ -16,14 +16,14 @@ - - - - - - - - + + + + + + + +
diff --git a/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp index 770fb5428..82d748b3a 100644 --- a/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp @@ -16,12 +16,12 @@ - - + + - - - + + +
diff --git a/src/main/webapp/WEB-INF/jsp/welcome.jsp b/src/main/webapp/WEB-INF/jsp/welcome.jsp index 95c506f42..7f7ac42a2 100644 --- a/src/main/webapp/WEB-INF/jsp/welcome.jsp +++ b/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -1,11 +1,14 @@ <%@ 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" %> - +

@@ -14,10 +17,19 @@
-
+ + +
+ +
+
+
diff --git a/src/main/webapp/WEB-INF/tags/inputField.tag b/src/main/webapp/WEB-INF/tags/inputField.tag index 0db10f39d..72de53f0b 100644 --- a/src/main/webapp/WEB-INF/tags/inputField.tag +++ b/src/main/webapp/WEB-INF/tags/inputField.tag @@ -5,15 +5,17 @@ description="Name of corresponding property in bean object" %> <%@ attribute name="label" required="true" rtexprvalue="true" description="Label appears in red color if input is considered as invalid after submission" %> +<%@ attribute name="placeholder" required="false" rtexprvalue="true" + description="Placeholder para los campos en los input fields" %>
- +
- + diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index daa63faa2..08772d137 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -25,7 +25,7 @@ - Home + Inicio Date: Thu, 1 Apr 2021 18:52:43 +0200 Subject: [PATCH 16/22] =?UTF-8?q?A=C3=B1adidos=20los=20botones=20de=20publ?= =?UTF-8?q?icar=20ofertas=20y=20activar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WEB-INF/jsp/offers/food/foodOffersShow.jsp | 5 +++++ .../webapp/WEB-INF/jsp/offers/myOffersList.jsp | 16 ++++++++++++---- .../WEB-INF/jsp/offers/nu/nuOffersShow.jsp | 5 +++++ .../WEB-INF/jsp/offers/speed/speedOffersShow.jsp | 5 +++++ .../WEB-INF/jsp/offers/time/timeOffersShow.jsp | 5 +++++ 5 files changed, 32 insertions(+), 4 deletions(-) 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 44b10a7f0..043248d25 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp @@ -49,6 +49,11 @@ Editar oferta + + + + + Activar oferta diff --git a/src/main/webapp/WEB-INF/jsp/offers/myOffersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/myOffersList.jsp index 201065542..cdaa65a66 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/myOffersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/myOffersList.jsp @@ -16,7 +16,9 @@ - + + + Nueva oferta @@ -55,7 +57,9 @@ - + + + Nueva oferta @@ -91,7 +95,9 @@ - + + + Nueva oferta @@ -128,7 +134,9 @@ - + + + Nueva oferta 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 f5a351168..8f916aeb6 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp @@ -60,6 +60,11 @@ Editar oferta + + + + + Activar 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 de2a32a80..54d492ac2 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp @@ -61,6 +61,11 @@ Editar oferta + + + + Activar 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 3db0c885a..a291144d9 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp @@ -37,6 +37,11 @@ Editar oferta + + + + Activar oferta + From db9cbbd8faff4b74e5d69388107cb4011f5f543f Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 1 Apr 2021 19:08:14 +0200 Subject: [PATCH 17/22] Validaciones de atributos hidden --- .../cheapy/web/FoodOfferController.java | 49 ++++++++++++++----- .../cheapy/web/NuOfferController.java | 37 +++++++++----- .../cheapy/web/SpeedOfferController.java | 42 ++++++++++++---- .../cheapy/web/TimeOfferController.java | 48 ++++++++++++------ src/main/resources/db/mysql/data.sql | 20 ++++++-- .../food/createOrUpdateFoodOfferForm.jsp | 1 + .../jsp/offers/food/foodOffersDisable.jsp | 3 -- .../WEB-INF/jsp/offers/nu/nuOffersDisable.jsp | 7 --- .../jsp/offers/speed/speedOffersDisable.jsp | 7 --- .../jsp/offers/time/timeOffersDisable.jsp | 4 -- 10 files changed, 145 insertions(+), 73 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java index 187d27e62..60491c56a 100644 --- a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java @@ -4,8 +4,10 @@ package org.springframework.cheapy.web; import java.time.format.DateTimeFormatter; import java.util.Map; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.StatusOffer; @@ -30,7 +32,7 @@ public class FoodOfferController { this.foodOfferService = foodOfferService; this.clientService = clientService; } - + private boolean checkIdentity(final int foodOfferId) { boolean res = false; Client client = this.clientService.getCurrentClient(); @@ -42,6 +44,15 @@ public class FoodOfferController { return res; } + private boolean checkOffer(final FoodOffer session, final FoodOffer offer) { + boolean res = false; + if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() + && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) { + res = true; + } + return res; + } + @GetMapping("/offers/food/new") public String initCreationForm(Map model) { FoodOffer foodOffer = new FoodOffer(); @@ -61,7 +72,7 @@ public class FoodOfferController { return "redirect:/offers/food/" + foodOffer.getId(); } } - + @GetMapping(value = "/offers/food/{foodOfferId}/activate") public String activateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, ModelMap modelMap) { FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); @@ -73,7 +84,7 @@ public class FoodOfferController { } else { modelMap.addAttribute("message", "You don't have access to this food offer"); } - return "redirect:/offers/food/"+foodOfferId; + return "redirect:/offers/food/" + foodOfferId; } @@ -83,29 +94,41 @@ public class FoodOfferController { FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); model.put("foodOffer", foodOffer); - + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); - + return "offers/food/foodOffersShow"; } @GetMapping(value = "/offers/food/{foodOfferId}/edit") - public String updateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) { - + public String updateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model, + HttpServletRequest request) { + if (!this.checkIdentity(foodOfferId)) { return "error"; } - FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); + if (foodOffer.getStatus().equals(StatusOffer.inactive)) { + return "error"; + } model.addAttribute("foodOffer", foodOffer); + request.getSession().setAttribute("idFood", foodOfferId); 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, HttpServletRequest request) { + if (!this.checkIdentity(foodOfferEdit.getId())) { + System.out.println("Fallo Indentity"); + return "error"; + } + Integer id = (Integer) request.getSession().getAttribute("idFood"); + FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(id); + if (!this.checkOffer(foodOffer, foodOfferEdit)) { + System.out.println("Fallo offer"); return "error"; } @@ -114,6 +137,8 @@ public class FoodOfferController { return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; } else { + BeanUtils.copyProperties(this.foodOfferService.findFoodOfferById(foodOfferEdit.getId()), foodOfferEdit, + "start", "end", "food", "discount"); this.foodOfferService.saveFoodOffer(foodOfferEdit); return "redirect:/offers/food/" + foodOfferEdit.getId(); } @@ -121,7 +146,7 @@ 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"; } @@ -133,7 +158,7 @@ public class FoodOfferController { @PostMapping(value = "/offers/food/{foodOfferId}/disable") public String disableFoodOfferForm(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) { - + if (!this.checkIdentity(foodOfferId)) { return "error"; } diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index 10d506aba..55145f399 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -4,20 +4,19 @@ import java.security.Principal; import java.time.format.DateTimeFormatter; import java.util.Map; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.StatusOffer; +import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.Client; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.NuOfferService; 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; @@ -34,11 +33,6 @@ 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(); @@ -57,6 +51,15 @@ public class NuOfferController { return res; } + private boolean checkOffer(final NuOffer session, final NuOffer offer) { + boolean res = false; + if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() + && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) { + res = true; + } + return res; + } + @PostMapping("/offers/nu/new") public String processCreationForm(@Valid NuOffer nuOffer, BindingResult result) { if (result.hasErrors()) { @@ -100,29 +103,41 @@ public class NuOfferController { } @GetMapping(value = "/offers/nu/{nuOfferId}/edit") - public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap model) { + public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap model, + HttpServletRequest request) { if (!this.checkIdentity(nuOfferId)) { return "error"; } - NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); + if (nuOffer.getStatus().equals(StatusOffer.inactive)) { + return "error"; + } model.addAttribute("nuOffer", nuOffer); + request.getSession().setAttribute("idNu", nuOfferId); return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping(value = "/offers/nu/{nuOfferId}/edit") - public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final ModelMap model) { + public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final ModelMap model, + HttpServletRequest request) { if (!this.checkIdentity(nuOfferEdit.getId())) { return "error"; } + Integer id = (Integer) request.getSession().getAttribute("idNu"); + NuOffer nuOffer = this.nuOfferService.findNuOfferById(id); + if (!this.checkOffer(nuOffer, nuOfferEdit)) { + return "error"; + } if (result.hasErrors()) { model.addAttribute("nuOffer", nuOfferEdit); return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; } else { + BeanUtils.copyProperties(this.nuOfferService.findNuOfferById(nuOfferEdit.getId()), nuOfferEdit, "start", + "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze"); this.nuOfferService.saveNuOffer(nuOfferEdit); return "redirect:/offers/nu/" + nuOfferEdit.getId(); } diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java index 8739479d4..fd3e43e6c 100644 --- a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -3,10 +3,12 @@ package org.springframework.cheapy.web; import java.time.format.DateTimeFormatter; import java.util.Map; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; +import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.Client; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.SpeedOfferService; @@ -29,7 +31,7 @@ public class SpeedOfferController { this.speedOfferService = speedOfferService; this.clientService = clientService; } - + private boolean checkIdentity(final int speedOfferId) { boolean res = false; Client client = this.clientService.getCurrentClient(); @@ -41,6 +43,15 @@ public class SpeedOfferController { return res; } + private boolean checkOffer(final SpeedOffer session, final SpeedOffer offer) { + boolean res = false; + if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() + && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) { + res = true; + } + return res; + } + @GetMapping("/offers/speed/new") public String initCreationForm(Map model) { SpeedOffer speedOffer = new SpeedOffer(); @@ -61,7 +72,6 @@ public class SpeedOfferController { } } - @GetMapping(value = "/offers/speed/{speedOfferId}/activate") public String activateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, ModelMap modelMap) { SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); @@ -87,29 +97,41 @@ public class SpeedOfferController { } @GetMapping(value = "/offers/speed/{speedOfferId}/edit") - public String updateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) { - + public String updateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model, HttpServletRequest request) { + if (!this.checkIdentity(speedOfferId)) { return "error"; } - SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); + if (speedOffer.getStatus().equals(StatusOffer.inactive)) { + return "error"; + } + model.addAttribute("speedOffer", speedOffer); + request.getSession().setAttribute("idSpeed", speedOfferId); return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping(value = "/offers/speed/{speedOfferId}/edit") - public String updateSpeedOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, final ModelMap model) { - + public String updateSpeedOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, + final ModelMap model, HttpServletRequest request) { + if (!this.checkIdentity(speedOfferEdit.getId())) { return "error"; } - + Integer id = (Integer) request.getSession().getAttribute("idSpeed"); + SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(id); + if (!this.checkOffer(speedOffer, speedOfferEdit)) { + return "error"; + } + if (result.hasErrors()) { model.addAttribute("speedOffer", speedOfferEdit); return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; } else { + BeanUtils.copyProperties(this.speedOfferService.findSpeedOfferById(speedOfferEdit.getId()), speedOfferEdit, + "start", "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze"); this.speedOfferService.saveSpeedOffer(speedOfferEdit); return "redirect:/offers/speed/" + speedOfferEdit.getId(); } @@ -118,7 +140,7 @@ 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"; } @@ -130,7 +152,7 @@ public class SpeedOfferController { @PostMapping(value = "/offers/speed/{speedOfferId}/disable") public String disableSpeedOfferForm(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) { - + if (!this.checkIdentity(speedOfferId)) { return "error"; } diff --git a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java index eb795cf35..e51e1b4e8 100644 --- a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java @@ -1,11 +1,12 @@ package org.springframework.cheapy.web; - import java.time.format.DateTimeFormatter; import java.util.Map; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; @@ -29,7 +30,7 @@ public class TimeOfferController { this.timeOfferService = timeOfferService; this.clientService = clientService; } - + private boolean checkIdentity(final int timeOfferId) { boolean res = false; Client client = this.clientService.getCurrentClient(); @@ -41,6 +42,15 @@ public class TimeOfferController { return res; } + private boolean checkOffer(final TimeOffer session, final TimeOffer offer) { + boolean res = false; + if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() + && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) { + res = true; + } + return res; + } + @GetMapping("/offers/time/new") public String initCreationForm(Map model) { TimeOffer timeOffer = new TimeOffer(); @@ -64,7 +74,7 @@ public class TimeOfferController { } } - @GetMapping(value ="/offers/time/{timeOfferId}/activate") + @GetMapping(value = "/offers/time/{timeOfferId}/activate") public String activateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap modelMap) { Client client = this.clientService.getCurrentClient(); TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); @@ -73,13 +83,11 @@ public class TimeOfferController { timeOffer.setCode("TI-" + timeOfferId); this.timeOfferService.saveTimeOffer(timeOffer); - } else { modelMap.addAttribute("message", "You don't have access to this time offer"); } return "redirect:/offers/time/" + timeOffer.getId(); - } @GetMapping("/offers/time/{timeOfferId}") @@ -90,35 +98,48 @@ public class TimeOfferController { model.put("timeOffer", timeOffer); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); - + return "offers/time/timeOffersShow"; } @GetMapping(value = "/offers/time/{timeOfferId}/edit") - public String updateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) { - + public String updateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model, + HttpServletRequest request) { + if (!this.checkIdentity(timeOfferId)) { return "error"; } - TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); + if (timeOffer.getStatus().equals(StatusOffer.inactive)) { + return "error"; + } + model.addAttribute("timeOffer", timeOffer); + request.getSession().setAttribute("idTime", timeOfferId); return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping(value = "/offers/time/{timeOfferId}/edit") - public String updateTimeOffer(@Valid final TimeOffer timeOfferEdit, final BindingResult result, final ModelMap model) { - + public String updateTimeOffer(@Valid final TimeOffer timeOfferEdit, final BindingResult result, + final ModelMap model, HttpServletRequest request) { + if (!this.checkIdentity(timeOfferEdit.getId())) { return "error"; } + Integer id = (Integer) request.getSession().getAttribute("idTime"); + TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(id); + if (!this.checkOffer(timeOffer, timeOfferEdit)) { + return "error"; + } if (result.hasErrors()) { model.addAttribute("timeOffer", timeOfferEdit); return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; } else { + BeanUtils.copyProperties(this.timeOfferService.findTimeOfferById(timeOfferEdit.getId()), timeOfferEdit, + "start", "end", "init", "finish", "discount"); this.timeOfferService.saveTimeOffer(timeOfferEdit); return "redirect:/offers/time/" + timeOfferEdit.getId(); } @@ -127,7 +148,7 @@ 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"; } @@ -139,7 +160,7 @@ public class TimeOfferController { @PostMapping(value = "/offers/time/{timeOfferId}/disable") public String disableTimeOfferForm(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) { - + if (!this.checkIdentity(timeOfferId)) { return "error"; } @@ -152,7 +173,6 @@ public class TimeOfferController { return "redirect:/myOffers"; - } } diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index 39f0ca7b1..c279eadf3 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -11,8 +11,8 @@ INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Wa INSERT INTO users (dtype,username,password,enabled) VALUES ('User','admin','admin', TRUE ); INSERT INTO authorities VALUES ('admin','admin'); -INSERT INTO users (dtype,username,password,enabled) VALUES ('User','manoli','manoli', TRUE ); +INSERT INTO users (dtype,username,password,enabled) VALUES ('User','manoli','manoli', TRUE ); INSERT INTO authorities VALUES ('manoli','client'); INSERT INTO users (dtype,username,password,enabled) VALUES ('User','david','david', TRUE ); INSERT INTO authorities VALUES ('david','client'); @@ -32,8 +32,18 @@ INSERT INTO usuarios VALUES (4, 'Pepe', 'Lopez', '12456776V', 'C/Macarena', '690 INSERT INTO clients (id, name, email, address, init, finish, telephone, description, code, food, username) VALUES (1,'bar manoli','manoli@gmail.com','C/Betis','10:00','22:00','608726190', 'description 1', 'code1', 'ESPAÑOLA','manoli'); INSERT INTO clients (id, name, email, address, init, finish, telephone, description, code, food, username) VALUES (2,'bar david','david@gmail.com','C/Sevilla','09:30','22:00','608726190', 'description 2', 'code2', 'americana','david'); -INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'FO-1', 'inactive', 1, 'macarrones', 15); -INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'T-1', 'active', 1, '12:00:00', '13:00:00', 10); -INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'SP-1', 'active',1,5,25,10,15,15,10); -INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'NU-1', 'active',1,15,25,10,15,5,10); +INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'FO-1', 'inactive', 1, 'macarrones', 15); +INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'FO-2', 'active', 1, 'macarrones con tomate', 10); +INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden', 1, 'macarrones con queso', 5); +INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'T-1', 'inactive', 1, '12:00:00', '13:00:00', 5); +INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-2', 'active', 1, '12:00:00', '13:00:00', 10); +INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden', 1, '12:00:00', '13:00:00', 15); + +INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'SP-1', 'inactive',1,5,25,10,15,15,10); +INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-2', 'active',1,5,25,10,15,15,10); +INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden',1,5,25,10,15,15,10); + +INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'NU-1', 'inactive',1,15,25,10,15,5,10); +INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-2', 'active',1,15,25,10,15,5,10); +INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden',1,15,25,10,15,5,10); diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp index b3a319d5c..7c53f2cf7 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp @@ -10,6 +10,7 @@

Nueva Oferta de plato específico

+
diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp index d2012045b..a450ece8b 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp @@ -11,9 +11,6 @@

¿Está seguro de que quiere eliminar su oferta?

- - - diff --git a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp index 97068ef27..6bf09ab33 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp @@ -11,13 +11,6 @@

¿Está seguro de que quiere dar de baja su oferta?

- - - - - - - diff --git a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp index 0a786416f..f4413b129 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp @@ -11,13 +11,6 @@

¿Está seguro de que quiere dar de baja su oferta?

- - - - - - - diff --git a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp index 020d3023f..a450ece8b 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp @@ -11,10 +11,6 @@

¿Está seguro de que quiere eliminar su oferta?

- - - - From 78bba05da22bf8d6115c236105e98f1931b4fabf Mon Sep 17 00:00:00 2001 From: Thiloparn <48439369+Thiloparn@users.noreply.github.com> Date: Thu, 1 Apr 2021 21:25:23 +0200 Subject: [PATCH 18/22] Validadores de fechas de ofertas, horarios, condiciones de descuentos y descuentos. --- .../cheapy/web/FoodOfferController.java | 18 ++++- .../cheapy/web/NuOfferController.java | 66 ++++++++++++++++--- .../cheapy/web/SpeedOfferController.java | 49 ++++++++++++++ .../cheapy/web/TimeOfferController.java | 35 ++++++++++ 4 files changed, 158 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java index 60491c56a..3cd695532 100644 --- a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java @@ -52,6 +52,14 @@ public class FoodOfferController { } return res; } + + private boolean checkDates(final FoodOffer foodOffer) { + boolean res = false; + if(foodOffer.getEnd().isAfter(foodOffer.getStart())) { + res = true; + } + return res; + } @GetMapping("/offers/food/new") public String initCreationForm(Map model) { @@ -65,6 +73,10 @@ public class FoodOfferController { if (result.hasErrors()) { return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(foodOffer)) { + //Poner aqui mensaje de error + return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; + } Client client = this.clientService.getCurrentClient(); foodOffer.setClient(client); foodOffer.setStatus(StatusOffer.hidden); @@ -122,13 +134,11 @@ public class FoodOfferController { final ModelMap model, HttpServletRequest request) { if (!this.checkIdentity(foodOfferEdit.getId())) { - System.out.println("Fallo Indentity"); return "error"; } Integer id = (Integer) request.getSession().getAttribute("idFood"); FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(id); if (!this.checkOffer(foodOffer, foodOfferEdit)) { - System.out.println("Fallo offer"); return "error"; } @@ -137,6 +147,10 @@ public class FoodOfferController { return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(foodOfferEdit)) { + //Poner aqui mensaje de error + return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; + } BeanUtils.copyProperties(this.foodOfferService.findFoodOfferById(foodOfferEdit.getId()), foodOfferEdit, "start", "end", "food", "discount"); this.foodOfferService.saveFoodOffer(foodOfferEdit); diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index 55145f399..7c8826521 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -8,9 +8,11 @@ import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import org.springframework.cheapy.model.NuOffer; +import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.Client; +import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.NuOfferService; import org.springframework.stereotype.Controller; @@ -32,14 +34,7 @@ public class NuOfferController { this.nuOfferService = nuOfferService; this.clientService = clientService; } - - @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(); @@ -59,12 +54,55 @@ public class NuOfferController { } return res; } + + private boolean checkDates(final NuOffer nuOffer) { + boolean res = false; + if(nuOffer.getEnd().isAfter(nuOffer.getStart())) { + res = true; + } + return res; + } + + private boolean checkConditions(final NuOffer NuOffer) { + boolean res = false; + if(NuOffer.getGold() > NuOffer.getSilver() && NuOffer.getSilver() > NuOffer.getBronze()) { + res = true; + } + return res; + } + + private boolean checkDiscounts(final NuOffer NuOffer) { + boolean res = false; + if(NuOffer.getDiscountGold() > NuOffer.getDiscountSilver() && NuOffer.getDiscountSilver() > NuOffer.getDiscountBronze()) { + res = true; + } + return res; + } + + @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; + } @PostMapping("/offers/nu/new") public String processCreationForm(@Valid NuOffer nuOffer, BindingResult result) { if (result.hasErrors()) { return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(nuOffer)) { + //Poner aqui mensaje de error + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkConditions(nuOffer)) { + //Poner aqui mensaje de error + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkDiscounts(nuOffer)) { + //Poner aqui mensaje de error + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } nuOffer.setStatus(StatusOffer.hidden); Client client = this.clientService.getCurrentClient(); @@ -136,6 +174,18 @@ public class NuOfferController { return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(nuOffer)) { + //Poner aqui mensaje de error + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkConditions(nuOffer)) { + //Poner aqui mensaje de error + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkDiscounts(nuOffer)) { + //Poner aqui mensaje de error + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } BeanUtils.copyProperties(this.nuOfferService.findNuOfferById(nuOfferEdit.getId()), nuOfferEdit, "start", "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze"); this.nuOfferService.saveNuOffer(nuOfferEdit); diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java index fd3e43e6c..5b7e5aada 100644 --- a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -10,6 +10,7 @@ import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.Client; +import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.SpeedOfferService; import org.springframework.stereotype.Controller; @@ -51,6 +52,30 @@ public class SpeedOfferController { } return res; } + + private boolean checkDates(final SpeedOffer speedOffer) { + boolean res = false; + if(speedOffer.getEnd().isAfter(speedOffer.getStart())) { + res = true; + } + return res; + } + + private boolean checkConditions(final SpeedOffer speedOffer) { + boolean res = false; + if(speedOffer.getGold() < speedOffer.getSilver() && speedOffer.getSilver() < speedOffer.getBronze()) { + res = true; + } + return res; + } + + private boolean checkDiscounts(final SpeedOffer speedOffer) { + boolean res = false; + if(speedOffer.getDiscountGold() > speedOffer.getDiscountSilver() && speedOffer.getDiscountSilver() > speedOffer.getDiscountBronze()) { + res = true; + } + return res; + } @GetMapping("/offers/speed/new") public String initCreationForm(Map model) { @@ -64,6 +89,18 @@ public class SpeedOfferController { if (result.hasErrors()) { return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(speedOffer)) { + //Poner aqui mensaje de error + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkConditions(speedOffer)) { + //Poner aqui mensaje de error + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkDiscounts(speedOffer)) { + //Poner aqui mensaje de error + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } Client client = this.clientService.getCurrentClient(); speedOffer.setClient(client); speedOffer.setStatus(StatusOffer.hidden); @@ -130,6 +167,18 @@ public class SpeedOfferController { return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(speedOffer)) { + //Poner aqui mensaje de error + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkConditions(speedOffer)) { + //Poner aqui mensaje de error + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkDiscounts(speedOffer)) { + //Poner aqui mensaje de error + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } BeanUtils.copyProperties(this.speedOfferService.findSpeedOfferById(speedOfferEdit.getId()), speedOfferEdit, "start", "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze"); this.speedOfferService.saveSpeedOffer(speedOfferEdit); diff --git a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java index e51e1b4e8..5b58bed76 100644 --- a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java @@ -8,6 +8,7 @@ import javax.validation.Valid; import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.Client; +import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.service.ClientService; @@ -50,6 +51,22 @@ public class TimeOfferController { } return res; } + + private boolean checkDates(final TimeOffer timeOffer) { + boolean res = false; + if(timeOffer.getEnd().isAfter(timeOffer.getStart())) { + res = true; + } + return res; + } + + private boolean checkTimes(final TimeOffer timeOffer) { + boolean res = false; + if(timeOffer.getFinish().isAfter(timeOffer.getInit())) { + res = true; + } + return res; + } @GetMapping("/offers/time/new") public String initCreationForm(Map model) { @@ -63,6 +80,16 @@ public class TimeOfferController { if (result.hasErrors()) { return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(timeOffer)) { + //Poner aqui mensaje de error + return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + } + + if(!this.checkTimes(timeOffer)) { + //Poner aqui mensaje de error + return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + } + timeOffer.setStatus(StatusOffer.hidden); Client client = this.clientService.getCurrentClient(); @@ -138,6 +165,14 @@ public class TimeOfferController { return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(timeOffer)) { + //Poner aqui mensaje de error + return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkTimes(timeOffer)) { + //Poner aqui mensaje de error + return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + } BeanUtils.copyProperties(this.timeOfferService.findTimeOfferById(timeOfferEdit.getId()), timeOfferEdit, "start", "end", "init", "finish", "discount"); this.timeOfferService.saveTimeOffer(timeOfferEdit); From 404547547950db17fdf7a59c9fb3d8ccc37095ee Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 Apr 2021 14:06:02 +0200 Subject: [PATCH 19/22] =?UTF-8?q?Cambios=20de=20dise=C3=B1o=20en=20algunas?= =?UTF-8?q?=20vistas=20(sobretodo=20en=20las=20vistas=20de=20ofertas)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/less/cheapy.less | 33 ++++++++++++++-- .../resources/messages/messages_es.properties | 26 +++++++------ .../createOrUpdateFoodOfferForm.jsp | 26 +++++++++---- .../WEB-INF/jsp/foodOffers/foodOffersShow.jsp | 10 ++++- src/main/webapp/WEB-INF/jsp/login.jsp | 4 +- .../nuOffers/createOrUpdateNuOfferForm.jsp | 34 ++++++++++------ .../WEB-INF/jsp/nuOffers/nuOffersShow.jsp | 20 ++++++---- .../WEB-INF/jsp/offers/offersCreate.jsp | 10 +++++ .../webapp/WEB-INF/jsp/offers/offersList.jsp | 39 +++++++++++++++++++ .../createOrUpdateSpeedOfferForm.jsp | 34 ++++++++++------ .../jsp/speedOffers/speedOffersShow.jsp | 21 ++++++---- .../createOrUpdateTimeOfferForm.jsp | 28 +++++++++---- .../WEB-INF/jsp/timeOffers/timeOffersShow.jsp | 19 +++++++-- 13 files changed, 229 insertions(+), 75 deletions(-) diff --git a/src/main/less/cheapy.less b/src/main/less/cheapy.less index 52ebdf6ab..6844c25df 100644 --- a/src/main/less/cheapy.less +++ b/src/main/less/cheapy.less @@ -56,7 +56,7 @@ .table-filter { background-color: @spring-brown; - padding: 9px 12px; + padding: 5px 12px; } .nav > li > a { @@ -298,18 +298,23 @@ img.img-responsive{ #foodOfferTable th { width: 25%; + text-align: center; + } #nuOfferTable th { - width: 33%; + width: 25%; +text-align: center; } #speedOfferTable th { - width: 33%; + width: 25%; +text-align: center; } #timeOfferTable th { - width: 33%; + width: 25%; +text-align: center; } .btn-detalles button { @@ -401,18 +406,38 @@ img.img-responsive{ #foodOfferTable td{ vertical-align:middle; +text-align: center; } #nuOfferTable td{ vertical-align:middle; +text-align: center; } #speedOfferTable td{ vertical-align:middle; +text-align: center; } #timeOfferTable td{ vertical-align:middle; +text-align: center; +} + +#nuOffer-table th{ + text-align: center; +} + +#nuOffer-table td{ + text-align: center; +} + +#speedOffer-table th{ + text-align: center; +} + +#speedOffer-table td{ + text-align: center; } #nuOffer-table tr:nth-child(3){ diff --git a/src/main/resources/messages/messages_es.properties b/src/main/resources/messages/messages_es.properties index 52ca403e5..c93d14f77 100644 --- a/src/main/resources/messages/messages_es.properties +++ b/src/main/resources/messages/messages_es.properties @@ -5,10 +5,10 @@ cancel=Cancelar deleteOfferMessage=Confirme que quiere eliminar su oferta listOffers=Ver Ofertas createOffers=Crear Ofertas -foodOffers=Ofertas por plato específico -foodOffer=Oferta por plato específico -nuOffers=Ofertas por número de comensales -nuOffer=Oferta por número de comensales +foodOffers=Ofertas por plato espec�fico +foodOffer=Oferta por plato espec�fico +nuOffers=Ofertas por n�mero de comensales +nuOffer=Oferta por n�mero de comensales speedOffers=Ofertas rapidez comiendo speedOffer=Oferta por comer veloz timeOffers=Ofertas por franja horaria @@ -28,16 +28,18 @@ offerBeginning=Inicio de la oferta endDate=Fecha fin offerEnding=Fin de la oferta details=Detalles -offerCode=Código de la oferta +offerCode=C�digo de la oferta return=Volver required=Es requerido Ofertas por franja horaria notFound=No ha sido encontrado duplicate=Ya se encuentra en uso -nonNumeric=Sólo debe contener números -duplicateFormSubmission=No se permite el envío de formularios duplicados -typeMismatch.date=Fecha inválida -typeMismatch.birthDate=Fecha inválida -createFoodOffers= Crear ofertas por plato específico -createNuOffers= Crear ofertas por número de comensales +nonNumeric=S�lo debe contener n�meros +duplicateFormSubmission=No se permite el env�o de formularios duplicados +typeMismatch.date=Fecha inv�lida +typeMismatch.birthDate=Fecha inv�lida +createFoodOffers= Crear ofertas por plato espec�fico +createNuOffers= Crear ofertas por n�mero de comensales createSpeedOffers= Crear ofertas por rapidez comiendo -createTimeOffers= Crear ofertas por franja horaria \ No newline at end of file +createTimeOffers= Crear ofertas por franja horaria +init= Inicio del intervalo +finish= Fin del intervalo \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp index b5e5dcfaa..a2366158e 100644 --- a/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp @@ -4,10 +4,10 @@ <%@ 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="petclinic" tagdir="/WEB-INF/tags" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +

@@ -16,10 +16,10 @@ - - - - + + + +
@@ -40,4 +40,16 @@
- + +
+ +
+ + + diff --git a/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp index 211212e0c..36ff24281 100644 --- a/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp @@ -29,7 +29,7 @@ - + @@ -41,7 +41,7 @@
-
@@ -63,4 +63,10 @@
+ + diff --git a/src/main/webapp/WEB-INF/jsp/login.jsp b/src/main/webapp/WEB-INF/jsp/login.jsp index 89f886557..aee0598c1 100644 --- a/src/main/webapp/WEB-INF/jsp/login.jsp +++ b/src/main/webapp/WEB-INF/jsp/login.jsp @@ -296,10 +296,10 @@ - +
diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp index 352522764..d693e8ae9 100644 --- a/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp @@ -4,10 +4,10 @@ <%@ 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="petclinic" tagdir="/WEB-INF/tags" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +

@@ -16,15 +16,15 @@ - - + + - - - - - - + + + + + +
@@ -46,4 +46,16 @@
- + +
+ +
+ + + diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp index 565d2bd43..af8ceb975 100644 --- a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp @@ -22,27 +22,27 @@ - + - + - + - + Meta bronce - + - + @@ -52,7 +52,7 @@
-
@@ -74,4 +74,10 @@
+ +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersCreate.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersCreate.jsp index 51fc8d8b1..d0b418471 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersCreate.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersCreate.jsp @@ -33,4 +33,14 @@ +
+ +
+ diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp index 30ee72a07..baa17bde9 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -14,6 +14,7 @@ + @@ -25,6 +26,9 @@ + + + @@ -55,6 +59,8 @@ + + @@ -69,6 +75,12 @@ + + + + + + @@ -91,6 +103,8 @@ + + @@ -105,6 +119,12 @@ + + + + + + @@ -128,6 +148,8 @@ + + @@ -141,6 +163,13 @@ + + + + + + + @@ -155,4 +184,14 @@ +
+ +
+ diff --git a/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp index 8f76164d5..d466bc2f5 100644 --- a/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp @@ -4,10 +4,10 @@ <%@ 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="petclinic" tagdir="/WEB-INF/tags" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +

@@ -16,14 +16,14 @@ - - - - - - - - + + + + + + + +
@@ -44,4 +44,16 @@
-
+ +
+ +
+ + + diff --git a/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp index 8659f8097..85a81a438 100644 --- a/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp @@ -22,27 +22,27 @@ - + - + - + - + - + - + @@ -52,7 +52,7 @@
-
@@ -73,6 +73,11 @@ Desactivar oferta
- + + diff --git a/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp index 82d748b3a..bc8c6fde5 100644 --- a/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp @@ -4,10 +4,10 @@ <%@ 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="petclinic" tagdir="/WEB-INF/tags" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +

@@ -16,12 +16,12 @@ - - + + - - - + + +
@@ -43,4 +43,16 @@
-
+ +
+ +
+ + + diff --git a/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp index b0ffd00a6..f39937b1a 100644 --- a/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp @@ -11,7 +11,7 @@

- +
@@ -21,9 +21,17 @@ + + + + + + + + - + @@ -34,7 +42,7 @@
-
@@ -56,6 +64,11 @@
+ From f7b8a236f01400077c12872b71f2ae92bf60a3bc Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 Apr 2021 16:27:52 +0200 Subject: [PATCH 20/22] =?UTF-8?q?Arreglos=20del=20merge=20m=C3=A1s=20cambi?= =?UTF-8?q?os=20a=20las=20nuevas=20vistas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/SecurityConfiguration.java | 4 +-- .../cheapy/web/FoodOfferController.java | 2 +- .../cheapy/web/NuOfferController.java | 2 +- .../cheapy/web/SpeedOfferController.java | 2 +- .../cheapy/web/TimeOfferController.java | 2 +- src/main/less/cheapy.less | 7 ++++ .../jsp/offers/food/foodOffersDisable.jsp | 6 ++-- .../jsp/offers/food/foodOffersShow.jsp | 14 +++++--- .../WEB-INF/jsp/offers/myOffersList.jsp | 35 +++++++++++++----- .../WEB-INF/jsp/offers/nu/nuOffersDisable.jsp | 16 ++++----- .../WEB-INF/jsp/offers/nu/nuOffersShow.jsp | 36 ++++++++++--------- .../WEB-INF/jsp/offers/offersCreate.jsp | 8 ++--- .../webapp/WEB-INF/jsp/offers/offersList.jsp | 28 ++++++++++++--- .../jsp/offers/speed/speedOffersDisable.jsp | 12 +++---- .../jsp/offers/speed/speedOffersShow.jsp | 35 ++++++++++-------- .../jsp/offers/time/timeOffersDisable.jsp | 10 +++--- .../jsp/offers/time/timeOffersShow.jsp | 36 +++++++++++-------- src/main/webapp/WEB-INF/jsp/welcome.jsp | 2 +- 18 files changed, 160 insertions(+), 97 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index ce15fc2b0..e2c866bb3 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -44,12 +44,12 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers("/owners/**").hasAnyAuthority("owner", "admin") - + .antMatchers("/offers/**/edit").hasAnyAuthority("admin", "client") .antMatchers("/offers/**/new").hasAnyAuthority("admin", "client") .antMatchers("/offers/**/activate").hasAnyAuthority("admin","client") .antMatchers("/clients/new").permitAll() - .antMatchers("/offers/**").permitAll() + .antMatchers("/offers").permitAll() .antMatchers("/offersCreate").hasAuthority("client") diff --git a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java index b2870d93b..056c45331 100644 --- a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java @@ -109,7 +109,7 @@ public class FoodOfferController { FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); model.put("foodOffer", foodOffer); - return "foodOffers/foodOffersDisable"; + return "offers/food/foodOffersDisable"; } @PostMapping(value = "/offers/food/{foodOfferId}/disable") diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index d8533842d..371f9c744 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -110,7 +110,7 @@ public class NuOfferController { NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); model.put("nuOffer", nuOffer); - return "nuOffers/nuOffersDisable"; + return "offers/nu/nuOffersDisable"; } @PostMapping(value = "/offers/nu/{nuOfferId}/disable") diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java index 2162e8558..9451e570b 100644 --- a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -104,7 +104,7 @@ public class SpeedOfferController { SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); model.put("speedOffer", speedOffer); - return "speedOffers/speedOffersDisable"; + return "offers/speed/speedOffersDisable"; } @PostMapping(value = "/offers/speed/{speedOfferId}/disable") diff --git a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java index 41fcb27ce..b0aaded83 100644 --- a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java @@ -115,7 +115,7 @@ public class TimeOfferController { TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); model.put("timeOffer", timeOffer); - return "timeOffers/timeOffersDisable"; + return "offers/time/timeOffersDisable"; } @PostMapping(value = "/offers/time/{timeOfferId}/disable") diff --git a/src/main/less/cheapy.less b/src/main/less/cheapy.less index 6844c25df..a0bff3551 100644 --- a/src/main/less/cheapy.less +++ b/src/main/less/cheapy.less @@ -488,6 +488,13 @@ text-align: center; background-color: rgb(204, 128, 51); } +#vacio { + text-align:center; + font-size: 120%; + padding:10px; + color: rgb(29, 142, 226); +} + .alert-success { .alert-variant(fade(@alert-success-bg, 70%); @alert-success-border; @alert-success-text); } diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp index 14a7519e0..e293dbded 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp @@ -8,11 +8,11 @@ -

¿Esta seguro de que quiere eliminar su oferta?

+

¿Está seguro de que quiere eliminar su oferta?

- - + + 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 84757189b..cf44e42c3 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp @@ -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" %> @@ -45,7 +46,7 @@ - +
@@ -53,23 +54,28 @@ - + + - + + + +
+ - +
+ 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 c86712314..5b82667b3 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp @@ -54,7 +54,7 @@ Editar oferta - + @@ -72,9 +72,8 @@ Desactivar oferta - + - 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 fbeffec81..ba76384d7 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp @@ -66,7 +66,7 @@ - + @@ -84,8 +84,8 @@ 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 a2147de9d..f7065d80c 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp @@ -67,7 +67,7 @@ Editar oferta - + @@ -85,8 +85,9 @@ 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 fa76b0e56..df891e271 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp @@ -56,7 +56,7 @@ Editar oferta - + @@ -75,8 +75,9 @@ + - +