Avances validadores

This commit is contained in:
Javier 2021-03-31 19:21:26 +02:00
parent ce0ee43e79
commit ba3aa68598
8 changed files with 341 additions and 280 deletions

View file

@ -6,6 +6,7 @@ import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Range;
import org.springframework.format.annotation.DateTimeFormat;
@Entity
@ -25,6 +26,7 @@ public class TimeOffer extends Offer {
private LocalTime finish;
@NotNull(message = "Debe rellenar el descuento")
@Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %")
private Integer discount;
public LocalTime getInit() {

View file

@ -35,6 +35,11 @@ public class NuOfferService {
this.nuOfferRepository.save(nuOffer);
}
@Transactional
public void saveUpdateNuOffer(final NuOffer nuOfferNew, final NuOffer nuOfferOld) throws DataAccessException {
this.nuOfferRepository.save(nuOfferNew);
}
public List<NuOffer> findActiveNuOffer() {
return this.nuOfferRepository.findActiveNuOffer(StatusOffer.active);
}

View file

@ -15,7 +15,9 @@ import org.springframework.stereotype.Controller;
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;
@ -32,6 +34,11 @@ public class NuOfferController {
this.clientService = clientService;
}
// @InitBinder
// public void setAllowedFields(WebDataBinder dataBinder) {
// dataBinder.setDisallowedFields("id");
// }
@GetMapping("/offers/nu/new")
public String initCreationForm(Map<String, Object> model) {
NuOffer nuOffer = new NuOffer();
@ -122,7 +129,8 @@ public class NuOfferController {
}
@GetMapping(value = "/offers/nu/{nuOfferId}/disable")
public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) {
public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal,
final ModelMap model) {
if (!this.checkIdentity(nuOfferId)) {
return "error";
@ -134,7 +142,8 @@ public class NuOfferController {
}
@PostMapping(value = "/offers/nu/{nuOfferId}/disable")
public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) {
public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal,
final ModelMap model) {
if (!this.checkIdentity(nuOfferId)) {
return "error";

View file

@ -4,13 +4,17 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
<link href='https://fonts.googleapis.com/css?family=Lobster'
rel='stylesheet'>
<cheapy:layout pageName="foodOffer">
<h2 style="text-align:center;padding:5px"><fmt:message key="foodOffer"/></h2>
<h2 style="text-align: center; padding: 5px">
<fmt:message key="foodOffer" />
</h2>
@ -18,7 +22,8 @@
<thead>
<tr>
<th><fmt:message key="offerBeginning" /></th>
<td><c:out value="${localDateTimeFormat.format(foodOffer.start)}"/></td>
<td><c:out
value="${localDateTimeFormat.format(foodOffer.start)}" /></td>
</tr>
<tr>
<th><fmt:message key="offerEnding" /></th>
@ -41,23 +46,28 @@
</table>
<div class="btn-return">
<button type="button" role="link" onclick="window.location='/offers'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true" style="padding: 5px"> </span>
<fmt:message key="return"/> </button>
<button type="button" role="link" onclick="window.location='/offers'"
style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true"
style="padding: 5px"> </span>
<fmt:message key="return" />
</button>
</div>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{foodOfferId}/edit" var="editUrl">
<spring:param name="foodOfferId" value="${foodOffer.id}" />
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar oferta</a>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar
oferta</a>
</sec:authorize>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{foodOfferId}/disable" var="editUrl">
<spring:param name="foodOfferId" value="${foodOffer.id}" />
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar oferta</a>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar
oferta</a>
</sec:authorize>
</cheapy:layout>

View file

@ -8,15 +8,20 @@
<cheapy:layout pageName="NumOffers">
<h2>
<c:if test="${nuOffer['new']}">Nueva </c:if> Oferta por número de comensales
<c:if test="${nuOffer['new']}">Nueva </c:if>
Oferta por número de comensales
</h2>
<form:form modelAttribute="nuOffer" class="form-horizontal" id="add-nuOffer-form">
<form:form modelAttribute="nuOffer" class="form-horizontal"
id="add-nuOffer-form">
<div class="form-group has-feedback">
<form:hidden path="id" />
<form:hidden path="code" />
<form:hidden path="status" />
<cheapy:inputField label="Fecha de inicio" placeholder="15/06/2021 14:00" name="start"/>
<cheapy:inputField label="Fecha de fin" placeholder="15/06/2021 16:00" name="end"/>
<cheapy:inputField label="Fecha de inicio"
placeholder="15/06/2021 14:00" name="start" />
<cheapy:inputField label="Fecha de fin"
placeholder="15/06/2021 16:00" name="end" />
<cheapy:inputField label="Oro" name="gold" />
<cheapy:inputField label="Descuento de oro" name="discountGold" />
@ -30,7 +35,8 @@
<div class="col-sm-offset-2 col-sm-10">
<c:choose>
<c:when test="${nuOffer['new']}">
<button class="btn btn-default" type="submit">Crear oferta</button>
<button class="btn btn-default" type="submit">Crear
oferta</button>
</c:when>
<c:otherwise>
<button class="btn btn-default" type="submit">Modificar</button>

View file

@ -4,12 +4,16 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
<link href='https://fonts.googleapis.com/css?family=Lobster'
rel='stylesheet'>
<cheapy:layout pageName="nuOffer">
<h2 style="text-align:center;padding:5px"><fmt:message key="nuOffer"/></h2>
<h2 style="text-align: center; padding: 5px">
<fmt:message key="nuOffer" />
</h2>
<table class="table table-striped" id="nuOffer-table">
@ -52,23 +56,28 @@
</table>
<div class="btn-return">
<button type="button" role="link" onclick="window.location='/offers'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true" style="padding: 5px"> </span>
<fmt:message key="return"/> </button>
<button type="button" role="link" onclick="window.location='/offers'"
style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true"
style="padding: 5px"> </span>
<fmt:message key="return" />
</button>
</div>
<sec:authorize access="hasAnyAuthority('client')">
<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">Editar oferta</a>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar
oferta</a>
</sec:authorize>
<sec:authorize access="hasAnyAuthority('client')">
<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">Desactivar oferta</a>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar
oferta</a>
</sec:authorize>
</cheapy:layout>

View file

@ -4,18 +4,23 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
<link href='https://fonts.googleapis.com/css?family=Lobster'
rel='stylesheet'>
<cheapy:layout pageName="speedOffer">
<h2 style="text-align:center;padding:5px"><fmt:message key="speedOffer"/></h2>
<h2 style="text-align: center; padding: 5px">
<fmt:message key="speedOffer" />
</h2>
<table class="table table-striped" id="speedOffer-table">
<tr>
<th><fmt:message key="offerBeginning" /></th>
<td><c:out value="${localDateTimeFormat.format(speedOffer.start)}"/></td>
<td><c:out
value="${localDateTimeFormat.format(speedOffer.start)}" /></td>
</tr>
<tr>
<th><fmt:message key="offerEnding" /></th>
@ -52,23 +57,28 @@
</table>
<div class="btn-return">
<button type="button" role="link" onclick="window.location='/offers'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true" style="padding: 5px"> </span>
<fmt:message key="return"/> </button>
<button type="button" role="link" onclick="window.location='/offers'"
style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true"
style="padding: 5px"> </span>
<fmt:message key="return" />
</button>
</div>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{speedOfferId}/edit" var="editUrl">
<spring:param name="speedOfferId" value="${speedOffer.id}" />
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar oferta</a>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar
oferta</a>
</sec:authorize>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{speedOfferId}/disable" var="editUrl">
<spring:param name="speedOfferId" value="${speedOffer.id}" />
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar oferta</a>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar
oferta</a>
</sec:authorize>
</cheapy:layout>

View file

@ -4,19 +4,24 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
<link href='https://fonts.googleapis.com/css?family=Lobster'
rel='stylesheet'>
<cheapy:layout pageName="timeOffer">
<h2 style="text-align:center;padding:5px"><fmt:message key="timeOffer"/></h2>
<h2 style="text-align: center; padding: 5px">
<fmt:message key="timeOffer" />
</h2>
<table class="table table-striped">
<thead>
<tr>
<th><fmt:message key="offerBeginning" /></th>
<td><c:out value="${localDateTimeFormat.format(timeOffer.start)}"/></td>
<td><c:out
value="${localDateTimeFormat.format(timeOffer.start)}" /></td>
</tr>
<tr>
<th><fmt:message key="offerEnding" /></th>
@ -37,20 +42,25 @@
<spring:url value="{timeOfferId}/edit" var="editUrl">
<spring:param name="timeOfferId" value="${timeOffer.id}" />
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar oferta</a>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar
oferta</a>
</sec:authorize>
<sec:authorize access="hasAnyAuthority('client')">
<spring:url value="{timeOfferId}/disable" var="editUrl">
<spring:param name="timeOfferId" value="${timeOffer.id}" />
</spring:url>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar oferta</a>
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar
oferta</a>
</sec:authorize>
<div class="btn-return">
<button type="button" role="link" onclick="window.location='/offers'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true" style="padding: 5px"> </span>
<fmt:message key="return"/> </button>
<button type="button" role="link" onclick="window.location='/offers'"
style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true"
style="padding: 5px"> </span>
<fmt:message key="return" />
</button>
</div>
</cheapy:layout>