Arreglado y trasladado

Los show de admin ahora funcionan y tienen su propia url (por temas del
security)
This commit is contained in:
Antonio Vidal 2021-04-14 22:13:06 +02:00
parent 9299088070
commit aec6b6b094
6 changed files with 126 additions and 50 deletions

View file

@ -3,7 +3,6 @@ package org.springframework.cheapy.repository;
import java.util.List;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.model.TimeOffer;
import org.springframework.data.domain.Pageable;
@ -12,15 +11,17 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
public interface TimeOfferRepository extends PagingAndSortingRepository<FoodOffer, Integer> {
TimeOffer findTimeOfferById(int timeOfferId);
public interface TimeOfferRepository extends PagingAndSortingRepository<TimeOffer, Integer> {
@Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.id =:id")
@Transactional(readOnly = true)
TimeOffer findTimeOfferById(int id);
@Query("SELECT timeOffer FROM TimeOffer timeOffer")
@Transactional(readOnly = true)
List<TimeOffer> findAllTimeOffer(Pageable p);
void save(TimeOffer timeOffer);
//void save(TimeOffer timeOffer);
@Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.status =:status")
@Transactional(readOnly = true)

View file

@ -25,7 +25,7 @@ public class FoodOfferService {
public FoodOffer findFoodOfferById(final int id) {
return this.foodOfferRepository.findByIdFO(id);
}
public List<FoodOffer> findAllFoodOffer(final Pageable p) { //
return this.foodOfferRepository.findAllFoodOffer();
}

View file

@ -1,13 +1,18 @@
package org.springframework.cheapy.web;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.http.HttpServletRequest;
import org.springframework.cheapy.model.Client;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.NuOffer;
import org.springframework.cheapy.model.Offer;
import org.springframework.cheapy.model.SpeedOffer;
import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.model.TimeOffer;
@ -18,6 +23,8 @@ import org.springframework.cheapy.service.NuOfferService;
import org.springframework.cheapy.service.SpeedOfferService;
import org.springframework.cheapy.service.TimeOfferService;
import org.springframework.cheapy.service.UsuarioService;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
@ -139,4 +146,98 @@ public class AdministratorController {
this.clientService.saveClient(client);
return "redirect:/administrators/clients";
}
@GetMapping("/administrators/offersRecord")
public String processOffersRecordForm(final Map<String, Object> model) {
Pageable p = PageRequest.of(0, 3);
List<Object[]> datos = new ArrayList<Object[]>();
for(Offer of:this.foodOfferService.findAllFoodOffer(p)) {
Object[] fo = {of, "food"};
datos.add(fo);
}
for(Offer of:this.nuOfferService.findAllNuOffer(p)) {
Object[] nu = {of, "nu"};
datos.add(nu);
}
for(Offer of:this.speedOfferService.findAllSpeedOffer(p)) {
Object[] sp = {of, "speed"};
datos.add(sp);
}
for(Offer of:this.timeOfferService.findAllTimeOffer(p)) {
Object[] ti = {of, "time"};
datos.add(ti);
}
model.put("datos", datos);
//Se añade formateador de fecha al modelo
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/offersRecordList";
}
@GetMapping("/administrators/offers/nu/{nuOfferId}")
public String processShowNuForm(@PathVariable("nuOfferId") final int nuOfferId, final Map<String, Object> model) {
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
if (nuOffer != null) {
model.put("nuOffer", nuOffer);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/nu/nuOffersShow";
} else {
return "welcome";
}
}
@GetMapping("/administrators/offers/food/{foodOfferId}")
public String processShowFoodForm(@PathVariable("foodOfferId") final int foodOfferId, final Map<String, Object> model) {
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
if (foodOffer != null) {
model.put("foodOffer", foodOffer);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/food/foodOffersShow";
} else {
return "welcome";
}
}
@GetMapping("/administrators/offers/speed/{speedOfferId}")
public String processShowSpeedForm(@PathVariable("speedOfferId") final int speedOfferId, final Map<String, Object> model) {
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
if (speedOffer != null) {
model.put("speedOffer", speedOffer);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/speed/speedOffersShow";
} else {
return "welcome";
}
}
@GetMapping("/administrators/offers/time/{timeOfferId}")
public String processShowTimeForm(@PathVariable("timeOfferId") final int timeOfferId, final Map<String, Object> model) {
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
if (timeOffer != null) {
model.put("timeOffer", timeOffer);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/time/timeOffersShow";
} else {
return "welcome";
}
}
}

View file

@ -127,37 +127,6 @@ public class OfertaController {
return "offers/offersCreate";
}
@GetMapping("/offersRecord")
public String processOffersRecordForm(final Map<String, Object> model) {
Pageable p = PageRequest.of(0, 3);
Map<Offer, String> datos = new HashMap<Offer, String>();
for(Offer of:this.foodOfferService.findAllFoodOffer(p)) {
datos.put(of, "food");
}
for(Offer of:this.nuOfferService.findAllNuOffer(p)) {
datos.put(of, "nu");
}
for(Offer of:this.speedOfferService.findAllSpeedOffer(p)) {
datos.put(of, "speed");
}
for(Offer of:this.timeOfferService.findAllTimeOffer(p)) {
datos.put(of, "time");
}
model.put("datos", datos);
//Se añade formateador de fecha al modelo
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/offersRecordList";
}
// @GetMapping("/owners/{ownerId}/edit")
// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
// Owner owner = this.ownerService.findOwnerById(ownerId);

View file

@ -17,6 +17,7 @@
<thead>
<tr>
<th>Restaurante</th>
<th>ID</th>
<th>Tipo de oferta</th>
<th><fmt:message key="startDate"/></th>
<th><fmt:message key="endDate"/></th>
@ -28,43 +29,47 @@
<c:forEach items="${datos}" var="datos">
<tr>
<td>
<c:out value="${datos.key.client.name}"/>
<c:out value="${datos[0].client.name}"/>
</td>
<td>
<c:if test="${datos.value == 'time'}">
<c:out value="${datos[0].id}"/>
</td>
<td>
<c:if test="${datos[1] == 'time'}">
<c:out value="Por franja horaria"/>
</c:if>
<c:if test="${datos.value == 'nu'}">
<c:if test="${datos[1] == 'nu'}">
<c:out value="Por numero de comensales"/>
</c:if>
<c:if test="${datos.value == 'speed'}">
<c:if test="${datos[1] == 'speed'}">
<c:out value="Por rapidez"/>
</c:if>
<c:if test="${datos.value == 'food'}">
<c:if test="${datos[1] == 'food'}">
<c:out value="Por plato especifico"/>
</c:if>
</td>
<td>
<c:out value="${localDateTimeFormat.format(datos.key.start)}"/>
<c:out value="${localDateTimeFormat.format(datos[0].start)}"/>
</td>
<td>
<c:out value="${localDateTimeFormat.format(datos.key.end)}"/>
<c:out value="${localDateTimeFormat.format(datos[0].end)}"/>
</td>
<td>
<c:if test="${datos.key.status == 'active'}">
<c:if test="${datos[0].status == 'active'}">
<c:out value="Activa"/>
</c:if>
<c:if test="${datos.key.status == 'hidden'}">
<c:if test="${datos[0].status == 'hidden'}">
<c:out value="Oculta"/>
</c:if>
<c:if test="${datos.key.status == 'inactive'}">
<c:if test="${datos[0].status == 'inactive'}">
<c:out value="Inactiva"/>
</c:if>
</td>
<td>
<spring:url value="/offers/${datos.value}/${datos.key.id}" var="offerUrl">
<spring:param name="foodOfferId" value="${foodOffer.id}"/>
<spring:url value="/administrators/offers/${datos[1]}/${datos[0].id}" var="offerUrl">
<spring:param name="offerId" value="${datos[0].id}"/>
</spring:url>
<div class="btn-detalles">
<button type="button" role="link" onclick="window.location='${fn:escapeXml(offerUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">

View file

@ -55,7 +55,7 @@
</sec:authorize>
<sec:authorize access="hasAnyAuthority('admin')">
<cheapy:menuItem active="${name eq 'registro'}" url="/offersRecord" title="offersRecord">
<cheapy:menuItem active="${name eq 'registro'}" url="/administrators/offersRecord" title="offersRecord">
<span class="glyphicon " aria-hidden="true"></span>
<span>Registro de ofertas</span>
</cheapy:menuItem>