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" %>
+
+
+
+ ¿Esta seguro de que quiere eliminar su oferta?
+
+