From a75a5adc70bb3b542207a7b9160dd3f3f4eb93b5 Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 25 Mar 2021 19:17:52 +0100 Subject: [PATCH 1/4] Modificar y eliminar ofertas de nuOffers y speedOffers, queda revisarlo --- .../springframework/cheapy/model/NuOffer.java | 7 +- .../springframework/cheapy/model/Offer.java | 5 +- .../cheapy/model/SpeedOffer.java | 7 +- .../cheapy/service/NuOfferService.java | 2 +- .../cheapy/service/SpeedOfferService.java | 2 +- .../cheapy/web/NuOfferController.java | 85 ++++++++++++++++++- .../cheapy/web/SpeedOfferController.java | 85 ++++++++++++++++++- src/main/resources/db/mysql/data.sql | 4 - .../nuOffers/createOrUpdateNuOfferForm.jsp | 39 +++++++++ .../WEB-INF/jsp/nuOffers/nuOffersDisable.jsp | 27 ++++++ .../createOrUpdateSpeedOfferForm.jsp | 37 ++++++++ .../jsp/speedOffers/speedOffersDisable.jsp | 27 ++++++ 12 files changed, 311 insertions(+), 16 deletions(-) create mode 100644 src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersDisable.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersDisable.jsp diff --git a/src/main/java/org/springframework/cheapy/model/NuOffer.java b/src/main/java/org/springframework/cheapy/model/NuOffer.java index 25ebce674..ca0965fd6 100644 --- a/src/main/java/org/springframework/cheapy/model/NuOffer.java +++ b/src/main/java/org/springframework/cheapy/model/NuOffer.java @@ -19,26 +19,27 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; @Entity @Table(name = "nu_offers") public class NuOffer extends Offer { //Oferta por numero de comensales - @NotBlank + @NotNull private Integer gold; @Column(name = "discount_gold") @NotBlank private String discountGold; - @NotBlank + @NotNull private Integer silver; @Column(name = "discount_silver") @NotBlank private String discountSilver; - @NotBlank + @NotNull private Integer bronze; @Column(name = "discount_bronze") diff --git a/src/main/java/org/springframework/cheapy/model/Offer.java b/src/main/java/org/springframework/cheapy/model/Offer.java index 0e6d23f18..17759487d 100644 --- a/src/main/java/org/springframework/cheapy/model/Offer.java +++ b/src/main/java/org/springframework/cheapy/model/Offer.java @@ -26,6 +26,7 @@ import javax.persistence.MappedSuperclass; import javax.persistence.Table; import javax.validation.constraints.Future; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import org.springframework.format.annotation.DateTimeFormat; @@ -33,12 +34,12 @@ import org.springframework.format.annotation.DateTimeFormat; public class Offer extends BaseEntity { //Clase padre @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") - @NotBlank + @NotNull @Future private LocalDateTime start; @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") - @NotBlank + @NotNull @Future private LocalDateTime end; diff --git a/src/main/java/org/springframework/cheapy/model/SpeedOffer.java b/src/main/java/org/springframework/cheapy/model/SpeedOffer.java index 71e32ae3e..2f76166b8 100644 --- a/src/main/java/org/springframework/cheapy/model/SpeedOffer.java +++ b/src/main/java/org/springframework/cheapy/model/SpeedOffer.java @@ -19,26 +19,27 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; @Entity @Table(name = "speed_offers") public class SpeedOffer extends Offer { //Ofertar por rapidez comiendo - @NotBlank + @NotNull private Integer gold; // x minutos @Column(name = "discount_gold") @NotBlank private String discountGold; - @NotBlank + @NotNull private Integer silver; @Column(name = "discount_silver") @NotBlank private String discountSilver; - @NotBlank + @NotNull private Integer bronze; @Column(name = "discount_bronze") diff --git a/src/main/java/org/springframework/cheapy/service/NuOfferService.java b/src/main/java/org/springframework/cheapy/service/NuOfferService.java index 1029999d5..ce149068e 100644 --- a/src/main/java/org/springframework/cheapy/service/NuOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/NuOfferService.java @@ -30,7 +30,7 @@ public class NuOfferService { } - public void saveOwner(final NuOffer nuOffer) throws DataAccessException { // + public void saveNuOffer(final NuOffer nuOffer) throws DataAccessException { // this.nuOfferRepository.save(nuOffer); } diff --git a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java index bfc70644e..192616ca4 100644 --- a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java @@ -28,7 +28,7 @@ public class SpeedOfferService { } - public void saveOwner(final SpeedOffer speedOffer) throws DataAccessException { // + public void saveSpeedOffer(final SpeedOffer speedOffer) throws DataAccessException { // this.speedOfferRepository.save(speedOffer); } diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index bd6d34844..f0e24eed7 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -15,22 +15,29 @@ */ package org.springframework.cheapy.web; +import java.security.Principal; import java.util.ArrayList; import java.util.List; import java.util.Map; +import javax.validation.Valid; + +import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.SpeedOffer; +import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; 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.stereotype.Controller; +import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; /** @@ -42,7 +49,7 @@ import org.springframework.web.bind.annotation.PathVariable; @Controller public class NuOfferController { - //private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; + private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "nuOffers/createOrUpdateNuOfferForm"; private final FoodOfferService foodOfferService; private final NuOfferService nuOfferService; @@ -101,4 +108,80 @@ public class NuOfferController { // } + @GetMapping(value = "/offers/nu/{nuOfferId}/edit") + public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { + +// if (!this.comprobarIdentidad(principal, vehiculoId)) { +// return "exception"; +// } + + NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId); + model.put("nuOffer", nuOffer); + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + + @PostMapping(value = "/offers/nu/{nuOfferId}/edit") + public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, @PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { + +// if (!this.comprobarIdentidad(principal, vehiculoId)) { +// return "exception"; +// } + + if (result.hasErrors()) { + model.put("nuOffer", nuOfferEdit); + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + + } else { + + NuOffer nuOfferOld=this.nuOfferService.findNuOfferById(nuOfferId); + + BeanUtils.copyProperties(nuOfferEdit, nuOfferOld, "id", "client_id"); + + this.nuOfferService.saveNuOffer(nuOfferOld); + + return "redirect:"; + } + + } + + @GetMapping(value = "/offers/nu/{nuOfferId}/disable") + public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { + +// if (!this.comprobarIdentidad(principal, vehiculoId)) { +// return "exception"; +// } +// +// if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { +// model.addAttribute("x", true); +// +// } else { +// model.addAttribute("x", false); +// } + + NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId); + model.put("nuOffer", nuOffer); + return "nuOffers/nuOffersDisable"; + } + + @PostMapping(value = "/offers/nu/{nuOfferId}/disable") + public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { + +// if (!this.comprobarIdentidad(principal, vehiculoId)) { +// return "exception"; +// } +// +// if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { +// return "redirect:/cliente/vehiculos/{vehiculoId}/disable"; +// +// } else { + NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId); + + nuOffer.setType(StatusOffer.inactive); + + this.nuOfferService.saveNuOffer(nuOffer); + + return "redirect:"; + + } + } diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java index 68a377a68..38513859e 100644 --- a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -15,22 +15,29 @@ */ package org.springframework.cheapy.web; +import java.security.Principal; import java.util.ArrayList; import java.util.List; import java.util.Map; +import javax.validation.Valid; + +import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.SpeedOffer; +import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; 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.stereotype.Controller; +import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; /** @@ -42,7 +49,7 @@ import org.springframework.web.bind.annotation.PathVariable; @Controller public class SpeedOfferController { - //private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; + private static final String VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM = "speedOffers/createOrUpdateSpeedOfferForm"; private final FoodOfferService foodOfferService; private final NuOfferService nuOfferService; @@ -100,5 +107,81 @@ public class SpeedOfferController { // return mav; // } + @GetMapping(value = "/offers/speed/{speedOfferId}/edit") + public String updateNuOffer(@PathVariable("speedOfferId") final int speedOfferId, final Principal principal, final ModelMap model) { + +// if (!this.comprobarIdentidad(principal, vehiculoId)) { +// return "exception"; +// } + + SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId); + model.put("speedOffer", speedOffer); + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } + + @PostMapping(value = "/offers/speed/{speedOfferId}/edit") + public String updateNuOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, @PathVariable("speedOfferId") final int speedOfferId, final Principal principal, final ModelMap model) { + +// if (!this.comprobarIdentidad(principal, vehiculoId)) { +// return "exception"; +// } + + if (result.hasErrors()) { + model.put("speedOffer", speedOfferEdit); + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + + } else { + + SpeedOffer speedOfferOld=this.speedOfferService.findSpeedOfferById(speedOfferId); + + BeanUtils.copyProperties(speedOfferEdit, speedOfferOld, "id", "client_id"); + + this.speedOfferService.saveSpeedOffer(speedOfferOld); + + return "redirect:"; + } + + } + + @GetMapping(value = "/offers/speed/{speedOfferId}/disable") + public String disableSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final Principal principal, final ModelMap model) { + +// if (!this.comprobarIdentidad(principal, vehiculoId)) { +// return "exception"; +// } +// +// if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { +// model.addAttribute("x", true); +// +// } else { +// model.addAttribute("x", false); +// } + + SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId); + model.put("speedOffer", speedOffer); + return "speedOffers/speedOffersDisable"; + } + + @PostMapping(value = "/offers/speed/{speedOfferId}/disable") + public String disableNuOfferForm(@PathVariable("speedOfferId") final int speedOfferId, final Principal principal, final ModelMap model) { + +// if (!this.comprobarIdentidad(principal, vehiculoId)) { +// return "exception"; +// } +// +// if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { +// return "redirect:/cliente/vehiculos/{vehiculoId}/disable"; +// +// } else { + SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId); + + speedOffer.setType(StatusOffer.inactive); + + this.speedOfferService.saveSpeedOffer(speedOffer); + + return "redirect:"; + + } + } diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index b1bab7a65..d0f4aac33 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -11,14 +11,10 @@ INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Wa INSERT INTO food_offers(start, end, code, type, client_id, food, discount, units) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, 'macarrones', '15%', 10); - INSERT INTO time_offers(start, end, code, type, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, '12:00:00', '13:00:00', '10%'); INSERT INTO speed_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null,5,'25%',10,'15%',15,'10%' ); INSERT INTO nu_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null,15,'25%',10,'15%',5,'10%' ); ---insert into usuarios(username, password, enabled) values ('admin3', 'admin', true); ---insert into authorities(id ,usuario, authority) values (42,'admin3', 'admin'); - INSERT INTO users(username,password,enabled) VALUES ('admin1','4dm1n',TRUE); INSERT INTO authorities(id,username,authority) VALUES (1,'admin1','admin'); diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp new file mode 100644 index 000000000..e0d2366cd --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp @@ -0,0 +1,39 @@ +<%@ 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="petclinic" tagdir="/WEB-INF/tags" %> + + +

+ New NuOffer +

+ +
+ + + + + + + + + + +
+
+
+ + + + + + + + +
+
+
+
diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersDisable.jsp new file mode 100644 index 000000000..83fa94c10 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersDisable.jsp @@ -0,0 +1,27 @@ +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ 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="fn" uri="http://java.sun.com/jsp/jstl/functions"%> + + + + +

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

+ + + + + + + + + + + + + Volver + +
+
diff --git a/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp new file mode 100644 index 000000000..f813733b0 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp @@ -0,0 +1,37 @@ +<%@ 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="petclinic" tagdir="/WEB-INF/tags" %> + + +

+ New SpeedOffer +

+ +
+ + + + + + + + +
+
+
+ + + + + + + + +
+
+
+
diff --git a/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersDisable.jsp new file mode 100644 index 000000000..0e2febbf0 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersDisable.jsp @@ -0,0 +1,27 @@ +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ 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="fn" uri="http://java.sun.com/jsp/jstl/functions"%> + + + + +

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

+ + + + + + + + + + + + + Volver + +
+
From dbf0b01744eb13a67830625da5f3eaa0fc07e675 Mon Sep 17 00:00:00 2001 From: Javier Date: Fri, 26 Mar 2021 19:20:31 +0100 Subject: [PATCH 2/4] =?UTF-8?q?A=C3=B1adir=20jsp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cheapy/web/NuOfferController.java | 40 ++++++++++++++----- .../createOrUpdateFoodOfferForm.jsp | 31 ++++++++++++++ .../jsp/foodOffers/foodOffersDisable.jsp | 24 +++++++++++ .../nuOffers/createOrUpdateNuOfferForm.jsp | 9 +---- .../WEB-INF/jsp/nuOffers/nuOffersShow.jsp | 13 ++++-- .../createOrUpdateTimeOfferForm.jsp | 37 +++++++++++++++++ .../jsp/timeOffers/timeOffersDisable.jsp | 24 +++++++++++ 7 files changed, 158 insertions(+), 20 deletions(-) create mode 100644 src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersDisable.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersDisable.jsp diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index f0e24eed7..fb39595ed 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -25,6 +25,7 @@ import javax.validation.Valid; import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.NuOffer; +import org.springframework.cheapy.model.Owner; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; @@ -33,9 +34,12 @@ import org.springframework.cheapy.service.NuOfferService; import org.springframework.cheapy.service.SpeedOfferService; import org.springframework.cheapy.service.TimeOfferService; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; 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; @@ -51,21 +55,19 @@ public class NuOfferController { private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "nuOffers/createOrUpdateNuOfferForm"; - private final FoodOfferService foodOfferService; private final NuOfferService nuOfferService; - private final SpeedOfferService speedOfferService; - private final TimeOfferService timeOfferService; - public NuOfferController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, - final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) { - this.foodOfferService = foodOfferService; + public NuOfferController(final NuOfferService nuOfferService) { this.nuOfferService = nuOfferService; - this.speedOfferService = speedOfferService; - this.timeOfferService = timeOfferService; } + + @InitBinder + public void setAllowedFields(WebDataBinder dataBinder) { + dataBinder.setDisallowedFields("id"); + } @GetMapping("/offers/nu/{nuOfferId}") @@ -139,11 +141,31 @@ public class NuOfferController { this.nuOfferService.saveNuOffer(nuOfferOld); - return "redirect:"; + return "offers/offersList"; } } + @GetMapping(value ="/offers/nu/{nuOfferId}/edit") + public String initUpdateNuOfferForm(@PathVariable("nuOfferId") int nuOfferId, Model model) { + NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId); + model.addAttribute(nuOffer); + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + + @PostMapping("/offers/nu/{nuOfferId}/edit") + public String processUpdateOwnerForm(@Valid NuOffer nuOffer, BindingResult result, + @PathVariable("nuOfferId") int nuOfferId) { + if (result.hasErrors()) { + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + else { + nuOffer.setId(nuOfferId); + this.nuOfferService.saveNuOffer(nuOffer); + return "redirect:/offers/nu/{nuOfferId}"; + } + } + @GetMapping(value = "/offers/nu/{nuOfferId}/disable") public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { diff --git a/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp new file mode 100644 index 000000000..ff6097fe2 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp @@ -0,0 +1,31 @@ +<%@ 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="petclinic" tagdir="/WEB-INF/tags" %> + + +

+ New FoodOffer +

+ +
+ + + + + +
+
+
+ + + + + +
+
+
+
diff --git a/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersDisable.jsp new file mode 100644 index 000000000..6f14e9ba0 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersDisable.jsp @@ -0,0 +1,24 @@ +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ 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="fn" uri="http://java.sun.com/jsp/jstl/functions"%> + + + + +

¿Esta seguro de que quiere eliminar su oferta?

+ + + + + + + + + + Volver + +
+
diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp index e0d2366cd..229cd0786 100644 --- a/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp @@ -25,14 +25,9 @@
- - - - - + - - +
diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp index 9c4eca9f3..e059983b3 100644 --- a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp @@ -6,7 +6,7 @@ -

Oferta por número de comensales

+

Oferta por n�mero de comensales

@@ -48,9 +48,14 @@
- <%-- - + + - Edit Owner --%> + Editar Oferta + + + + + Eliminar Oferta
diff --git a/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp new file mode 100644 index 000000000..687a2d6b9 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp @@ -0,0 +1,37 @@ + +<%@ 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="petclinic" tagdir="/WEB-INF/tags" %> + + +

+ New TimeOffer +

+ +
+ + + + + + + +
+
+
+ + + + + + + + +
+
+
+
diff --git a/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersDisable.jsp new file mode 100644 index 000000000..0baaaabcc --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersDisable.jsp @@ -0,0 +1,24 @@ +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ 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="fn" uri="http://java.sun.com/jsp/jstl/functions"%> + + + + +

¿Esta seguro de que quiere eliminar su oferta?

+ + + + + + + + + + Volver + +
+
From 14585f778af8785a45b468750657835db5da4e4b Mon Sep 17 00:00:00 2001 From: "gabgutpri@alum.us.es" Date: Fri, 26 Mar 2021 19:28:11 +0100 Subject: [PATCH 3/4] Error corregido --- .../springframework/cheapy/model/NuOffer.java | 49 +++--- .../cheapy/model/SpeedOffer.java | 49 +++--- .../cheapy/service/NuOfferService.java | 13 +- .../cheapy/service/SpeedOfferService.java | 11 +- .../cheapy/web/NuOfferController.java | 148 ++++++------------ .../cheapy/web/SpeedOfferController.java | 148 ++++++------------ src/main/resources/db/mysql/data.sql | 8 +- .../nuOffers/createOrUpdateNuOfferForm.jsp | 7 +- .../WEB-INF/jsp/nuOffers/nuOffersShow.jsp | 6 +- .../createOrUpdateSpeedOfferForm.jsp | 7 +- .../jsp/speedOffers/speedOffersShow.jsp | 6 +- 11 files changed, 186 insertions(+), 266 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/model/NuOffer.java b/src/main/java/org/springframework/cheapy/model/NuOffer.java index ca0965fd6..37e665cbd 100644 --- a/src/main/java/org/springframework/cheapy/model/NuOffer.java +++ b/src/main/java/org/springframework/cheapy/model/NuOffer.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,85 +13,92 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.cheapy.model; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; @Entity @Table(name = "nu_offers") public class NuOffer extends Offer { -//Oferta por numero de comensales + + //Oferta por numero de comensales @NotNull - private Integer gold; + @Min(1) + private Integer gold; @Column(name = "discount_gold") @NotBlank - private String discountGold; + private String discountGold; @NotNull - private Integer silver; + @Min(1) + private Integer silver; @Column(name = "discount_silver") @NotBlank - private String discountSilver; + private String discountSilver; @NotNull - private Integer bronze; + @Min(1) + private Integer bronze; @Column(name = "discount_bronze") @NotBlank - private String discountBronze; + private String discountBronze; + public Integer getGold() { - return gold; + return this.gold; } - public void setGold(Integer gold) { + public void setGold(final Integer gold) { this.gold = gold; } public String getDiscountGold() { - return discountGold; + return this.discountGold; } - public void setDiscountGold(String discountGold) { + public void setDiscountGold(final String discountGold) { this.discountGold = discountGold; } public Integer getSilver() { - return silver; + return this.silver; } - public void setSilver(Integer silver) { + public void setSilver(final Integer silver) { this.silver = silver; } public String getDiscountSilver() { - return discountSilver; + return this.discountSilver; } - public void setDiscountSilver(String discountSilver) { + public void setDiscountSilver(final String discountSilver) { this.discountSilver = discountSilver; } public Integer getBronze() { - return bronze; + return this.bronze; } - public void setBronze(Integer bronze) { + public void setBronze(final Integer bronze) { this.bronze = bronze; } public String getDiscountBronze() { - return discountBronze; + return this.discountBronze; } - public void setDiscountBronze(String discountBronze) { + public void setDiscountBronze(final String discountBronze) { this.discountBronze = discountBronze; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/cheapy/model/SpeedOffer.java b/src/main/java/org/springframework/cheapy/model/SpeedOffer.java index 2f76166b8..ca20c296e 100644 --- a/src/main/java/org/springframework/cheapy/model/SpeedOffer.java +++ b/src/main/java/org/springframework/cheapy/model/SpeedOffer.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,85 +13,92 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.cheapy.model; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; @Entity @Table(name = "speed_offers") public class SpeedOffer extends Offer { -//Ofertar por rapidez comiendo + + //Ofertar por rapidez comiendo @NotNull - private Integer gold; // x minutos + @Min(0) + private Integer gold; // x minutos @Column(name = "discount_gold") @NotBlank - private String discountGold; + private String discountGold; @NotNull - private Integer silver; + @Min(0) + private Integer silver; @Column(name = "discount_silver") @NotBlank - private String discountSilver; + private String discountSilver; @NotNull - private Integer bronze; + @Min(0) + private Integer bronze; @Column(name = "discount_bronze") @NotBlank - private String discountBronze; + private String discountBronze; + public Integer getGold() { - return gold; + return this.gold; } - public void setGold(Integer gold) { + public void setGold(final Integer gold) { this.gold = gold; } public String getDiscountGold() { - return discountGold; + return this.discountGold; } - public void setDiscountGold(String discountGold) { + public void setDiscountGold(final String discountGold) { this.discountGold = discountGold; } public Integer getSilver() { - return silver; + return this.silver; } - public void setSilver(Integer silver) { + public void setSilver(final Integer silver) { this.silver = silver; } public String getDiscountSilver() { - return discountSilver; + return this.discountSilver; } - public void setDiscountSilver(String discountSilver) { + public void setDiscountSilver(final String discountSilver) { this.discountSilver = discountSilver; } public Integer getBronze() { - return bronze; + return this.bronze; } - public void setBronze(Integer bronze) { + public void setBronze(final Integer bronze) { this.bronze = bronze; } public String getDiscountBronze() { - return discountBronze; + return this.discountBronze; } - public void setDiscountBronze(String discountBronze) { + public void setDiscountBronze(final String discountBronze) { this.discountBronze = discountBronze; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/cheapy/service/NuOfferService.java b/src/main/java/org/springframework/cheapy/service/NuOfferService.java index ce149068e..95147d734 100644 --- a/src/main/java/org/springframework/cheapy/service/NuOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/NuOfferService.java @@ -1,18 +1,18 @@ + package org.springframework.cheapy.service; -import java.util.Collection; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.NuOffer; -import org.springframework.cheapy.model.Owner; import org.springframework.cheapy.repository.NuOfferRepository; -import org.springframework.cheapy.repository.OwnerRepository; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service public class NuOfferService { + private NuOfferRepository nuOfferRepository; @@ -21,17 +21,18 @@ public class NuOfferService { this.nuOfferRepository = nuOfferRepository; } + @Transactional public NuOffer findNuOfferById(final int id) { return this.nuOfferRepository.findById(id); } + @Transactional public List findAllNuOffer() { // return this.nuOfferRepository.findAllNuOffer(); - } - + + @Transactional public void saveNuOffer(final NuOffer nuOffer) throws DataAccessException { // this.nuOfferRepository.save(nuOffer); - } } diff --git a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java index 192616ca4..54017526a 100644 --- a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java @@ -1,6 +1,6 @@ + package org.springframework.cheapy.service; -import java.util.Collection; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; @@ -8,9 +8,11 @@ import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.repository.SpeedOfferRepository; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service public class SpeedOfferService { + private SpeedOfferRepository speedOfferRepository; @@ -19,17 +21,18 @@ public class SpeedOfferService { this.speedOfferRepository = speedOfferRepository; } + @Transactional public SpeedOffer findSpeedOfferById(final int id) { return this.speedOfferRepository.findById(id); } + @Transactional public List findAllSpeedOffer() { // return this.speedOfferRepository.findAllSpeedOffer(); - } - + + @Transactional public void saveSpeedOffer(final SpeedOffer speedOffer) throws DataAccessException { // this.speedOfferRepository.save(speedOffer); - } } diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index f0e24eed7..ff2d512d6 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,21 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.cheapy.web; import java.security.Principal; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import javax.validation.Valid; -import org.springframework.beans.BeanUtils; -import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.NuOffer; -import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; -import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.service.FoodOfferService; import org.springframework.cheapy.service.NuOfferService; import org.springframework.cheapy.service.SpeedOfferService; @@ -39,27 +34,24 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; - /** * @author Juergen Hoeller * @author Ken Krebs * @author Arjen Poutsma * @author Michael Isvy */ -@Controller +@Controller public class NuOfferController { - private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "nuOffers/createOrUpdateNuOfferForm"; + private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "nuOffers/createOrUpdateNuOfferForm"; - private final FoodOfferService foodOfferService; - private final NuOfferService nuOfferService; - private final SpeedOfferService speedOfferService; - private final TimeOfferService timeOfferService; + private final FoodOfferService foodOfferService; + private final NuOfferService nuOfferService; + private final SpeedOfferService speedOfferService; + private final TimeOfferService timeOfferService; - - public NuOfferController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, - final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) { + public NuOfferController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) { this.foodOfferService = foodOfferService; this.nuOfferService = nuOfferService; this.speedOfferService = speedOfferService; @@ -67,121 +59,77 @@ public class NuOfferController { } - @GetMapping("/offers/nu/{nuOfferId}") - public String processShowForm(@PathVariable("nuOfferId") int nuOfferId, Map model) { + public String processShowForm(@PathVariable("nuOfferId") final int nuOfferId, final Map model) { + + NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); - NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId); - model.put("nuOffer", nuOffer); - + return "nuOffers/nuOffersShow"; } -// @GetMapping("/owners/{ownerId}/edit") -// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { -// Owner owner = this.ownerService.findOwnerById(ownerId); -// model.addAttribute(owner); -// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; -// } -// -// @PostMapping("/owners/{ownerId}/edit") -// public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, -// @PathVariable("ownerId") int ownerId) { -// if (result.hasErrors()) { -// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; -// } -// else { -// owner.setId(ownerId); -// this.ownerService.saveOwner(owner); -// return "redirect:/owners/{ownerId}"; -// } -// } -// @GetMapping("/owners/{ownerId}") -// public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { -// ModelAndView mav = new ModelAndView("owners/ownerDetails"); -// Owner owner = this.ownerService.findOwnerById(ownerId); -// -// mav.addObject(owner); -// return mav; -// } - - @GetMapping(value = "/offers/nu/{nuOfferId}/edit") public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { -// if (!this.comprobarIdentidad(principal, vehiculoId)) { -// return "exception"; -// } - - NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId); - model.put("nuOffer", nuOffer); - return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); + model.addAttribute("nuOffer", nuOffer); + 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, @PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { - -// if (!this.comprobarIdentidad(principal, vehiculoId)) { -// return "exception"; -// } + public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final Principal principal, final ModelMap model) { if (result.hasErrors()) { - model.put("nuOffer", nuOfferEdit); - return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + model.addAttribute("nuOffer", nuOfferEdit); + return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; } else { - - NuOffer nuOfferOld=this.nuOfferService.findNuOfferById(nuOfferId); - - BeanUtils.copyProperties(nuOfferEdit, nuOfferOld, "id", "client_id"); - - this.nuOfferService.saveNuOffer(nuOfferOld); - - return "redirect:"; + this.nuOfferService.saveNuOffer(nuOfferEdit); + return "redirect:/offers/nu/" + nuOfferEdit.getId(); } } - + @GetMapping(value = "/offers/nu/{nuOfferId}/disable") public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { -// if (!this.comprobarIdentidad(principal, vehiculoId)) { -// return "exception"; -// } -// -// if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { -// model.addAttribute("x", true); -// -// } else { -// model.addAttribute("x", false); -// } + // if (!this.comprobarIdentidad(principal, vehiculoId)) { + // return "exception"; + // } + // + // if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { + // model.addAttribute("x", true); + // + // } else { + // model.addAttribute("x", false); + // } - NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId); + NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); model.put("nuOffer", nuOffer); return "nuOffers/nuOffersDisable"; } - @PostMapping(value = "/offers/nu/{nuOfferId}/disable") + @PostMapping(value = "/offers/nu/{nuOfferId}/disable") public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { -// if (!this.comprobarIdentidad(principal, vehiculoId)) { -// return "exception"; -// } -// -// if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { -// return "redirect:/cliente/vehiculos/{vehiculoId}/disable"; -// -// } else { - NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId); - + // if (!this.comprobarIdentidad(principal, vehiculoId)) { + // return "exception"; + // } + // + // if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { + // return "redirect:/cliente/vehiculos/{vehiculoId}/disable"; + // + // } else { + NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); + nuOffer.setType(StatusOffer.inactive); - + this.nuOfferService.saveNuOffer(nuOffer); - + return "redirect:"; - + } - + } diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java index 38513859e..bd62eee3f 100644 --- a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,21 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.cheapy.web; import java.security.Principal; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import javax.validation.Valid; -import org.springframework.beans.BeanUtils; -import org.springframework.cheapy.model.FoodOffer; -import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; -import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.service.FoodOfferService; import org.springframework.cheapy.service.NuOfferService; import org.springframework.cheapy.service.SpeedOfferService; @@ -39,27 +34,24 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; - /** * @author Juergen Hoeller * @author Ken Krebs * @author Arjen Poutsma * @author Michael Isvy */ -@Controller +@Controller public class SpeedOfferController { - private static final String VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM = "speedOffers/createOrUpdateSpeedOfferForm"; + private static final String VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM = "speedOffers/createOrUpdateSpeedOfferForm"; - private final FoodOfferService foodOfferService; - private final NuOfferService nuOfferService; - private final SpeedOfferService speedOfferService; - private final TimeOfferService timeOfferService; + private final FoodOfferService foodOfferService; + private final NuOfferService nuOfferService; + private final SpeedOfferService speedOfferService; + private final TimeOfferService timeOfferService; - - public SpeedOfferController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, - final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) { + public SpeedOfferController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) { this.foodOfferService = foodOfferService; this.nuOfferService = nuOfferService; this.speedOfferService = speedOfferService; @@ -67,121 +59,77 @@ public class SpeedOfferController { } - @GetMapping("/offers/speed/{speedOfferId}") - public String processShowForm(@PathVariable("speedOfferId") int speedOfferId, Map model) { + public String processShowForm(@PathVariable("speedOfferId") final int speedOfferId, final Map model) { + + SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); - SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId); - model.put("speedOffer", speedOffer); - + return "speedOffers/speedOffersShow"; } -// @GetMapping("/owners/{ownerId}/edit") -// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { -// Owner owner = this.ownerService.findOwnerById(ownerId); -// model.addAttribute(owner); -// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; -// } -// -// @PostMapping("/owners/{ownerId}/edit") -// public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, -// @PathVariable("ownerId") int ownerId) { -// if (result.hasErrors()) { -// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; -// } -// else { -// owner.setId(ownerId); -// this.ownerService.saveOwner(owner); -// return "redirect:/owners/{ownerId}"; -// } -// } -// @GetMapping("/owners/{ownerId}") -// public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { -// ModelAndView mav = new ModelAndView("owners/ownerDetails"); -// Owner owner = this.ownerService.findOwnerById(ownerId); -// -// mav.addObject(owner); -// return mav; -// } - @GetMapping(value = "/offers/speed/{speedOfferId}/edit") public String updateNuOffer(@PathVariable("speedOfferId") final int speedOfferId, final Principal principal, final ModelMap model) { -// if (!this.comprobarIdentidad(principal, vehiculoId)) { -// return "exception"; -// } - - SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId); - model.put("speedOffer", speedOffer); - return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); + model.addAttribute("speedOffer", speedOffer); + return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping(value = "/offers/speed/{speedOfferId}/edit") - public String updateNuOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, @PathVariable("speedOfferId") final int speedOfferId, final Principal principal, final ModelMap model) { - -// if (!this.comprobarIdentidad(principal, vehiculoId)) { -// return "exception"; -// } + public String updateNuOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, final Principal principal, final ModelMap model) { if (result.hasErrors()) { - model.put("speedOffer", speedOfferEdit); - return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + model.addAttribute("speedOffer", speedOfferEdit); + return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; } else { - - SpeedOffer speedOfferOld=this.speedOfferService.findSpeedOfferById(speedOfferId); - - BeanUtils.copyProperties(speedOfferEdit, speedOfferOld, "id", "client_id"); - - this.speedOfferService.saveSpeedOffer(speedOfferOld); - - return "redirect:"; + this.speedOfferService.saveSpeedOffer(speedOfferEdit); + return "redirect:/offers/speed/" + speedOfferEdit.getId(); } } - + @GetMapping(value = "/offers/speed/{speedOfferId}/disable") public String disableSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final Principal principal, final ModelMap model) { -// if (!this.comprobarIdentidad(principal, vehiculoId)) { -// return "exception"; -// } -// -// if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { -// model.addAttribute("x", true); -// -// } else { -// model.addAttribute("x", false); -// } + // if (!this.comprobarIdentidad(principal, vehiculoId)) { + // return "exception"; + // } + // + // if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { + // model.addAttribute("x", true); + // + // } else { + // model.addAttribute("x", false); + // } - SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId); + SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); model.put("speedOffer", speedOffer); return "speedOffers/speedOffersDisable"; } - @PostMapping(value = "/offers/speed/{speedOfferId}/disable") + @PostMapping(value = "/offers/speed/{speedOfferId}/disable") public String disableNuOfferForm(@PathVariable("speedOfferId") final int speedOfferId, final Principal principal, final ModelMap model) { -// if (!this.comprobarIdentidad(principal, vehiculoId)) { -// return "exception"; -// } -// -// if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { -// return "redirect:/cliente/vehiculos/{vehiculoId}/disable"; -// -// } else { - SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId); - + // if (!this.comprobarIdentidad(principal, vehiculoId)) { + // return "exception"; + // } + // + // if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { + // return "redirect:/cliente/vehiculos/{vehiculoId}/disable"; + // + // } else { + SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); + speedOffer.setType(StatusOffer.inactive); - + this.speedOfferService.saveSpeedOffer(speedOffer); - + return "redirect:"; - + } - - + } diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index d0f4aac33..862d199a7 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -10,10 +10,10 @@ INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Mad INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487'); -INSERT INTO food_offers(start, end, code, type, client_id, food, discount, units) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, 'macarrones', '15%', 10); -INSERT INTO time_offers(start, end, code, type, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, '12:00:00', '13:00:00', '10%'); -INSERT INTO speed_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null,5,'25%',10,'15%',15,'10%' ); -INSERT INTO nu_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null,15,'25%',10,'15%',5,'10%' ); +INSERT INTO food_offers(start, end, code, type, client_id, food, discount, units) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'F-001', 'active', null, 'macarrones', '15%', 10); +INSERT INTO time_offers(start, end, code, type, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'T-001', 'active', null, '12:00:00', '13:00:00', '10%'); +INSERT INTO speed_offers(start, end, code, type, 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-001', 'active', null,5,'25%',10,'15%',15,'10%' ); +INSERT INTO nu_offers(start, end, code, type, 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-001', 'active', null,15,'25%',10,'15%',5,'10%' ); INSERT INTO users(username,password,enabled) VALUES ('admin1','4dm1n',TRUE); INSERT INTO authorities(id,username,authority) VALUES (1,'admin1','admin'); diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp index e0d2366cd..3392a11c5 100644 --- a/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/createOrUpdateNuOfferForm.jsp @@ -12,6 +12,9 @@
+ + + @@ -27,10 +30,10 @@
- + - +
diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp index 9c4eca9f3..e52856c9d 100644 --- a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp @@ -48,9 +48,9 @@ - <%-- - + + - Edit Owner --%> + Editar ofeta diff --git a/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp index f813733b0..245444234 100644 --- a/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/speedOffers/createOrUpdateSpeedOfferForm.jsp @@ -12,6 +12,9 @@
+ + + @@ -25,10 +28,10 @@
- + - +
diff --git a/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp index 4a85df28b..ec071786d 100644 --- a/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp @@ -48,9 +48,9 @@ - <%-- - + + - Edit Owner --%> + Editar oferta From 1b211c32d530afcb9a4efbbc847f7109ff7c2e84 Mon Sep 17 00:00:00 2001 From: Javier Date: Sat, 27 Mar 2021 19:47:45 +0100 Subject: [PATCH 4/4] Modificar y eliminar ofertas con seguridad --- .../configuration/SecurityConfiguration.java | 4 +- .../cheapy/repository/ClientRepository.java | 2 +- .../cheapy/service/NuOfferService.java | 6 +- .../cheapy/service/SpeedOfferService.java | 1 - .../cheapy/web/FoodOfferController.java | 90 ++++++++++-- .../cheapy/web/NuOfferController.java | 134 ++++++++---------- .../cheapy/web/SpeedOfferController.java | 82 +++++------ .../cheapy/web/TimeOfferController.java | 133 ++++++++++++----- src/main/resources/db/mysql/data.sql | 24 ++-- .../createOrUpdateFoodOfferForm.jsp | 6 + .../WEB-INF/jsp/foodOffers/foodOffersShow.jsp | 13 +- .../WEB-INF/jsp/nuOffers/nuOffersShow.jsp | 4 +- .../jsp/speedOffers/speedOffersShow.jsp | 7 +- .../createOrUpdateTimeOfferForm.jsp | 3 + .../WEB-INF/jsp/timeOffers/timeOffersShow.jsp | 12 +- 15 files changed, 320 insertions(+), 201 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index 4c119fe2c..384f9b36b 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -36,7 +36,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.GET, "/", "/oups").permitAll() .antMatchers("/users/new").permitAll() - .antMatchers("/nuOffers/**").hasAnyAuthority("admin","client") + .antMatchers("/nuOffers/**").hasAnyAuthority("admin","cliente") .antMatchers("/timeOffers/**").hasAnyAuthority("admin","client") .antMatchers("/login/**").anonymous() @@ -49,7 +49,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers("/owners/**").hasAnyAuthority("owner", "admin") .antMatchers("/clients/new").permitAll() - .antMatchers("/offers/**").hasAnyAuthority("admin") + .antMatchers("/offers/**").hasAnyAuthority("admin", "cliente") .and().formLogin() .loginPage("/login").permitAll() diff --git a/src/main/java/org/springframework/cheapy/repository/ClientRepository.java b/src/main/java/org/springframework/cheapy/repository/ClientRepository.java index 764b35184..1e04f6f3a 100644 --- a/src/main/java/org/springframework/cheapy/repository/ClientRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/ClientRepository.java @@ -10,5 +10,5 @@ public interface ClientRepository extends CrudRepository { @Query("SELECT client FROM Client client WHERE username =:username") @Transactional(readOnly = true) Client findByUsername(String username); - + } diff --git a/src/main/java/org/springframework/cheapy/service/NuOfferService.java b/src/main/java/org/springframework/cheapy/service/NuOfferService.java index f2a174db9..d09255d64 100644 --- a/src/main/java/org/springframework/cheapy/service/NuOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/NuOfferService.java @@ -4,7 +4,6 @@ package org.springframework.cheapy.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.repository.NuOfferRepository; -import java.util.Collection; import java.util.List; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -15,7 +14,6 @@ public class NuOfferService { private NuOfferRepository nuOfferRepository; - @Autowired public NuOfferService(final NuOfferRepository nuOfferRepository) { this.nuOfferRepository = nuOfferRepository; @@ -27,12 +25,12 @@ public class NuOfferService { } @Transactional - public List findAllNuOffer() { // + public List findAllNuOffer() { return this.nuOfferRepository.findAllNuOffer(); } @Transactional - public void saveNuOffer(final NuOffer nuOffer) throws DataAccessException { // + public void saveNuOffer(final NuOffer nuOffer) throws DataAccessException { this.nuOfferRepository.save(nuOffer); } } diff --git a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java index 36d62b1ab..121874247 100644 --- a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java @@ -1,7 +1,6 @@ package org.springframework.cheapy.service; -import java.util.Collection; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.SpeedOffer; diff --git a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java index af191c66d..f70930878 100644 --- a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java @@ -11,9 +11,7 @@ import org.springframework.cheapy.service.FoodOfferService; 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; @@ -25,15 +23,20 @@ public class FoodOfferController { private final FoodOfferService foodOfferService; private final ClientService clientService; - public FoodOfferController(final FoodOfferService foodOfferService, final ClientService clientService) { this.foodOfferService = foodOfferService; this.clientService = clientService; } - @InitBinder - public void setAllowedFields(WebDataBinder dataBinder) { - dataBinder.setDisallowedFields("id"); + 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("/foodOffers/new") @@ -47,8 +50,7 @@ public class FoodOfferController { public String processCreationForm(@Valid FoodOffer foodOffer, BindingResult result) { if (result.hasErrors()) { return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; - } - else { + } else { Client client = this.clientService.getCurrentClient(); foodOffer.setClient(client); foodOffer.setType(StatusOffer.hidden); @@ -56,28 +58,88 @@ public class FoodOfferController { return "redirect:/foodOffers/" + foodOffer.getId(); } } - + @GetMapping(value = "/foodOffers/{foodOfferId}/activate") public String activateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, ModelMap modelMap) { FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); Client client = this.clientService.getCurrentClient(); - if(foodOffer.getClient().equals(client)) { + if (foodOffer.getClient().equals(client)) { foodOffer.setType(StatusOffer.active); - foodOffer.setCode("FO-"+foodOfferId); + foodOffer.setCode("FO-" + foodOfferId); this.foodOfferService.saveFoodOffer(foodOffer); } else { modelMap.addAttribute("message", "You don't have access to this food offer"); } return "redirect:/foodOffers/"; } + @GetMapping("/offers/food/{foodOfferId}") public String processShowForm(@PathVariable("foodOfferId") int foodOfferId, Map model) { - FoodOffer foodOffer=this.foodOfferService.findFoodOfferById(foodOfferId); - + FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); + model.put("foodOffer", foodOffer); - + return "foodOffers/foodOffersShow"; } + + @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) { + + if (!this.checkIdentity(foodOfferEdit.getId())) { + return "error"; + } + + if (result.hasErrors()) { + model.addAttribute("foodOffer", foodOfferEdit); + return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; + + } else { + this.foodOfferService.saveFoodOffer(foodOfferEdit); + return "redirect:/offers/food/" + foodOfferEdit.getId(); + } + } + + @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"; + } + + @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); + + foodOffer.setType(StatusOffer.inactive); + + this.foodOfferService.saveFoodOffer(foodOffer); + + return "redirect:/offers"; + + } } diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index ca0c88f19..30a9af776 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -5,57 +5,42 @@ import java.util.Map; import javax.validation.Valid; -import org.springframework.beans.BeanUtils; -import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.NuOffer; -import org.springframework.cheapy.model.Owner; -import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; -import org.springframework.cheapy.service.FoodOfferService; import org.springframework.cheapy.model.Client; -import org.springframework.cheapy.model.NuOffer; -import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.service.ClientService; - import org.springframework.cheapy.service.NuOfferService; import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; 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; - @Controller public class NuOfferController { - private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "nuOffers/createOrUpdateNuOfferForm"; + private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "nuOffers/createOrUpdateNuOfferForm"; - private final FoodOfferService foodOfferService; - private final NuOfferService nuOfferService; - private final SpeedOfferService speedOfferService; - private final TimeOfferService timeOfferService; + private final NuOfferService nuOfferService; + private final ClientService clientService; - - public NuOfferController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) { - this.foodOfferService = foodOfferService; + public NuOfferController(final NuOfferService nuOfferService, final ClientService clientService) { this.nuOfferService = nuOfferService; this.clientService = clientService; - + } - @InitBinder - public void setAllowedFields(WebDataBinder dataBinder) { - dataBinder.setDisallowedFields("id"); - } - - @InitBinder - public void setAllowedFields(WebDataBinder dataBinder) { - dataBinder.setDisallowedFields("id"); + 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; } @GetMapping("/nuOffers/new") @@ -69,48 +54,49 @@ public class NuOfferController { public String processCreationForm(@Valid NuOffer nuOffer, BindingResult result) { if (result.hasErrors()) { return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; - } - else { + } else { nuOffer.setType(StatusOffer.hidden); - + Client client = this.clientService.getCurrentClient(); - + nuOffer.setClient(client); - - + this.nuOfferService.saveNuOffer(nuOffer); return "redirect:/nuOffers/" + nuOffer.getId(); } } - @GetMapping(value ="/nuOffers/{nuOfferId}/activate") + + @GetMapping(value = "/nuOffers/{nuOfferId}/activate") public String activateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap modelMap) { Client client = this.clientService.getCurrentClient(); - NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId); - if(nuOffer.getClient().equals(client)) { + NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); + if (nuOffer.getClient().equals(client)) { nuOffer.setType(StatusOffer.active); - nuOffer.setCode("NU-"+nuOfferId); + nuOffer.setCode("NU-" + nuOfferId); this.nuOfferService.saveNuOffer(nuOffer); - - return "redirect:/nuOffers/" + nuOffer.getId(); + + return "redirect:/nuOffers/" + nuOffer.getId(); } else { - modelMap.addAttribute("message", "You don't have access to this number offer"); - } - return "redirect:/nuOffers/"; - + modelMap.addAttribute("message", "You don't have access to this number offer"); + } + return "redirect:/nuOffers/"; } - - @GetMapping("/offers/nu/{nuOfferId}") + + @GetMapping("/offers/nu/{nuOfferId}") public String processShowForm(@PathVariable("nuOfferId") int nuOfferId, Map model) { - - model.put("nuOffer", nuOffer); + NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); + model.put("nuOffer", nuOffer); return "nuOffers/nuOffersShow"; } - @GetMapping(value = "/offers/nu/{nuOfferId}/edit") - public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { + 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); @@ -118,7 +104,11 @@ public class NuOfferController { } @PostMapping(value = "/offers/nu/{nuOfferId}/edit") - public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final Principal principal, final ModelMap model) { + 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); @@ -129,20 +119,14 @@ public class NuOfferController { return "redirect:/offers/nu/" + nuOfferEdit.getId(); } } - - @GetMapping(value = "/offers/nu/{nuOfferId}/disable") - public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { - // if (!this.comprobarIdentidad(principal, vehiculoId)) { - // return "exception"; - // } - // - // if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { - // model.addAttribute("x", true); - // - // } else { - // model.addAttribute("x", false); - // } + @GetMapping(value = "/offers/nu/{nuOfferId}/disable") + 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); @@ -150,23 +134,17 @@ 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"; + } - // if (!this.comprobarIdentidad(principal, vehiculoId)) { - // return "exception"; - // } - // - // if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { - // return "redirect:/cliente/vehiculos/{vehiculoId}/disable"; - // - // } else { NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); - nuOffer.setType(StatusOffer.inactive); - this.nuOfferService.saveNuOffer(nuOffer); - - return "redirect:"; + return "redirect:/offers"; } diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java index 2d80b14d2..08684e333 100644 --- a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -1,26 +1,18 @@ package org.springframework.cheapy.web; - -import java.security.Principal; import java.util.Map; import javax.validation.Valid; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; -import org.springframework.cheapy.service.FoodOfferService; -import org.springframework.cheapy.service.NuOfferService; import org.springframework.cheapy.model.Client; -import org.springframework.cheapy.model.SpeedOffer; -import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.SpeedOfferService; 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; @@ -36,10 +28,16 @@ public class SpeedOfferController { this.speedOfferService = speedOfferService; this.clientService = clientService; } - - @InitBinder - public void setAllowedFields(WebDataBinder dataBinder) { - dataBinder.setDisallowedFields("id"); + + 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("/speedOffers/new") @@ -53,8 +51,7 @@ public class SpeedOfferController { public String processCreationForm(@Valid SpeedOffer speedOffer, BindingResult result) { if (result.hasErrors()) { return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; - } - else { + } else { Client client = this.clientService.getCurrentClient(); speedOffer.setClient(client); speedOffer.setType(StatusOffer.hidden); @@ -62,31 +59,35 @@ public class SpeedOfferController { return "redirect:/speedOffers/" + speedOffer.getId(); } } - + @GetMapping(value = "/speedOffers/{speedOfferId}/activate") public String activateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, ModelMap modelMap) { SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); Client client = this.clientService.getCurrentClient(); - if(speedOffer.getClient().equals(client)) { + if (speedOffer.getClient().equals(client)) { speedOffer.setType(StatusOffer.active); - speedOffer.setCode("SP-"+speedOfferId); + speedOffer.setCode("SP-" + speedOfferId); this.speedOfferService.saveSpeedOffer(speedOffer); } else { modelMap.addAttribute("message", "You don't have access to this speed offer"); } return "redirect:/speedOffers/"; } - - @GetMapping("/offers/speed/{speedOfferId}") + + @GetMapping("/offers/speed/{speedOfferId}") public String processShowForm(@PathVariable("speedOfferId") int speedOfferId, Map model) { - SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId); + SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); model.put("speedOffer", speedOffer); return "speedOffers/speedOffersShow"; } @GetMapping(value = "/offers/speed/{speedOfferId}/edit") - public String updateNuOffer(@PathVariable("speedOfferId") final int speedOfferId, final Principal principal, final ModelMap model) { + 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); @@ -94,7 +95,11 @@ public class SpeedOfferController { } @PostMapping(value = "/offers/speed/{speedOfferId}/edit") - public String updateNuOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, final Principal principal, final ModelMap model) { + 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); @@ -108,18 +113,11 @@ public class SpeedOfferController { } @GetMapping(value = "/offers/speed/{speedOfferId}/disable") - public String disableSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final Principal principal, final ModelMap model) { - - // if (!this.comprobarIdentidad(principal, vehiculoId)) { - // return "exception"; - // } - // - // if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { - // model.addAttribute("x", true); - // - // } else { - // model.addAttribute("x", false); - // } + 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); @@ -127,23 +125,19 @@ public class SpeedOfferController { } @PostMapping(value = "/offers/speed/{speedOfferId}/disable") - public String disableNuOfferForm(@PathVariable("speedOfferId") final int speedOfferId, final Principal principal, final ModelMap model) { + public String disableSpeedOfferForm(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) { + + if (!this.checkIdentity(speedOfferId)) { + return "error"; + } - // if (!this.comprobarIdentidad(principal, vehiculoId)) { - // return "exception"; - // } - // - // if (this.tieneCitasAceptadasYPendientes(vehiculoId)) { - // return "redirect:/cliente/vehiculos/{vehiculoId}/disable"; - // - // } else { SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); speedOffer.setType(StatusOffer.inactive); this.speedOfferService.saveSpeedOffer(speedOffer); - return "redirect:"; + return "redirect:/offers"; } } diff --git a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java index b1bc2e528..6882c57c8 100644 --- a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java @@ -1,96 +1,155 @@ package org.springframework.cheapy.web; + import java.util.Map; + import javax.validation.Valid; import org.springframework.cheapy.model.Client; -import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.model.StatusOffer; +import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.TimeOfferService; 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; - @Controller public class TimeOfferController { - private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "timeOffers/createOrUpdateTimeOfferForm"; + private static final String VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM = "timeOffers/createOrUpdateTimeOfferForm"; private final TimeOfferService timeOfferService; private final ClientService clientService; - - - public TimeOfferController(final TimeOfferService timeOfferService,ClientService clientService) { + public TimeOfferController(final TimeOfferService timeOfferService, ClientService clientService) { this.timeOfferService = timeOfferService; this.clientService = clientService; - - } - @InitBinder - public void setAllowedFields(WebDataBinder dataBinder) { - dataBinder.setDisallowedFields("id"); + } + + 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("/timeOffers/new") public String initCreationForm(Map model) { TimeOffer timeOffer = new TimeOffer(); model.put("timeOffer", timeOffer); - return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping("/timeOffers/new") public String processCreationForm(@Valid TimeOffer timeOffer, BindingResult result) { if (result.hasErrors()) { - return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; - } - else { + return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + } else { timeOffer.setType(StatusOffer.hidden); - + Client client = this.clientService.getCurrentClient(); - + timeOffer.setClient(client); - - + this.timeOfferService.saveTimeOffer(timeOffer); return "redirect:/TimeOffers/" + timeOffer.getId(); } } - @GetMapping(value ="/timeOffers/{timeOfferId}/activate") + + @GetMapping(value = "/timeOffers/{timeOfferId}/activate") public String activateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap modelMap) { Client client = this.clientService.getCurrentClient(); - TimeOffer timeOffer=this.timeOfferService.findTimeOfferById(timeOfferId); - if(timeOffer.getClient().equals(client)) { + TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); + if (timeOffer.getClient().equals(client)) { timeOffer.setType(StatusOffer.active); - timeOffer.setCode("TI-"+timeOfferId); + timeOffer.setCode("TI-" + timeOfferId); this.timeOfferService.saveTimeOffer(timeOffer); - - return "redirect:/timeOffers/" + timeOffer.getId(); + + return "redirect:/timeOffers/" + timeOffer.getId(); } else { - modelMap.addAttribute("message", "You don't have access to this time offer"); - } - return "redirect:/timeOffers/"; - + modelMap.addAttribute("message", "You don't have access to this time offer"); + } + return "redirect:/timeOffers/"; } - - @GetMapping("/offers/time/{timeOfferId}") + + @GetMapping("/offers/time/{timeOfferId}") public String processShowForm(@PathVariable("timeOfferId") int timeOfferId, Map model) { - TimeOffer timeOffer=this.timeOfferService.findTimeOfferById(timeOfferId); - + TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); + model.put("timeOffer", timeOffer); - + return "timeOffers/timeOffersShow"; } - + + @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); + 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) { + + if (!this.checkIdentity(timeOfferEdit.getId())) { + return "error"; + } + + if (result.hasErrors()) { + model.addAttribute("timeOffer", timeOfferEdit); + return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + + } else { + this.timeOfferService.saveTimeOffer(timeOfferEdit); + return "redirect:/offers/time/" + timeOfferEdit.getId(); + } + + } + + @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"; + } + + @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); + + timeOffer.setType(StatusOffer.inactive); + + this.timeOfferService.saveTimeOffer(timeOffer); + + return "redirect:/offers"; + + } } diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index f0e3afa68..57beff1a4 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -9,17 +9,17 @@ INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', ' INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435'); INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487'); -INSERT INTO users (dtype,username,password,enabled) VALUES ('user','admin','admin', TRUE ); +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','cliente'); -INSERT INTO users (dtype,username,password,enabled) VALUES ('user','david','david', TRUE ); +INSERT INTO users (dtype,username,password,enabled) VALUES ('User','david','david', TRUE ); INSERT INTO authorities VALUES ('david','cliente'); -INSERT INTO users (dtype,username,password,enabled) VALUES ('user','paco','paco', TRUE ); +INSERT INTO users (dtype,username,password,enabled) VALUES ('User','paco','paco', TRUE ); INSERT INTO authorities VALUES ('paco','usuario'); -INSERT INTO users (dtype,username,password,enabled) VALUES ('user','lolo','lolo', TRUE ); +INSERT INTO users (dtype,username,password,enabled) VALUES ('User','lolo','lolo', TRUE ); INSERT INTO authorities VALUES ('lolo','usuario'); -INSERT INTO users (dtype,username,password,enabled) VALUES ('user','pepe','pepe', TRUE ); +INSERT INTO users (dtype,username,password,enabled) VALUES ('User','pepe','pepe', TRUE ); INSERT INTO authorities VALUES ('pepe','usuario'); INSERT INTO usuarios VALUES (1, 'admin', 'admin', 'admin', 'C/admin', '000000000', 'admin@gmail.com','admin'); @@ -27,11 +27,11 @@ INSERT INTO usuarios VALUES (2, 'Paco', 'Naranjo', '21154416G', 'C/Esperanza', ' INSERT INTO usuarios VALUES (3, 'Lolo', 'Lopez', '25486596L', 'C/Macarena', '690670547' ,'Lolo@gmail.com','lolo'); INSERT INTO usuarios VALUES (4, 'Pepe', 'Lopez', '12456776V', 'C/Macarena', '690670547', 'Pepe@gmail.com','pepe'); -INSERT INTO clients VALUES (1,'manoli@gmail.com','C/Betis','10:00','22:00','608726190', 'description 1', 'code1', 'ESPAÑOLA','manoli'); -INSERT INTO clients VALUES (2,'david@gmail.com','C/Sevilla','09:30','22:00','608726190', 'description 2', 'code2', 'americana','david'); +INSERT INTO clients (id, email, address, init, finish, telephone, description, code, food, username) VALUES (1,'manoli@gmail.com','C/Betis','10:00','22:00','608726190', 'description 1', 'code1', 'ESPAÑOLA','manoli'); +INSERT INTO clients (id, email, address, init, finish, telephone, description, code, food, username) VALUES (2,'david@gmail.com','C/Sevilla','09:30','22:00','608726190', 'description 2', 'code2', 'americana','david'); -INSERT INTO food_offers(start, end, code, type, client_id, food, discount, units) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'FO-1', 'active', null, 'macarrones', '15%', 10); -INSERT INTO time_offers(start, end, code, type, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'T-1', 'active', null, '12:00:00', '13:00:00', '10%'); -INSERT INTO speed_offers(start, end, code, type, 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', null,5,'25%',10,'15%',15,'10%' ); -INSERT INTO nu_offers(start, end, code, type, 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', null,15,'25%',10,'15%',5,'10%' ); +INSERT INTO food_offers(start, end, code, type, client_id, food, discount, units) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'FO-1', 'active', 1, 'macarrones', '15%', 10); +INSERT INTO time_offers(start, end, code, type, 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, type, 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, type, 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/foodOffers/createOrUpdateFoodOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp index ff6097fe2..a1b6d9c95 100644 --- a/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/foodOffers/createOrUpdateFoodOfferForm.jsp @@ -12,6 +12,9 @@
+ + + @@ -24,6 +27,9 @@ + + +
diff --git a/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp index 0b7c8785a..6b6fcf130 100644 --- a/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp @@ -6,7 +6,7 @@ -

Oferta por plato específico

+

Oferta por plato espec�fico

@@ -36,9 +36,14 @@
- <%-- - + + - Edit Owner --%> + Editar oferta + + + + + Desactivar oferta
diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp index 6529c281b..0959918bd 100644 --- a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp @@ -49,13 +49,13 @@ - + Editar oferta - Desactiva oferta + Desactivar oferta diff --git a/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp index ec071786d..c643afdf6 100644 --- a/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp @@ -49,8 +49,13 @@ - + 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 0dc37f439..efe5160c2 100644 --- a/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/timeOffers/createOrUpdateTimeOfferForm.jsp @@ -12,6 +12,9 @@
+ + + diff --git a/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp index a344a6221..80d90e44a 100644 --- a/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp @@ -6,7 +6,7 @@ -

Oferta por franja horária

+

Oferta por franja horaria

@@ -27,5 +27,15 @@
+ + + + + Editar oferta + + + + + Desactivar oferta