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 + +
+