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