Vista de restaurante
This commit is contained in:
Pablo Franco Sánchez 2021-04-10 11:55:29 +02:00 committed by GitHub
commit 0736665c2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 192 additions and 105 deletions

View file

@ -1,23 +1,30 @@
package org.springframework.cheapy.repository;
import java.util.Optional;
import java.util.List;
import org.springframework.cheapy.model.Client;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.Repository;
import org.springframework.transaction.annotation.Transactional;
public interface ClientRepository extends Repository<Client, String> {
public interface ClientRepository extends CrudRepository<Client, String> {
@Query("SELECT client FROM Client client WHERE username =:username")
@Transactional(readOnly = true)
Client findByUsername(String username);
Optional<Client> findById(Integer id);
// void save(Client client);
@Query("SELECT client FROM Client client")
@Transactional(readOnly = true)
List<Client> findAllClient();
void save(Client client);
}
}

View file

@ -7,14 +7,17 @@ import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.websocket.server.PathParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cheapy.model.Client;
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.repository.ClientRepository;
import org.springframework.cheapy.service.ClientService;
import org.springframework.cheapy.service.FoodOfferService;
import org.springframework.cheapy.service.NuOfferService;
@ -24,6 +27,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@Controller
@ -41,6 +45,9 @@ public class ClientController {
private final TimeOfferService timeOfferService;
@Autowired
private ClientRepository clientRepo;
public ClientController(final ClientService clientService, FoodOfferService foodOfferService,
SpeedOfferService speedOfferService, NuOfferService nuOfferService, TimeOfferService timeOfferService) {
@ -141,4 +148,12 @@ public class ClientController {
return "redirect:/login";
}
@GetMapping(value = "/restaurant/{clientId}")
public String showRestaurant(final ModelMap model, @PathVariable("clientId") Integer id) {
Client client = this.clientRepo.findById(id).get();
System.out.println(client.getDescription());
model.put("client", client);
return "clients/restaurantShow";
}
}

View file

@ -0,0 +1,58 @@
<%@ 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="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'>
<cheapy:layout pageName="client">
<h2 style="text-align:center;padding:5px"><fmt:message key="client"/></h2>
<table class="table table-striped" id="clientTable">
<thead>
<tr>
<th><fmt:message key="clientInit"/></th>
<td><c:out value="${client.init}"/></td>
</tr>
<tr>
<th><fmt:message key="clientFinish"/></th>
<td><c:out value="${client.finish}"/></td>
</tr>
<tr>
<th><fmt:message key="nameClient"/></th>
<td><c:out value="${client.name}"/></td>
</tr>
<tr>
<th><fmt:message key="emailClient"/></th>
<td><c:out value="${client.email}%"/> </td>
</tr>
<tr>
<th><fmt:message key="addressClient"/></th>
<td><c:out value="${client.address}%"/> </td>
</tr><tr>
<th><fmt:message key="telephoneClient"/></th>
<td><c:out value="${client.telephone}%"/> </td>
</tr><tr>
<th><fmt:message key="descriptionClient"/></th>
<td><c:out value="${client.description}%"/> </td>
</tr><tr>
<th><fmt:message key="foodClient"/></th>
<td><c:out value="${client.food}%"/> </td>
</tr>
</thead>
</table>
<div class="btn-menu">
</div>
</cheapy:layout>

View file

@ -11,111 +11,115 @@
<h2 style="text-align:center;padding:5px"><fmt:message key="foodOffers"/></h2>
<c:if test="${empty foodOfferLs }">
<p id="vacio" >No hay ninguna oferta por plato específico activa.</p>
<p id="vacio" >No hay ninguna oferta por plato específico activa.</p>
</c:if>
<c:if test="${not empty foodOfferLs }">
<div class="table-responsive">
<table id="foodOfferTable" class="table table-striped">
<thead>
<tr>
<!-- <th style="width: 150px;">Restaurante</th> -->
<th><fmt:message key="name"/></th>
<th><fmt:message key="food"/></th>
<th><fmt:message key="discount"/></th>
<th><fmt:message key="startDate"/></th>
<th><fmt:message key="endDate"/></th>
<th> </th>
</tr>
</thead>
<tbody>
<c:forEach items="${foodOfferLs}" var="foodOffer">
<tr>
<td>
<c:out value="${foodOffer.client.name}"/>
</td>
<td>
<c:out value="${foodOffer.food}"/>
</td>
<td>
<c:out value="${foodOffer.discount}%"/>
</td>
<td>
<c:out value="${localDateTimeFormat.format(foodOffer.start)}"/>
</td>
<td>
<c:out value="${localDateTimeFormat.format(foodOffer.end)}"/>
</td>
<td>
<spring:url value="/offers/food/{foodOfferId}" var="foodOfferUrl">
<spring:param name="foodOfferId" value="${foodOffer.id}"/>
</spring:url>
<div class="btn-detalles">
<button type="button" role="link" onclick="window.location='${fn:escapeXml(foodOfferUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true" style="padding: 5px"> </span>
<fmt:message key="details"/></button>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<div class="table-responsive">
<table id="foodOfferTable" class="table table-striped">
<thead>
<tr>
<!-- <th style="width: 150px;">Restaurante</th> -->
<th><fmt:message key="name"/></th>
<th><fmt:message key="food"/></th>
<th><fmt:message key="discount"/></th>
<th><fmt:message key="startDate"/></th>
<th><fmt:message key="endDate"/></th>
<th> </th>
</tr>
</thead>
<tbody>
<c:forEach items="${foodOfferLs}" var="foodOffer">
<tr>
<td>
<a href="/restaurant/${foodOffer.client.id}"><c:out value="${foodOffer.client.name}"/></a>
</td>
<td>
<c:out value="${foodOffer.food}"/>
</td>
<td>
<c:out value="${foodOffer.discount}%"/>
</td>
<td>
<c:out value="${localDateTimeFormat.format(foodOffer.start)}"/>
</td>
<td>
<c:out value="${localDateTimeFormat.format(foodOffer.end)}"/>
</td>
<td>
<spring:url value="/offers/food/{foodOfferId}" var="foodOfferUrl">
<spring:param name="foodOfferId" value="${foodOffer.id}"/>
</spring:url>
<div class="btn-detalles">
<button type="button" role="link" onclick="window.location='${fn:escapeXml(foodOfferUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true" style="padding: 5px"> </span>
<fmt:message key="details"/></button>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</c:if>
<h2 style="text-align:center;padding:5px"><fmt:message key="nuOffers"/></h2>
<c:if test="${empty nuOfferLs }">
<p id="vacio" >No hay ninguna oferta por número de comensales activa.</p>
<p id="vacio" >No hay ninguna oferta por número de comensales activa.</p>
</c:if>
<c:if test="${not empty nuOfferLs }">
<div class="table-responsive">
<table id="nuOfferTable" class="table table-striped">
<thead>
<tr>
<!-- <th style="width: 150px;">Restaurante</th> -->
<th><fmt:message key="name"/></th>
<th><fmt:message key="startDate"/></th>
<th><fmt:message key="endDate"/></th>
<th><fmt:message key="goldGoal"/></th>
<th><fmt:message key="goldDiscount"/></th>
<th> </th>
</tr>
</thead>
<tbody>
<c:forEach items="${nuOfferLs}" var="nuOffer">
<tr>
<td>
<c:out value="${nuOffer.client.name}"/>
</td>
<td>
<c:out value="${localDateTimeFormat.format(nuOffer.start)}"/>
</td>
<td>
<c:out value="${localDateTimeFormat.format(nuOffer.end)}"/>
</td>
<td>
<c:out value="${nuOffer.gold} comensales"/>
</td>
<td>
<c:out value="${nuOffer.discountGold}%"/>
</td>
<td>
<spring:url value="/offers/nu/{nuOfferId}" var="nuOfferUrl">
<spring:param name="nuOfferId" value="${nuOffer.id}"/>
</spring:url>
<div class="btn-detalles">
<button type="button" role="link" onclick="window.location='${fn:escapeXml(nuOfferUrl)}'" class="btn-detalles" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true" style="padding: 5px"> </span>
<fmt:message key="details"/> </button>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<div class="table-responsive">
<table id="nuOfferTable" class="table table-striped">
<thead>
<tr>
<!-- <th style="width: 150px;">Restaurante</th> -->
<th><fmt:message key="name"/></th>
<th><fmt:message key="startDate"/></th>
<th><fmt:message key="endDate"/></th>
<th><fmt:message key="goldGoal"/></th>
<th><fmt:message key="goldDiscount"/></th>
<th> </th>
</tr>
</thead>
<tbody>
<c:forEach items="${nuOfferLs}" var="nuOffer">
<tr>
<td>
<a href="/restaurant/${nuOffer.client.id}"><c:out value="${nuOffer.client.name}"/></a>
</td>
<td>
<c:out value="${localDateTimeFormat.format(nuOffer.start)}"/>
</td>
<td>
<c:out value="${localDateTimeFormat.format(nuOffer.end)}"/>
</td>
<td>
<c:out value="${nuOffer.gold} comensales"/>
</td>
<td>
<c:out value="${nuOffer.discountGold}%"/>
</td>
<td>
<spring:url value="/offers/nu/{nuOfferId}" var="nuOfferUrl">
<spring:param name="nuOfferId" value="${nuOffer.id}"/>
</spring:url>
<div class="btn-detalles">
<button type="button" role="link" onclick="window.location='${fn:escapeXml(nuOfferUrl)}'" class="btn-detalles" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true" style="padding: 5px"> </span>
<fmt:message key="details"/> </button>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</c:if>
<h2 style="text-align:center;padding:5px"><fmt:message key="speedOffers"/></h2>
@ -123,6 +127,7 @@
<p id="vacio" >No hay ninguna oferta por tiempo empleado en comer activa.</p>
</c:if>
<c:if test="${not empty speedOfferLs }">
<div class="table-responsive">
<table id="speedOfferTable" class="table table-striped">
<thead>
@ -141,7 +146,7 @@
<c:forEach items="${speedOfferLs}" var="speedOffer">
<tr>
<td>
<c:out value="${speedOffer.client.name}"/>
<a href="/restaurant/${speedOffer.client.id}"><c:out value="${speedOffer.client.name}"/></a>
</td>
<td>
<c:out value="${localDateTimeFormat.format(speedOffer.start)}"/>
@ -171,6 +176,7 @@
</tbody>
</table>
</div>
</c:if>
<h2 style="text-align:center;padding:5px"><fmt:message key="timeOffers"/></h2>
@ -178,6 +184,7 @@
<p id="vacio" >No hay ninguna oferta por franja horaria activa.</p>
</c:if>
<c:if test="${not empty timeOfferLs }">
<div class="table-responsive">
<table id="timeOfferTable" class="table table-striped">
<thead>
@ -195,7 +202,7 @@
<c:forEach items="${timeOfferLs}" var="timeOffer">
<tr>
<td>
<c:out value="${timeOffer.client.name}"/>
<a href="/restaurant/${timeOffer.client.id}"><c:out value="${timeOffer.client.name}"/></a>
</td>
<td>
<c:out value="${localDateTimeFormat.format(timeOffer.start)}"/>
@ -224,7 +231,7 @@
</c:forEach>
</tbody>
</table>
</div>
</div>
</c:if>