mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 07:45:49 +00:00
Merge pull request #30 from cheapy-ispp/010-modificar-eliminar-ofertas
010 modificar eliminar ofertas
This commit is contained in:
commit
e83d68bbfb
13 changed files with 322 additions and 18 deletions
|
@ -10,11 +10,8 @@ import javax.validation.constraints.NotNull;
|
|||
@Table(name = "nu_offers")
|
||||
public class NuOffer extends Offer {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@NotNull
|
||||
private Integer gold;
|
||||
|
||||
|
|
|
@ -10,9 +10,6 @@ import javax.validation.constraints.NotNull;
|
|||
@Table(name = "speed_offers")
|
||||
public class SpeedOffer extends Offer {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
|
|
|
@ -30,7 +30,6 @@ public class NuOfferService {
|
|||
|
||||
|
||||
public void saveNuOffer(final NuOffer nuOffer) throws DataAccessException { //
|
||||
|
||||
this.nuOfferRepository.save(nuOffer);
|
||||
|
||||
}
|
||||
|
|
|
@ -28,10 +28,8 @@ public class SpeedOfferService {
|
|||
return this.speedOfferRepository.findAllSpeedOffer();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void saveSpeedOffer(final SpeedOffer speedOffer) throws DataAccessException {
|
||||
|
||||
|
||||
public void saveSpeedOffer(final SpeedOffer speedOffer) throws DataAccessException { //
|
||||
this.speedOfferRepository.save(speedOffer);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,30 @@
|
|||
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.Owner;
|
||||
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.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;
|
||||
|
@ -27,14 +42,17 @@ public class NuOfferController {
|
|||
private final NuOfferService nuOfferService;
|
||||
private final ClientService clientService;
|
||||
|
||||
|
||||
|
||||
public NuOfferController(final NuOfferService nuOfferService,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");
|
||||
|
@ -95,4 +113,100 @@ 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 "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) {
|
||||
|
||||
// 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:";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,21 @@
|
|||
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.model.Client;
|
||||
import org.springframework.cheapy.model.SpeedOffer;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
|
@ -94,4 +105,81 @@ public class SpeedOfferController {
|
|||
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) {
|
||||
|
||||
// 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:";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,3 +35,4 @@ INSERT INTO speed_offers(start, end, code, type, client_id, gold, discount_gold,
|
|||
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%' );
|
||||
|
||||
|
|
24
src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersDisable.jsp
Normal file
24
src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersDisable.jsp
Normal file
|
@ -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"%>
|
||||
|
||||
<petclinic:layout pageName="foodOffer">
|
||||
|
||||
<jsp:body>
|
||||
<h2> ¿Esta seguro de que quiere eliminar su oferta? </h2>
|
||||
|
||||
<form:form modelAttribute="foodOffer" class="form-horizontal">
|
||||
<input type="hidden" name="food" value="${food_offer.food}" />
|
||||
<input type="hidden" name="discount" value="${food_offer.discount}" />
|
||||
<input type="hidden" name="units" value="${food_offer.units}" />
|
||||
|
||||
<button class="btn btn-default" type="submit">Eliminar Oferta</button>
|
||||
</form:form>
|
||||
|
||||
<a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a>
|
||||
|
||||
</jsp:body>
|
||||
</petclinic:layout>
|
27
src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersDisable.jsp
Normal file
27
src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersDisable.jsp
Normal file
|
@ -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"%>
|
||||
|
||||
<petclinic:layout pageName="nuOffer">
|
||||
|
||||
<jsp:body>
|
||||
<h2> ¿Esta seguro de que quiere dar de baja su offer? </h2>
|
||||
|
||||
<form:form modelAttribute="nuOffer" class="form-horizontal">
|
||||
<input type="hidden" name="gold" value="${nu_offer.gold}" />
|
||||
<input type="hidden" name="discountGold" value="${nu_offer.discount_gold}" />
|
||||
<input type="hidden" name="silver" value="${nu_offer.silver}" />
|
||||
<input type="hidden" name="discountSilver" value="${nu_offer.discount_silver}" />
|
||||
<input type="hidden" name="bronze" value="${nu_offer.bronze}" />
|
||||
<input type="hidden" name="discountBronze" value="${nu_offer.discount_bronze}" />
|
||||
|
||||
<button class="btn btn-default" type="submit">Dar de baja</button>
|
||||
</form:form>
|
||||
|
||||
<a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a>
|
||||
|
||||
</jsp:body>
|
||||
</petclinic:layout>
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<cheapy:layout pageName="nuOffer">
|
||||
|
||||
<h2>Oferta por número de comensales</h2>
|
||||
<h2>Oferta por n<EFBFBD>mero de comensales</h2>
|
||||
|
||||
|
||||
<table class="table table-striped">
|
||||
|
@ -48,9 +48,14 @@
|
|||
</tr>
|
||||
</table>
|
||||
|
||||
<%-- <spring:url value="{ownerId}/edit" var="editUrl">
|
||||
<spring:param name="ownerId" value="${owner.id}"/>
|
||||
<spring:url value="{nuOfferId}/edit" var="editUrl">
|
||||
<spring:param name="nuOfferId" value="${nuOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Edit Owner</a> --%>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar Oferta</a>
|
||||
|
||||
<spring:url value="{nuOfferId}/disable" var="editUrl">
|
||||
<spring:param name="nuOfferId" value="${nuOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Eliminar Oferta</a>
|
||||
|
||||
</cheapy:layout>
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
<c:when test="${speedOffer['new']}">
|
||||
<button class="btn btn-default" type="submit">Add Speed Offer</button>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<button class="btn btn-default" type="submit">Update Offer</button>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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"%>
|
||||
|
||||
<petclinic:layout pageName="speedOffer">
|
||||
|
||||
<jsp:body>
|
||||
<h2> ¿Esta seguro de que quiere dar de baja su offer? </h2>
|
||||
|
||||
<form:form modelAttribute="speedOffer" class="form-horizontal">
|
||||
<input type="hidden" name="gold" value="${nu_offer.gold}" />
|
||||
<input type="hidden" name="discountGold" value="${nu_offer.discount_gold}" />
|
||||
<input type="hidden" name="silver" value="${nu_offer.silver}" />
|
||||
<input type="hidden" name="discountSilver" value="${nu_offer.discount_silver}" />
|
||||
<input type="hidden" name="bronze" value="${nu_offer.bronze}" />
|
||||
<input type="hidden" name="discountBronze" value="${nu_offer.discount_bronze}" />
|
||||
|
||||
<button class="btn btn-default" type="submit">Dar de baja</button>
|
||||
</form:form>
|
||||
|
||||
<a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a>
|
||||
|
||||
</jsp:body>
|
||||
</petclinic:layout>
|
24
src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersDisable.jsp
Normal file
24
src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersDisable.jsp
Normal file
|
@ -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"%>
|
||||
|
||||
<petclinic:layout pageName="foodOffer">
|
||||
|
||||
<jsp:body>
|
||||
<h2> ¿Esta seguro de que quiere eliminar su oferta? </h2>
|
||||
|
||||
<form:form modelAttribute="foodOffer" class="form-horizontal">
|
||||
<input type="hidden" name="init" value="${time_offer.init}" />
|
||||
<input type="hidden" name="finish" value="${time_offer.finish}" />
|
||||
<input type="hidden" name="discount" value="${time_offer.discount}" />
|
||||
|
||||
<button class="btn btn-default" type="submit">Eliminar Oferta</button>
|
||||
</form:form>
|
||||
|
||||
<a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a>
|
||||
|
||||
</jsp:body>
|
||||
</petclinic:layout>
|
Loading…
Reference in a new issue