From a75a5adc70bb3b542207a7b9160dd3f3f4eb93b5 Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 25 Mar 2021 19:17:52 +0100 Subject: [PATCH] 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 + +
+