#88 018-paginacion-issue#65 a develop

018 paginacion issue#65
This commit is contained in:
gabgutpri 2021-04-10 21:45:43 +02:00 committed by GitHub
commit f2e12d1b94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 581 additions and 414 deletions

View file

@ -1,32 +1,34 @@
package org.springframework.cheapy.repository; package org.springframework.cheapy.repository;
import java.util.List; import java.util.List;
import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.NuOffer;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
import org.springframework.data.repository.Repository; import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
public interface NuOfferRepository extends Repository<NuOffer, Integer> { public interface NuOfferRepository extends PagingAndSortingRepository<NuOffer, Integer> {
NuOffer findNuOfferById(int nuOfferId); NuOffer findNuOfferById(int nuOfferId);
@Query("SELECT nuOffer FROM NuOffer nuOffer") @Query("SELECT nuOffer FROM NuOffer nuOffer")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<NuOffer> findAllNuOffer(); List<NuOffer> findAllNuOffer(Pageable p);
//void save(NuOffer nuOffer);
void save(NuOffer nuOffer);
@Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.status =:status") @Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.status =:status")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<NuOffer> findActiveNuOffer(StatusOffer status); List<NuOffer> findActiveNuOffer(StatusOffer status, Pageable p);
@Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.id =:id") @Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.id =:id")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<NuOffer> findByUserId(@Param("id") Integer id); List<NuOffer> findByUserId(@Param("id") Integer id);
@Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.id =:id AND nuOffer.status!= 'inactive'") @Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.id =:id AND nuOffer.status!= 'inactive'")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<NuOffer> findNuOfferActOclByUserId(@Param("id") Integer id); List<NuOffer> findNuOfferActOclByUserId(@Param("id") Integer id);

View file

@ -1,21 +1,23 @@
package org.springframework.cheapy.repository; package org.springframework.cheapy.repository;
import java.util.List; import java.util.List;
import org.springframework.cheapy.model.Review; import org.springframework.cheapy.model.Review;
import org.springframework.data.repository.Repository; import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
public interface ReviewRepository extends Repository<Review, Integer> { public interface ReviewRepository extends PagingAndSortingRepository<Review, Integer> {
@Query("SELECT r FROM Review r") @Query("SELECT r FROM Review r")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<Review> findAllReviews(); List<Review> findAllReviews(Pageable p);
//void save(Review review);
void save(Review review);
@Query("SELECT r FROM Review r WHERE id =:id") @Query("SELECT r FROM Review r WHERE id =:id")
@Transactional(readOnly = true) @Transactional(readOnly = true)
Review findReviewById(@Param("id") Integer id); Review findReviewById(@Param("id") Integer id);

View file

@ -1,34 +1,36 @@
package org.springframework.cheapy.repository; package org.springframework.cheapy.repository;
import java.util.List; import java.util.List;
import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.SpeedOffer;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
public interface SpeedOfferRepository extends Repository<SpeedOffer, Integer> { public interface SpeedOfferRepository extends PagingAndSortingRepository<SpeedOffer, Integer> {
@Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE id =:id") @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE id =:id")
@Transactional(readOnly = true) @Transactional(readOnly = true)
SpeedOffer findById(@Param("id") Integer id); SpeedOffer findByIdSO(@Param("id") Integer id);
@Query("SELECT speedOffer FROM SpeedOffer speedOffer") @Query("SELECT speedOffer FROM SpeedOffer speedOffer")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<SpeedOffer> findAllSpeedOffer(); List<SpeedOffer> findAllSpeedOffer(Pageable p);
void save(SpeedOffer speedOffer); //void save(SpeedOffer speedOffer);
@Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.status =:status") @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.status =:status")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<SpeedOffer> findActiveSpeedOffer(StatusOffer status); List<SpeedOffer> findActiveSpeedOffer(StatusOffer status, Pageable p);
@Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.id =:id") @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.id =:id")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<SpeedOffer> findByUserId(@Param("id") Integer id); List<SpeedOffer> findByUserId(@Param("id") Integer id);
@Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.id =:id AND speedOffer.status!= 'inactive'") @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.id =:id AND speedOffer.status!= 'inactive'")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<SpeedOffer> findSpeedOfferActOclByUserId(@Param("id") Integer id); List<SpeedOffer> findSpeedOfferActOclByUserId(@Param("id") Integer id);

View file

@ -1,32 +1,35 @@
package org.springframework.cheapy.repository; package org.springframework.cheapy.repository;
import java.util.List; import java.util.List;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.model.TimeOffer;
import org.springframework.data.repository.Repository; import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
public interface TimeOfferRepository extends Repository<TimeOffer, Integer> { public interface TimeOfferRepository extends PagingAndSortingRepository<FoodOffer, Integer> {
TimeOffer findTimeOfferById(int timeOfferId); TimeOffer findTimeOfferById(int timeOfferId);
@Query("SELECT timeOffer FROM TimeOffer timeOffer") @Query("SELECT timeOffer FROM TimeOffer timeOffer")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<TimeOffer> findAllTimeOffer(); List<TimeOffer> findAllTimeOffer(Pageable p);
void save(TimeOffer timeOffer); void save(TimeOffer timeOffer);
@Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.status =:status") @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.status =:status")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<TimeOffer> findActiveTimeOffer(StatusOffer status); List<TimeOffer> findActiveTimeOffer(StatusOffer status, Pageable p);
@Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.id =:id") @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.id =:id")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<TimeOffer> findByUserId(@Param("id") Integer id); List<TimeOffer> findByUserId(@Param("id") Integer id);
@Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.id =:id AND timeOffer.status!= 'inactive'") @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.id =:id AND timeOffer.status!= 'inactive'")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<TimeOffer> findTimeOfferActOclByUserId(@Param("id") Integer id); List<TimeOffer> findTimeOfferActOclByUserId(@Param("id") Integer id);

View file

@ -1,12 +1,14 @@
package org.springframework.cheapy.service; package org.springframework.cheapy.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.NuOffer;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.repository.NuOfferRepository; import org.springframework.cheapy.repository.NuOfferRepository;
import java.util.List;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -15,6 +17,7 @@ public class NuOfferService {
private NuOfferRepository nuOfferRepository; private NuOfferRepository nuOfferRepository;
@Autowired @Autowired
public NuOfferService(final NuOfferRepository nuOfferRepository) { public NuOfferService(final NuOfferRepository nuOfferRepository) {
this.nuOfferRepository = nuOfferRepository; this.nuOfferRepository = nuOfferRepository;
@ -26,28 +29,28 @@ public class NuOfferService {
} }
@Transactional @Transactional
public List<NuOffer> findAllNuOffer() { public List<NuOffer> findAllNuOffer(final Pageable page) {
return this.nuOfferRepository.findAllNuOffer(); return this.nuOfferRepository.findAllNuOffer(page);
} }
@Transactional @Transactional
public void saveNuOffer(final NuOffer nuOffer) throws DataAccessException { public void saveNuOffer(final NuOffer nuOffer) throws DataAccessException {
this.nuOfferRepository.save(nuOffer); this.nuOfferRepository.save(nuOffer);
} }
@Transactional @Transactional
public void saveUpdateNuOffer(final NuOffer nuOfferNew, final NuOffer nuOfferOld) throws DataAccessException { public void saveUpdateNuOffer(final NuOffer nuOfferNew, final NuOffer nuOfferOld) throws DataAccessException {
this.nuOfferRepository.save(nuOfferNew); this.nuOfferRepository.save(nuOfferNew);
} }
public List<NuOffer> findActiveNuOffer() { public List<NuOffer> findActiveNuOffer(final Pageable page) {
return this.nuOfferRepository.findActiveNuOffer(StatusOffer.active); return this.nuOfferRepository.findActiveNuOffer(StatusOffer.active, page);
} }
public List<NuOffer> findNuOfferByUserId(final int id) { public List<NuOffer> findNuOfferByUserId(final int id) {
return this.nuOfferRepository.findByUserId(id); return this.nuOfferRepository.findByUserId(id);
} }
public List<NuOffer> findNuOfferActOclByUserId(final int id) { public List<NuOffer> findNuOfferActOclByUserId(final int id) {
return this.nuOfferRepository.findNuOfferActOclByUserId(id); return this.nuOfferRepository.findNuOfferActOclByUserId(id);
} }

View file

@ -1,3 +1,4 @@
package org.springframework.cheapy.service; package org.springframework.cheapy.service;
import java.util.List; import java.util.List;
@ -5,15 +6,17 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cheapy.model.Review; import org.springframework.cheapy.model.Review;
import org.springframework.cheapy.repository.ReviewRepository; import org.springframework.cheapy.repository.ReviewRepository;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@Service @Service
public class ReviewService { public class ReviewService {
private ReviewRepository reviewRepository; private ReviewRepository reviewRepository;
@Autowired @Autowired
public ReviewService(final ReviewRepository reviewRepository) { public ReviewService(final ReviewRepository reviewRepository) {
this.reviewRepository = reviewRepository; this.reviewRepository = reviewRepository;
@ -25,8 +28,8 @@ public class ReviewService {
} }
@Transactional @Transactional
public List<Review> findAllReviews() { public List<Review> findAllReviews(final Pageable page) {
return this.reviewRepository.findAllReviews(); return this.reviewRepository.findAllReviews(page);
} }
@Transactional @Transactional

View file

@ -2,11 +2,13 @@
package org.springframework.cheapy.service; package org.springframework.cheapy.service;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.SpeedOffer;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.repository.SpeedOfferRepository; import org.springframework.cheapy.repository.SpeedOfferRepository;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -23,27 +25,27 @@ public class SpeedOfferService {
@Transactional @Transactional
public SpeedOffer findSpeedOfferById(final int id) { public SpeedOffer findSpeedOfferById(final int id) {
return this.speedOfferRepository.findById(id); return this.speedOfferRepository.findByIdSO(id);
} }
@Transactional @Transactional
public List<SpeedOffer> findAllSpeedOffer() { // public List<SpeedOffer> findAllSpeedOffer(final Pageable page) { //
return this.speedOfferRepository.findAllSpeedOffer(); return this.speedOfferRepository.findAllSpeedOffer(page);
} }
@Transactional @Transactional
public void saveSpeedOffer(final SpeedOffer speedOffer) throws DataAccessException { // public void saveSpeedOffer(final SpeedOffer speedOffer) throws DataAccessException { //
this.speedOfferRepository.save(speedOffer); this.speedOfferRepository.save(speedOffer);
} }
public List<SpeedOffer> findActiveSpeedOffer() { public List<SpeedOffer> findActiveSpeedOffer(final Pageable page) {
return this.speedOfferRepository.findActiveSpeedOffer(StatusOffer.active); return this.speedOfferRepository.findActiveSpeedOffer(StatusOffer.active, page);
} }
public List<SpeedOffer> findSpeedOfferByUserId(final int id) { public List<SpeedOffer> findSpeedOfferByUserId(final int id) {
return this.speedOfferRepository.findByUserId(id); return this.speedOfferRepository.findByUserId(id);
} }
public List<SpeedOffer> findSpeedOfferActOclByUserId(final int id) { public List<SpeedOffer> findSpeedOfferActOclByUserId(final int id) {
return this.speedOfferRepository.findSpeedOfferActOclByUserId(id); return this.speedOfferRepository.findSpeedOfferActOclByUserId(id);
} }

View file

@ -1,3 +1,4 @@
package org.springframework.cheapy.service; package org.springframework.cheapy.service;
import java.util.List; import java.util.List;
@ -6,12 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.model.TimeOffer;
import org.springframework.cheapy.repository.TimeOfferRepository; import org.springframework.cheapy.repository.TimeOfferRepository;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class TimeOfferService { public class TimeOfferService {
private TimeOfferRepository timeOfferRepository; private TimeOfferRepository timeOfferRepository;
@ -23,24 +25,23 @@ public class TimeOfferService {
public TimeOffer findTimeOfferById(final int id) { public TimeOffer findTimeOfferById(final int id) {
return this.timeOfferRepository.findTimeOfferById(id); return this.timeOfferRepository.findTimeOfferById(id);
} }
public List<TimeOffer> findAllTimeOffer() { public List<TimeOffer> findAllTimeOffer(final Pageable page) {
return this.timeOfferRepository.findAllTimeOffer(); return this.timeOfferRepository.findAllTimeOffer(page);
} }
public void saveTimeOffer(final TimeOffer TimeOffer) throws DataAccessException {
public void saveTimeOffer(final TimeOffer TimeOffer) throws DataAccessException {
this.timeOfferRepository.save(TimeOffer); this.timeOfferRepository.save(TimeOffer);
} }
public List<TimeOffer> findActiveTimeOffer() { public List<TimeOffer> findActiveTimeOffer(final Pageable p) {
return this.timeOfferRepository.findActiveTimeOffer(StatusOffer.active); return this.timeOfferRepository.findActiveTimeOffer(StatusOffer.active, p);
} }
public List<TimeOffer> findTimeOfferByUserId(final int id) { public List<TimeOffer> findTimeOfferByUserId(final int id) {
return this.timeOfferRepository.findByUserId(id); return this.timeOfferRepository.findByUserId(id);
} }
public List<TimeOffer> findTimeOfferActOclByUserId(final int id) { public List<TimeOffer> findTimeOfferActOclByUserId(final int id) {
return this.timeOfferRepository.findTimeOfferActOclByUserId(id); return this.timeOfferRepository.findTimeOfferActOclByUserId(id);
} }

View file

@ -14,6 +14,8 @@ import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.ClientService;
import org.springframework.cheapy.service.FoodOfferService; import org.springframework.cheapy.service.FoodOfferService;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
@ -24,10 +26,11 @@ import org.springframework.web.bind.annotation.PostMapping;
@Controller @Controller
public class FoodOfferController { public class FoodOfferController {
private static final String VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM = "offers/food/createOrUpdateFoodOfferForm"; private static final String VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM = "offers/food/createOrUpdateFoodOfferForm";
private final FoodOfferService foodOfferService;
private final ClientService clientService;
private final FoodOfferService foodOfferService;
private final ClientService clientService;
public FoodOfferController(final FoodOfferService foodOfferService, final ClientService clientService) { public FoodOfferController(final FoodOfferService foodOfferService, final ClientService clientService) {
this.foodOfferService = foodOfferService; this.foodOfferService = foodOfferService;
@ -47,24 +50,25 @@ public class FoodOfferController {
private boolean checkOffer(final FoodOffer session, final FoodOffer offer) { private boolean checkOffer(final FoodOffer session, final FoodOffer offer) {
boolean res = false; boolean res = false;
if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !session.getStatus().equals(StatusOffer.inactive)) {
&& (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) {
res = true; res = true;
} }
return res; return res;
} }
private boolean checkDates(final FoodOffer foodOffer) { private boolean checkDates(final FoodOffer foodOffer) {
boolean res = false; boolean res = false;
if(foodOffer.getEnd()==null || foodOffer.getStart()==null || foodOffer.getEnd().isAfter(foodOffer.getStart())) { if (foodOffer.getEnd() == null || foodOffer.getStart() == null || foodOffer.getEnd().isAfter(foodOffer.getStart())) {
res = true; res = true;
} }
return res; return res;
} }
@GetMapping("/offers/foodOfferList") @GetMapping("/offers/foodOfferList/{page}")
public String processFindForm(Map<String, Object> model) { public String processFindForm(@PathVariable("page") final int page, final Map<String, Object> model) {
List<FoodOffer> foodOfferLs=this.foodOfferService.findActiveFoodOffer(); Pageable elements = PageRequest.of(page, 5);
List<FoodOffer> foodOfferLs = this.foodOfferService.findActiveFoodOffer(elements);
model.put("foodOfferLs", foodOfferLs); model.put("foodOfferLs", foodOfferLs);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/food/foodOffersList"; return "offers/food/foodOffersList";
@ -72,32 +76,32 @@ public class FoodOfferController {
} }
@GetMapping("/offers/food/new") @GetMapping("/offers/food/new")
public String initCreationForm(Map<String, Object> model) { public String initCreationForm(final Map<String, Object> model) {
FoodOffer foodOffer = new FoodOffer(); FoodOffer foodOffer = new FoodOffer();
model.put("foodOffer", foodOffer); model.put("foodOffer", foodOffer);
return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
} }
@PostMapping("/offers/food/new") @PostMapping("/offers/food/new")
public String processCreationForm(@Valid FoodOffer foodOffer, BindingResult result) { public String processCreationForm(@Valid final FoodOffer foodOffer, final BindingResult result) {
if(!this.checkDates(foodOffer)) { if (!this.checkDates(foodOffer)) {
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio"); result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio");
} }
if (result.hasErrors()) { if (result.hasErrors()) {
return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
} }
Client client = this.clientService.getCurrentClient(); Client client = this.clientService.getCurrentClient();
foodOffer.setClient(client); foodOffer.setClient(client);
foodOffer.setStatus(StatusOffer.hidden); foodOffer.setStatus(StatusOffer.hidden);
this.foodOfferService.saveFoodOffer(foodOffer); this.foodOfferService.saveFoodOffer(foodOffer);
return "redirect:/offers/food/" + foodOffer.getId(); return "redirect:/offers/food/" + foodOffer.getId();
} }
@GetMapping(value = "/offers/food/{foodOfferId}/activate") @GetMapping(value = "/offers/food/{foodOfferId}/activate")
public String activateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, ModelMap modelMap) { public String activateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap modelMap) {
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
Client client = this.clientService.getCurrentClient(); Client client = this.clientService.getCurrentClient();
if (foodOffer.getClient().equals(client)) { if (foodOffer.getClient().equals(client)) {
@ -112,26 +116,25 @@ public class FoodOfferController {
} }
@GetMapping("/offers/food/{foodOfferId}") @GetMapping("/offers/food/{foodOfferId}")
public String processShowForm(@PathVariable("foodOfferId") int foodOfferId, Map<String, Object> model) { public String processShowForm(@PathVariable("foodOfferId") final int foodOfferId, final Map<String, Object> model) {
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
if(foodOffer.getStatus().equals(StatusOffer.active)) { if (foodOffer.getStatus().equals(StatusOffer.active)) {
model.put("foodOffer", foodOffer); model.put("foodOffer", foodOffer);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/food/foodOffersShow"; return "offers/food/foodOffersShow";
}else if(foodOffer.getStatus().equals(StatusOffer.hidden)&&(this.checkIdentity(foodOfferId))) { } else if (foodOffer.getStatus().equals(StatusOffer.hidden) && this.checkIdentity(foodOfferId)) {
model.put("foodOffer", foodOffer); model.put("foodOffer", foodOffer);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/food/foodOffersShow"; return "offers/food/foodOffersShow";
}else { } else {
return "error"; return "error";
} }
} }
@GetMapping(value = "/offers/food/{foodOfferId}/edit") @GetMapping(value = "/offers/food/{foodOfferId}/edit")
public String updateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model, public String updateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model, final HttpServletRequest request) {
HttpServletRequest request) {
if (!this.checkIdentity(foodOfferId)) { if (!this.checkIdentity(foodOfferId)) {
return "error"; return "error";
@ -146,8 +149,7 @@ public class FoodOfferController {
} }
@PostMapping(value = "/offers/food/{foodOfferId}/edit") @PostMapping(value = "/offers/food/{foodOfferId}/edit")
public String updateFoodOffer(@Valid final FoodOffer foodOfferEdit, final BindingResult result, public String updateFoodOffer(@Valid final FoodOffer foodOfferEdit, final BindingResult result, final ModelMap model, final HttpServletRequest request) {
final ModelMap model, HttpServletRequest request) {
if (!this.checkIdentity(foodOfferEdit.getId())) { if (!this.checkIdentity(foodOfferEdit.getId())) {
return "error"; return "error";
@ -157,22 +159,21 @@ public class FoodOfferController {
if (!this.checkOffer(foodOffer, foodOfferEdit)) { if (!this.checkOffer(foodOffer, foodOfferEdit)) {
return "error"; return "error";
} }
if(!this.checkDates(foodOfferEdit)) {
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio");
}
if (result.hasErrors()) {
model.addAttribute("foodOffer", foodOfferEdit);
return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
} if (!this.checkDates(foodOfferEdit)) {
BeanUtils.copyProperties(this.foodOfferService.findFoodOfferById(foodOfferEdit.getId()), foodOfferEdit, result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio");
"start", "end", "food", "discount");
this.foodOfferService.saveFoodOffer(foodOfferEdit); }
return "redirect:/offers/food/" + foodOfferEdit.getId();
if (result.hasErrors()) {
model.addAttribute("foodOffer", foodOfferEdit);
return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
}
BeanUtils.copyProperties(this.foodOfferService.findFoodOfferById(foodOfferEdit.getId()), foodOfferEdit, "start", "end", "food", "discount");
this.foodOfferService.saveFoodOffer(foodOfferEdit);
return "redirect:/offers/food/" + foodOfferEdit.getId();
} }
@GetMapping(value = "/offers/food/{foodOfferId}/disable") @GetMapping(value = "/offers/food/{foodOfferId}/disable")

View file

@ -1,3 +1,4 @@
package org.springframework.cheapy.web; package org.springframework.cheapy.web;
import java.security.Principal; import java.security.Principal;
@ -14,6 +15,8 @@ import org.springframework.cheapy.model.NuOffer;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.ClientService;
import org.springframework.cheapy.service.NuOfferService; import org.springframework.cheapy.service.NuOfferService;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
@ -24,16 +27,17 @@ import org.springframework.web.bind.annotation.PostMapping;
@Controller @Controller
public class NuOfferController { public class NuOfferController {
private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "offers/nu/createOrUpdateNuOfferForm"; private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "offers/nu/createOrUpdateNuOfferForm";
private final NuOfferService nuOfferService;
private final ClientService clientService;
private final NuOfferService nuOfferService;
private final ClientService clientService;
public NuOfferController(final NuOfferService nuOfferService, final ClientService clientService) { public NuOfferController(final NuOfferService nuOfferService, final ClientService clientService) {
this.nuOfferService = nuOfferService; this.nuOfferService = nuOfferService;
this.clientService = clientService; this.clientService = clientService;
} }
private boolean checkIdentity(final int nuOfferId) { private boolean checkIdentity(final int nuOfferId) {
boolean res = false; boolean res = false;
Client client = this.clientService.getCurrentClient(); Client client = this.clientService.getCurrentClient();
@ -47,43 +51,44 @@ public class NuOfferController {
private boolean checkOffer(final NuOffer session, final NuOffer offer) { private boolean checkOffer(final NuOffer session, final NuOffer offer) {
boolean res = false; boolean res = false;
if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !session.getStatus().equals(StatusOffer.inactive)) {
&& (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) {
res = true; res = true;
} }
return res; return res;
} }
private boolean checkDates(final NuOffer nuOffer) { private boolean checkDates(final NuOffer nuOffer) {
boolean res = false; boolean res = false;
if(nuOffer.getEnd()==null || nuOffer.getStart()==null || nuOffer.getEnd().isAfter(nuOffer.getStart())) { if (nuOffer.getEnd() == null || nuOffer.getStart() == null || nuOffer.getEnd().isAfter(nuOffer.getStart())) {
res = true; res = true;
} }
return res; return res;
} }
private boolean checkConditions(final NuOffer nuOffer) { private boolean checkConditions(final NuOffer nuOffer) {
boolean res = false; boolean res = false;
if(nuOffer.getGold()==null || nuOffer.getSilver()==null || nuOffer.getBronze()==null) { if (nuOffer.getGold() == null || nuOffer.getSilver() == null || nuOffer.getBronze() == null) {
}else if(nuOffer.getGold() >= nuOffer.getSilver() && nuOffer.getSilver() >= nuOffer.getBronze()) { } else if (nuOffer.getGold() >= nuOffer.getSilver() && nuOffer.getSilver() >= nuOffer.getBronze()) {
res = true; res = true;
} }
return res; return res;
} }
private boolean checkDiscounts(final NuOffer NuOffer) { private boolean checkDiscounts(final NuOffer NuOffer) {
boolean res = false; boolean res = false;
if(NuOffer.getDiscountGold()==null || NuOffer.getDiscountSilver()==null || NuOffer.getDiscountBronze()==null) { if (NuOffer.getDiscountGold() == null || NuOffer.getDiscountSilver() == null || NuOffer.getDiscountBronze() == null) {
}else if(NuOffer.getDiscountGold() >= NuOffer.getDiscountSilver() && NuOffer.getDiscountSilver() >= NuOffer.getDiscountBronze()) { } else if (NuOffer.getDiscountGold() >= NuOffer.getDiscountSilver() && NuOffer.getDiscountSilver() >= NuOffer.getDiscountBronze()) {
res = true; res = true;
} }
return res; return res;
} }
@GetMapping("/offers/nuOfferList") @GetMapping("/offers/nuOfferList/{page}")
public String processFindForm(Map<String, Object> model) { public String processFindForm(@PathVariable("page") final int page, final Map<String, Object> model) {
List<NuOffer> foodOfferLs=this.nuOfferService.findActiveNuOffer(); Pageable elements = PageRequest.of(page, 5);
List<NuOffer> foodOfferLs = this.nuOfferService.findActiveNuOffer(elements);
model.put("nuOfferLs", foodOfferLs); model.put("nuOfferLs", foodOfferLs);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/nu/nuOffersList"; return "offers/nu/nuOffersList";
@ -91,40 +96,40 @@ public class NuOfferController {
} }
@GetMapping("/offers/nu/new") @GetMapping("/offers/nu/new")
public String initCreationForm(Map<String, Object> model) { public String initCreationForm(final Map<String, Object> model) {
NuOffer nuOffer = new NuOffer(); NuOffer nuOffer = new NuOffer();
model.put("nuOffer", nuOffer); model.put("nuOffer", nuOffer);
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
} }
@PostMapping("/offers/nu/new") @PostMapping("/offers/nu/new")
public String processCreationForm(@Valid NuOffer nuOffer, BindingResult result) { public String processCreationForm(@Valid final NuOffer nuOffer, final BindingResult result) {
if(!this.checkDates(nuOffer)) {
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio");
}
if(!this.checkConditions(nuOffer)) {
result.rejectValue("gold","" ,"Oro debe ser mayor o igual que plata, y plata mayor o igual que bronce");
}
if(!this.checkDiscounts(nuOffer)) {
result.rejectValue("discountGold","" ,"El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce");
}
if (result.hasErrors()) {
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
}
nuOffer.setStatus(StatusOffer.hidden);
Client client = this.clientService.getCurrentClient(); if (!this.checkDates(nuOffer)) {
result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio");
nuOffer.setClient(client); }
if (!this.checkConditions(nuOffer)) {
result.rejectValue("gold", "", "Oro debe ser mayor o igual que plata, y plata mayor o igual que bronce");
}
if (!this.checkDiscounts(nuOffer)) {
result.rejectValue("discountGold", "", "El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce");
}
if (result.hasErrors()) {
return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
}
nuOffer.setStatus(StatusOffer.hidden);
Client client = this.clientService.getCurrentClient();
nuOffer.setClient(client);
this.nuOfferService.saveNuOffer(nuOffer);
return "redirect:/offers/nu/" + nuOffer.getId();
this.nuOfferService.saveNuOffer(nuOffer);
return "redirect:/offers/nu/" + nuOffer.getId();
} }
@GetMapping(value = "/offers/nu/{nuOfferId}/activate") @GetMapping(value = "/offers/nu/{nuOfferId}/activate")
@ -144,26 +149,25 @@ public class NuOfferController {
} }
@GetMapping("/offers/nu/{nuOfferId}") @GetMapping("/offers/nu/{nuOfferId}")
public String processShowForm(@PathVariable("nuOfferId") int nuOfferId, Map<String, Object> model) { public String processShowForm(@PathVariable("nuOfferId") final int nuOfferId, final Map<String, Object> model) {
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
if(nuOffer.getStatus().equals(StatusOffer.active)) { if (nuOffer.getStatus().equals(StatusOffer.active)) {
model.put("nuOffer", nuOffer); model.put("nuOffer", nuOffer);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/nu/nuOffersShow"; return "offers/nu/nuOffersShow";
}else if(nuOffer.getStatus().equals(StatusOffer.hidden)&&(this.checkIdentity(nuOfferId))) { } else if (nuOffer.getStatus().equals(StatusOffer.hidden) && this.checkIdentity(nuOfferId)) {
model.put("nuOffer", nuOffer); model.put("nuOffer", nuOffer);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/nu/nuOffersShow"; return "offers/nu/nuOffersShow";
}else { } else {
return "error"; return "error";
} }
} }
@GetMapping(value = "/offers/nu/{nuOfferId}/edit") @GetMapping(value = "/offers/nu/{nuOfferId}/edit")
public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap model, public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap model, final HttpServletRequest request) {
HttpServletRequest request) {
if (!this.checkIdentity(nuOfferId)) { if (!this.checkIdentity(nuOfferId)) {
return "error"; return "error";
@ -178,8 +182,7 @@ public class NuOfferController {
} }
@PostMapping(value = "/offers/nu/{nuOfferId}/edit") @PostMapping(value = "/offers/nu/{nuOfferId}/edit")
public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final ModelMap model, public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final ModelMap model, final HttpServletRequest request) {
HttpServletRequest request) {
if (!this.checkIdentity(nuOfferEdit.getId())) { if (!this.checkIdentity(nuOfferEdit.getId())) {
return "error"; return "error";
@ -190,35 +193,32 @@ public class NuOfferController {
return "error"; return "error";
} }
if(!this.checkDates(nuOfferEdit)) { if (!this.checkDates(nuOfferEdit)) {
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio"); result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio");
}
if(!this.checkConditions(nuOfferEdit)) {
result.rejectValue("gold","" ,"Oro debe ser mayor o igual que plata, y plata mayor o igual que bronce");
}
if(!this.checkDiscounts(nuOfferEdit)) {
result.rejectValue("discountGold","" ,"El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce");
}
if (result.hasErrors()) { }
model.addAttribute("nuOffer", nuOfferEdit); if (!this.checkConditions(nuOfferEdit)) {
return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; result.rejectValue("gold", "", "Oro debe ser mayor o igual que plata, y plata mayor o igual que bronce");
}
if (!this.checkDiscounts(nuOfferEdit)) {
result.rejectValue("discountGold", "", "El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce");
}
if (result.hasErrors()) {
model.addAttribute("nuOffer", nuOfferEdit);
return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
}
BeanUtils.copyProperties(this.nuOfferService.findNuOfferById(nuOfferEdit.getId()), nuOfferEdit, "start", "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze");
this.nuOfferService.saveNuOffer(nuOfferEdit);
return "redirect:/offers/nu/" + nuOfferEdit.getId();
}
BeanUtils.copyProperties(this.nuOfferService.findNuOfferById(nuOfferEdit.getId()), nuOfferEdit, "start",
"end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze");
this.nuOfferService.saveNuOffer(nuOfferEdit);
return "redirect:/offers/nu/" + nuOfferEdit.getId();
} }
@GetMapping(value = "/offers/nu/{nuOfferId}/disable") @GetMapping(value = "/offers/nu/{nuOfferId}/disable")
public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) {
final ModelMap model) {
if (!this.checkIdentity(nuOfferId)) { if (!this.checkIdentity(nuOfferId)) {
return "error"; return "error";
@ -230,8 +230,7 @@ public class NuOfferController {
} }
@PostMapping(value = "/offers/nu/{nuOfferId}/disable") @PostMapping(value = "/offers/nu/{nuOfferId}/disable")
public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) {
final ModelMap model) {
if (!this.checkIdentity(nuOfferId)) { if (!this.checkIdentity(nuOfferId)) {
return "error"; return "error";

View file

@ -43,9 +43,9 @@ public class OfertaController {
Pageable elements = PageRequest.of(0, 3); Pageable elements = PageRequest.of(0, 3);
List<FoodOffer> foodOfferLs = this.foodOfferService.findActiveFoodOffer(elements); List<FoodOffer> foodOfferLs = this.foodOfferService.findActiveFoodOffer(elements);
List<NuOffer> nuOfferLs = this.nuOfferService.findActiveNuOffer(); List<NuOffer> nuOfferLs = this.nuOfferService.findActiveNuOffer(elements);
List<SpeedOffer> speedOfferLs = this.speedOfferService.findActiveSpeedOffer(); List<SpeedOffer> speedOfferLs = this.speedOfferService.findActiveSpeedOffer(elements);
List<TimeOffer> timeOfferLs = this.timeOfferService.findActiveTimeOffer(); List<TimeOffer> timeOfferLs = this.timeOfferService.findActiveTimeOffer(elements);
model.put("foodOfferLs", foodOfferLs); model.put("foodOfferLs", foodOfferLs);
model.put("nuOfferLs", nuOfferLs); model.put("nuOfferLs", nuOfferLs);

View file

@ -1,3 +1,4 @@
package org.springframework.cheapy.web; package org.springframework.cheapy.web;
import java.util.List; import java.util.List;
@ -9,6 +10,8 @@ import org.springframework.cheapy.model.Review;
import org.springframework.cheapy.model.User; import org.springframework.cheapy.model.User;
import org.springframework.cheapy.service.ReviewService; import org.springframework.cheapy.service.ReviewService;
import org.springframework.cheapy.service.UserService; import org.springframework.cheapy.service.UserService;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
@ -19,10 +22,10 @@ import org.springframework.web.bind.annotation.PostMapping;
@Controller @Controller
public class ReviewController { public class ReviewController {
private static final String VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM = "reviews/createOrUpdateReviewForm";
private final ReviewService reviewService;
private final UserService userService;
private static final String VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM = "reviews/createOrUpdateReviewForm";
private final ReviewService reviewService;
private final UserService userService;
public ReviewController(final ReviewService reviewService, final UserService userService) { public ReviewController(final ReviewService reviewService, final UserService userService) {
this.reviewService = reviewService; this.reviewService = reviewService;
@ -38,46 +41,44 @@ public class ReviewController {
} }
return res; return res;
} }
@GetMapping("/reviews") @GetMapping("/reviewsList/{page}")
public String processFindForm( Map<String, Object> model) { public String processFindForm(@PathVariable("page") final int page, final Map<String, Object> model) {
Pageable elements = PageRequest.of(page, 6);
List<Review> reviewsLs=this.reviewService.findAllReviews(); List<Review> reviewsLs = this.reviewService.findAllReviews(elements);
model.put("reviewsLs", reviewsLs); model.put("reviewsLs", reviewsLs);
return "reviews/reviewsList"; return "reviews/reviewsList";
} }
@GetMapping("/reviews/new") @GetMapping("/reviews/new")
public String initCreationForm(Map<String, Object> model) { public String initCreationForm(final Map<String, Object> model) {
Review review = new Review(); Review review = new Review();
model.put("review", review); model.put("review", review);
return VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM; return ReviewController.VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM;
} }
@PostMapping("/reviews/new") @PostMapping("/reviews/new")
public String processCreationForm(@Valid Review review, BindingResult result) { public String processCreationForm(@Valid final Review review, final BindingResult result) {
if (result.hasErrors()) { if (result.hasErrors()) {
return VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM; return ReviewController.VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM;
} else { } else {
User escritor = this.userService.getCurrentUser(); User escritor = this.userService.getCurrentUser();
review.setEscritor(escritor); review.setEscritor(escritor);
this.reviewService.saveReview(review); this.reviewService.saveReview(review);
return "redirect:/reviews/" + review.getId(); return "redirect:/reviews/" + review.getId();
} }
} }
@GetMapping("/reviews/{reviewId}") @GetMapping("/reviews/{reviewId}")
public String processShowForm(@PathVariable("reviewId") int reviewId, Map<String, Object> model) { public String processShowForm(@PathVariable("reviewId") final int reviewId, final Map<String, Object> model) {
Review review = this.reviewService.findReviewById(reviewId); Review review = this.reviewService.findReviewById(reviewId);
model.put("review", review); model.put("review", review);
return "reviews/reviewsShow"; return "reviews/reviewsShow";
} }
@ -105,7 +106,7 @@ public class ReviewController {
} else { } else {
User escritor = this.userService.getCurrentUser(); User escritor = this.userService.getCurrentUser();
reviewEdit.setEscritor(escritor); reviewEdit.setEscritor(escritor);
this.reviewService.saveReview(reviewEdit); this.reviewService.saveReview(reviewEdit);
return "redirect:/reviews/" + reviewEdit.getId(); return "redirect:/reviews/" + reviewEdit.getId();
} }

View file

@ -1,3 +1,4 @@
package org.springframework.cheapy.web; package org.springframework.cheapy.web;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -13,6 +14,8 @@ import org.springframework.cheapy.model.SpeedOffer;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.ClientService;
import org.springframework.cheapy.service.SpeedOfferService; import org.springframework.cheapy.service.SpeedOfferService;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
@ -23,10 +26,11 @@ import org.springframework.web.bind.annotation.PostMapping;
@Controller @Controller
public class SpeedOfferController { public class SpeedOfferController {
private static final String VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM = "offers/speed/createOrUpdateSpeedOfferForm"; private static final String VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM = "offers/speed/createOrUpdateSpeedOfferForm";
private final SpeedOfferService speedOfferService;
private final ClientService clientService;
private final SpeedOfferService speedOfferService;
private final ClientService clientService;
public SpeedOfferController(final SpeedOfferService speedOfferService, final ClientService clientService) { public SpeedOfferController(final SpeedOfferService speedOfferService, final ClientService clientService) {
this.speedOfferService = speedOfferService; this.speedOfferService = speedOfferService;
@ -46,43 +50,44 @@ public class SpeedOfferController {
private boolean checkOffer(final SpeedOffer session, final SpeedOffer offer) { private boolean checkOffer(final SpeedOffer session, final SpeedOffer offer) {
boolean res = false; boolean res = false;
if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !session.getStatus().equals(StatusOffer.inactive)) {
&& (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) {
res = true; res = true;
} }
return res; return res;
} }
private boolean checkDates(final SpeedOffer speedOffer) { private boolean checkDates(final SpeedOffer speedOffer) {
boolean res = false; boolean res = false;
if(speedOffer.getEnd()==null || speedOffer.getStart()==null || speedOffer.getEnd().isAfter(speedOffer.getStart())) { if (speedOffer.getEnd() == null || speedOffer.getStart() == null || speedOffer.getEnd().isAfter(speedOffer.getStart())) {
res = true; res = true;
} }
return res; return res;
} }
private boolean checkConditions(final SpeedOffer speedOffer) { private boolean checkConditions(final SpeedOffer speedOffer) {
boolean res = false; boolean res = false;
if(speedOffer.getGold()==null || speedOffer.getSilver()==null || speedOffer.getBronze()==null) { if (speedOffer.getGold() == null || speedOffer.getSilver() == null || speedOffer.getBronze() == null) {
}else if(speedOffer.getGold() <= speedOffer.getSilver() && speedOffer.getSilver() <= speedOffer.getBronze()) { } else if (speedOffer.getGold() <= speedOffer.getSilver() && speedOffer.getSilver() <= speedOffer.getBronze()) {
res = true; res = true;
} }
return res; return res;
} }
private boolean checkDiscounts(final SpeedOffer speedOffer) { private boolean checkDiscounts(final SpeedOffer speedOffer) {
boolean res = false; boolean res = false;
if(speedOffer.getDiscountGold()==null || speedOffer.getDiscountSilver()==null || speedOffer.getDiscountBronze()==null) { if (speedOffer.getDiscountGold() == null || speedOffer.getDiscountSilver() == null || speedOffer.getDiscountBronze() == null) {
}else if(speedOffer.getDiscountGold() >= speedOffer.getDiscountSilver() && speedOffer.getDiscountSilver() >= speedOffer.getDiscountBronze()) { } else if (speedOffer.getDiscountGold() >= speedOffer.getDiscountSilver() && speedOffer.getDiscountSilver() >= speedOffer.getDiscountBronze()) {
res = true; res = true;
} }
return res; return res;
} }
@GetMapping("/offers/speedOfferList") @GetMapping("/offers/speedOfferList/{page}")
public String processFindForm(Map<String, Object> model) { public String processFindForm(@PathVariable("page") final int page, final Map<String, Object> model) {
List<SpeedOffer> speedOfferLs=this.speedOfferService.findActiveSpeedOffer(); Pageable elements = PageRequest.of(page, 5);
List<SpeedOffer> speedOfferLs = this.speedOfferService.findActiveSpeedOffer(elements);
model.put("speedOfferLs", speedOfferLs); model.put("speedOfferLs", speedOfferLs);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/speed/speedOffersList"; return "offers/speed/speedOffersList";
@ -90,42 +95,42 @@ public class SpeedOfferController {
} }
@GetMapping("/offers/speed/new") @GetMapping("/offers/speed/new")
public String initCreationForm(Map<String, Object> model) { public String initCreationForm(final Map<String, Object> model) {
SpeedOffer speedOffer = new SpeedOffer(); SpeedOffer speedOffer = new SpeedOffer();
model.put("speedOffer", speedOffer); model.put("speedOffer", speedOffer);
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
} }
@PostMapping("/offers/speed/new") @PostMapping("/offers/speed/new")
public String processCreationForm(@Valid SpeedOffer speedOffer, BindingResult result) { public String processCreationForm(@Valid final SpeedOffer speedOffer, final BindingResult result) {
if(!this.checkDates(speedOffer)) { if (!this.checkDates(speedOffer)) {
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio"); result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio");
} }
if(!this.checkConditions(speedOffer)) { if (!this.checkConditions(speedOffer)) {
result.rejectValue("gold","" ,"Oro debe ser menor o igual que plata, y plata menor o igual que bronce"); result.rejectValue("gold", "", "Oro debe ser menor o igual que plata, y plata menor o igual que bronce");
} }
if(!this.checkDiscounts(speedOffer)) { if (!this.checkDiscounts(speedOffer)) {
result.rejectValue("discountGold","" ,"El descuento de Oro debe ser menor o igual que el de plata, y el de plata menor o igual que el de bronce"); result.rejectValue("discountGold", "", "El descuento de Oro debe ser menor o igual que el de plata, y el de plata menor o igual que el de bronce");
} }
if (result.hasErrors()) { if (result.hasErrors()) {
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
} }
Client client = this.clientService.getCurrentClient(); Client client = this.clientService.getCurrentClient();
speedOffer.setClient(client); speedOffer.setClient(client);
speedOffer.setStatus(StatusOffer.hidden); speedOffer.setStatus(StatusOffer.hidden);
this.speedOfferService.saveSpeedOffer(speedOffer); this.speedOfferService.saveSpeedOffer(speedOffer);
return "redirect:/offers/speed/" + speedOffer.getId(); return "redirect:/offers/speed/" + speedOffer.getId();
} }
@GetMapping(value = "/offers/speed/{speedOfferId}/activate") @GetMapping(value = "/offers/speed/{speedOfferId}/activate")
public String activateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, ModelMap modelMap) { public String activateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap modelMap) {
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
Client client = this.clientService.getCurrentClient(); Client client = this.clientService.getCurrentClient();
if (speedOffer.getClient().equals(client)) { if (speedOffer.getClient().equals(client)) {
@ -139,24 +144,24 @@ public class SpeedOfferController {
} }
@GetMapping("/offers/speed/{speedOfferId}") @GetMapping("/offers/speed/{speedOfferId}")
public String processShowForm(@PathVariable("speedOfferId") int speedOfferId, Map<String, Object> model) { public String processShowForm(@PathVariable("speedOfferId") final int speedOfferId, final Map<String, Object> model) {
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
if(speedOffer.getStatus().equals(StatusOffer.active)) { if (speedOffer.getStatus().equals(StatusOffer.active)) {
model.put("speedOffer", speedOffer); model.put("speedOffer", speedOffer);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/speed/speedOffersShow"; return "offers/speed/speedOffersShow";
}else if(speedOffer.getStatus().equals(StatusOffer.hidden)&&(this.checkIdentity(speedOfferId))) { } else if (speedOffer.getStatus().equals(StatusOffer.hidden) && this.checkIdentity(speedOfferId)) {
model.put("speedOffer", speedOffer); model.put("speedOffer", speedOffer);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/speed/speedOffersShow"; return "offers/speed/speedOffersShow";
}else { } else {
return "error"; return "error";
} }
} }
@GetMapping(value = "/offers/speed/{speedOfferId}/edit") @GetMapping(value = "/offers/speed/{speedOfferId}/edit")
public String updateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model, HttpServletRequest request) { public String updateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model, final HttpServletRequest request) {
if (!this.checkIdentity(speedOfferId)) { if (!this.checkIdentity(speedOfferId)) {
return "error"; return "error";
@ -172,8 +177,7 @@ public class SpeedOfferController {
} }
@PostMapping(value = "/offers/speed/{speedOfferId}/edit") @PostMapping(value = "/offers/speed/{speedOfferId}/edit")
public String updateSpeedOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, public String updateSpeedOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, final ModelMap model, final HttpServletRequest request) {
final ModelMap model, HttpServletRequest request) {
if (!this.checkIdentity(speedOfferEdit.getId())) { if (!this.checkIdentity(speedOfferEdit.getId())) {
return "error"; return "error";
@ -184,29 +188,27 @@ public class SpeedOfferController {
return "error"; return "error";
} }
if(!this.checkDates(speedOfferEdit)) { if (!this.checkDates(speedOfferEdit)) {
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio"); result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio");
}
if(!this.checkConditions(speedOfferEdit)) {
result.rejectValue("gold","" ,"Oro debe ser menor o igual que plata, y plata menor o igual que bronce");
}
if(!this.checkDiscounts(speedOfferEdit)) {
result.rejectValue("discountGold","" ,"El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce");
}
if (result.hasErrors()) {
model.addAttribute("speedOffer", speedOfferEdit);
return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
} }
BeanUtils.copyProperties(this.speedOfferService.findSpeedOfferById(speedOfferEdit.getId()), speedOfferEdit, if (!this.checkConditions(speedOfferEdit)) {
"start", "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze"); result.rejectValue("gold", "", "Oro debe ser menor o igual que plata, y plata menor o igual que bronce");
this.speedOfferService.saveSpeedOffer(speedOfferEdit);
return "redirect:/offers/speed/" + speedOfferEdit.getId(); }
if (!this.checkDiscounts(speedOfferEdit)) {
result.rejectValue("discountGold", "", "El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce");
}
if (result.hasErrors()) {
model.addAttribute("speedOffer", speedOfferEdit);
return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
}
BeanUtils.copyProperties(this.speedOfferService.findSpeedOfferById(speedOfferEdit.getId()), speedOfferEdit, "start", "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze");
this.speedOfferService.saveSpeedOffer(speedOfferEdit);
return "redirect:/offers/speed/" + speedOfferEdit.getId();
} }

View file

@ -1,3 +1,4 @@
package org.springframework.cheapy.web; package org.springframework.cheapy.web;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -13,6 +14,8 @@ import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.model.TimeOffer;
import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.ClientService;
import org.springframework.cheapy.service.TimeOfferService; import org.springframework.cheapy.service.TimeOfferService;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
@ -23,11 +26,12 @@ import org.springframework.web.bind.annotation.PostMapping;
@Controller @Controller
public class TimeOfferController { public class TimeOfferController {
private static final String VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM = "offers/time/createOrUpdateTimeOfferForm"; private static final String VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM = "offers/time/createOrUpdateTimeOfferForm";
private final TimeOfferService timeOfferService; private final TimeOfferService timeOfferService;
private final ClientService clientService; private final ClientService clientService;
public TimeOfferController(final TimeOfferService timeOfferService, ClientService clientService) {
public TimeOfferController(final TimeOfferService timeOfferService, final ClientService clientService) {
this.timeOfferService = timeOfferService; this.timeOfferService = timeOfferService;
this.clientService = clientService; this.clientService = clientService;
} }
@ -45,32 +49,33 @@ public class TimeOfferController {
private boolean checkOffer(final TimeOffer session, final TimeOffer offer) { private boolean checkOffer(final TimeOffer session, final TimeOffer offer) {
boolean res = false; boolean res = false;
if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !session.getStatus().equals(StatusOffer.inactive)) {
&& (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) {
res = true; res = true;
} }
return res; return res;
} }
private boolean checkDates(final TimeOffer timeOffer) { private boolean checkDates(final TimeOffer timeOffer) {
boolean res = false; boolean res = false;
if(timeOffer.getEnd()==null || timeOffer.getStart()==null || timeOffer.getEnd().isAfter(timeOffer.getStart())) { if (timeOffer.getEnd() == null || timeOffer.getStart() == null || timeOffer.getEnd().isAfter(timeOffer.getStart())) {
res = true; res = true;
} }
return res; return res;
} }
private boolean checkTimes(final TimeOffer timeOffer) { private boolean checkTimes(final TimeOffer timeOffer) {
boolean res = false; boolean res = false;
if(timeOffer.getFinish()==null || timeOffer.getInit()==null || timeOffer.getFinish().isAfter(timeOffer.getInit())) { if (timeOffer.getFinish() == null || timeOffer.getInit() == null || timeOffer.getFinish().isAfter(timeOffer.getInit())) {
res = true; res = true;
} }
return res; return res;
} }
@GetMapping("/offers/timeOfferList") @GetMapping("/offers/timeOfferList/{page}")
public String processFindForm(Map<String, Object> model) { public String processFindForm(@PathVariable("page") final int page, final Map<String, Object> model) {
List<TimeOffer> timeOfferLs=this.timeOfferService.findActiveTimeOffer(); Pageable elements = PageRequest.of(page, 5);
List<TimeOffer> timeOfferLs = this.timeOfferService.findActiveTimeOffer(elements);
model.put("timeOfferLs", timeOfferLs); model.put("timeOfferLs", timeOfferLs);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/time/timeOffersList"; return "offers/time/timeOffersList";
@ -78,38 +83,38 @@ public class TimeOfferController {
} }
@GetMapping("/offers/time/new") @GetMapping("/offers/time/new")
public String initCreationForm(Map<String, Object> model) { public String initCreationForm(final Map<String, Object> model) {
TimeOffer timeOffer = new TimeOffer(); TimeOffer timeOffer = new TimeOffer();
model.put("timeOffer", timeOffer); model.put("timeOffer", timeOffer);
return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
} }
@PostMapping("/offers/time/new") @PostMapping("/offers/time/new")
public String processCreationForm(@Valid TimeOffer timeOffer, BindingResult result) { public String processCreationForm(@Valid final TimeOffer timeOffer, final BindingResult result) {
if(!this.checkDates(timeOffer)) {
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio");
}
if(!this.checkTimes(timeOffer)) {
result.rejectValue("finish","" ,"La hora de fin debe ser posterior a la de inicio");
}
if (result.hasErrors()) {
return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
}
timeOffer.setStatus(StatusOffer.hidden);
Client client = this.clientService.getCurrentClient(); if (!this.checkDates(timeOffer)) {
result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio");
timeOffer.setClient(client); }
if (!this.checkTimes(timeOffer)) {
result.rejectValue("finish", "", "La hora de fin debe ser posterior a la de inicio");
}
if (result.hasErrors()) {
return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
}
timeOffer.setStatus(StatusOffer.hidden);
Client client = this.clientService.getCurrentClient();
timeOffer.setClient(client);
this.timeOfferService.saveTimeOffer(timeOffer);
return "redirect:/offers/time/" + timeOffer.getId();
this.timeOfferService.saveTimeOffer(timeOffer);
return "redirect:/offers/time/" + timeOffer.getId();
} }
@GetMapping(value = "/offers/time/{timeOfferId}/activate") @GetMapping(value = "/offers/time/{timeOfferId}/activate")
@ -129,26 +134,25 @@ public class TimeOfferController {
} }
@GetMapping("/offers/time/{timeOfferId}") @GetMapping("/offers/time/{timeOfferId}")
public String processShowForm(@PathVariable("timeOfferId") int timeOfferId, Map<String, Object> model) { public String processShowForm(@PathVariable("timeOfferId") final int timeOfferId, final Map<String, Object> model) {
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
if(timeOffer.getStatus().equals(StatusOffer.active)) { if (timeOffer.getStatus().equals(StatusOffer.active)) {
model.put("timeOffer", timeOffer); model.put("timeOffer", timeOffer);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/time/timeOffersShow"; return "offers/time/timeOffersShow";
} else if(timeOffer.getStatus().equals(StatusOffer.hidden)&&(this.checkIdentity(timeOfferId))) { } else if (timeOffer.getStatus().equals(StatusOffer.hidden) && this.checkIdentity(timeOfferId)) {
model.put("timeOffer", timeOffer); model.put("timeOffer", timeOffer);
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/time/timeOffersShow"; return "offers/time/timeOffersShow";
}else { } else {
return "error"; return "error";
} }
} }
@GetMapping(value = "/offers/time/{timeOfferId}/edit") @GetMapping(value = "/offers/time/{timeOfferId}/edit")
public String updateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model, public String updateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model, final HttpServletRequest request) {
HttpServletRequest request) {
if (!this.checkIdentity(timeOfferId)) { if (!this.checkIdentity(timeOfferId)) {
return "error"; return "error";
@ -164,8 +168,7 @@ public class TimeOfferController {
} }
@PostMapping(value = "/offers/time/{timeOfferId}/edit") @PostMapping(value = "/offers/time/{timeOfferId}/edit")
public String updateTimeOffer(@Valid final TimeOffer timeOfferEdit, final BindingResult result, public String updateTimeOffer(@Valid final TimeOffer timeOfferEdit, final BindingResult result, final ModelMap model, final HttpServletRequest request) {
final ModelMap model, HttpServletRequest request) {
if (!this.checkIdentity(timeOfferEdit.getId())) { if (!this.checkIdentity(timeOfferEdit.getId())) {
return "error"; return "error";
@ -176,26 +179,23 @@ public class TimeOfferController {
return "error"; return "error";
} }
if (!this.checkDates(timeOfferEdit)) {
if(!this.checkDates(timeOfferEdit)) { result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio");
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio");
}
if(!this.checkTimes(timeOfferEdit)) {
result.rejectValue("finish","" ,"La hora de fin debe ser posterior a la de inicio");
}
if (result.hasErrors()) {
model.addAttribute("timeOffer", timeOfferEdit);
return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
} }
if (!this.checkTimes(timeOfferEdit)) {
BeanUtils.copyProperties(this.timeOfferService.findTimeOfferById(timeOfferEdit.getId()), timeOfferEdit, result.rejectValue("finish", "", "La hora de fin debe ser posterior a la de inicio");
"start", "end", "init", "finish", "discount");
this.timeOfferService.saveTimeOffer(timeOfferEdit); }
return "redirect:/offers/time/" + timeOfferEdit.getId(); if (result.hasErrors()) {
model.addAttribute("timeOffer", timeOfferEdit);
return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
}
BeanUtils.copyProperties(this.timeOfferService.findTimeOfferById(timeOfferEdit.getId()), timeOfferEdit, "start", "end", "init", "finish", "discount");
this.timeOfferService.saveTimeOffer(timeOfferEdit);
return "redirect:/offers/time/" + timeOfferEdit.getId();
} }

View file

@ -9,23 +9,34 @@
<cheapy:layout pageName="ofertas de plato especifico"> <cheapy:layout pageName="ofertas de plato especifico">
<spring:url value="/offers/nuOfferList" var="nuOfferUrl"> <spring:url value="/offers/foodOfferList/{page}" var="foodOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/nuOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(foodOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de plato especifico</button>
<spring:url value="/offers/nuOfferList/{page}" var="nuOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(nuOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas por número de comensales</button> Ofertas por número de comensales</button>
<spring:url value="/offers/speedOfferList" var="speedOfferUrl"> <spring:url value="/offers/speedOfferList/{page}" var="speedOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/speedOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(speedOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de velocidad</button> Ofertas de velocidad</button>
<spring:url value="/offers/timeOfferList" var="timeOfferUrl"> <spring:url value="/offers/timeOfferList/{page}" var="timeOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/timeOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(timeOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de franja horaria</button> Ofertas de franja horaria</button>
<h2 style="text-align:center;padding:5px"><fmt:message key="foodOffers"/></h2> <h2 style="text-align:center;padding:5px"><fmt:message key="foodOffers"/></h2>
@ -80,6 +91,23 @@
</c:forEach> </c:forEach>
</tbody> </tbody>
</table> </table>
<c:if test='${page!=0}'>
<spring:url value="/offers/foodOfferList/{page}" var="foodOfferListUrl">
<spring:param name="page" value="${page-1}"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(foodOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Pág. anterior</button>
</c:if>
<c:out value='${page}'></c:out>
<c:if test="${fn:length(foodOfferLs) == 5}">
<spring:url value="/offers/foodOfferList/{page}" var="foodOfferListUrl">
<spring:param name="page" value="${page+1}"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(foodOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Pág. siguiente</button>
</c:if>
</c:if> </c:if>
</cheapy:layout> </cheapy:layout>

View file

@ -9,24 +9,35 @@
<cheapy:layout pageName="ofertas"> <cheapy:layout pageName="ofertas">
<spring:url value="/offers/foodOfferList" var="foodOfferUrl"> <spring:url value="/offers/foodOfferList/{page}" var="foodOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/foodOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(foodOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de plato especifico</button> Ofertas de plato especifico</button>
<spring:url value="/offers/speedOfferList" var="speedOfferUrl"> <spring:url value="/offers/nuOfferList/{page}" var="nuOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/speedOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(nuOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas por número de comensales</button>
<spring:url value="/offers/speedOfferList/{page}" var="speedOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(speedOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de velocidad</button> Ofertas de velocidad</button>
<spring:url value="/offers/timeOfferList" var="timeOfferUrl"> <spring:url value="/offers/timeOfferList/{page}" var="timeOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/timeOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(timeOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de franja horaria</button> Ofertas de franja horaria</button>
<h2 style="text-align:center;padding:5px"><fmt:message key="nuOffers"/></h2> <h2 style="text-align:center;padding:5px"><fmt:message key="nuOffers"/></h2>
<c:if test="${empty nuOfferLs }"> <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>
@ -77,6 +88,23 @@
</c:forEach> </c:forEach>
</tbody> </tbody>
</table> </table>
<c:if test='${page!=0}'>
<spring:url value="/offers/nuOfferList/{page}" var="nuOfferListUrl">
<spring:param name="page" value="${page-1}"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(nuOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Pág. anterior</button>
</c:if>
<c:out value='${page}'></c:out>
<c:if test="${fn:length(nuOfferLs) == 5}">
<spring:url value="/offers/nuOfferList/{page}" var="nuOfferListUrl">
<spring:param name="page" value="${page+1}"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(nuOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Pág. siguiente</button>
</c:if>
</c:if> </c:if>
</cheapy:layout> </cheapy:layout>

View file

@ -9,34 +9,38 @@
<cheapy:layout pageName="ofertas"> <cheapy:layout pageName="ofertas">
<spring:url value="/offers/foodOfferList" var="foodOfferUrl"> <spring:url value="/offers/foodOfferList/{page}" var="foodOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/foodOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(foodOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de plato especifico</button> Ofertas de plato especifico</button>
<spring:url value="/offers/nuOfferList" var="nuOfferUrl"> <spring:url value="/offers/nuOfferList/{page}" var="nuOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/nuOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(nuOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas por número de comensales</button> Ofertas por número de comensales</button>
<spring:url value="/offers/speedOfferList" var="speedOfferUrl"> <spring:url value="/offers/speedOfferList/{page}" var="speedOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/speedOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(speedOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de velocidad</button> Ofertas de velocidad</button>
<spring:url value="/offers/timeOfferList" var="timeOfferUrl"> <spring:url value="/offers/timeOfferList/{page}" var="timeOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/timeOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(timeOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de franja horaria</button> Ofertas de franja horaria</button>
<h2 style="text-align:center;padding:5px"><fmt:message key="foodOffers"/></h2> <h2 style="text-align:center;padding:5px"><fmt:message key="foodOffers"/></h2>
<c:if test="${empty foodOfferLs }"> <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>
<c:if test="${not empty foodOfferLs }"> <c:if test="${not empty foodOfferLs }">
@ -88,6 +92,9 @@
</c:forEach> </c:forEach>
</tbody> </tbody>
</table> </table>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(foodOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ver más</button>
</div> </div>
</c:if> </c:if>
@ -143,6 +150,9 @@
</c:forEach> </c:forEach>
</tbody> </tbody>
</table> </table>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(nuOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ver más</button>
</div> </div>
</c:if> </c:if>
@ -200,6 +210,10 @@
</c:forEach> </c:forEach>
</tbody> </tbody>
</table> </table>
<spring:url value="/offers/speedOfferList" var="speedOfferUrl"></spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(speedOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ver más</button>
</div> </div>
</c:if> </c:if>
@ -254,9 +268,12 @@
</td> </td>
</tr> </tr>
</c:forEach> </c:forEach>
</tbody>
</table> </table>
</div> <spring:url value="/offers/timeOfferList" var="timeOfferUrl"></spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(timeOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ver más</button>
</div>
</c:if> </c:if>

View file

@ -9,24 +9,35 @@
<cheapy:layout pageName="ofertas"> <cheapy:layout pageName="ofertas">
<spring:url value="/offers/foodOfferList" var="foodOfferUrl"> <spring:url value="/offers/foodOfferList/{page}" var="foodOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/foodOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(foodOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de plato especifico</button> Ofertas de plato especifico</button>
<spring:url value="/offers/nuOfferList" var="nuOfferUrl"> <spring:url value="/offers/nuOfferList/{page}" var="nuOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/nuOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(nuOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas por número de comensales</button> Ofertas por número de comensales</button>
<spring:url value="/offers/timeOfferList" var="timeOfferUrl"> <spring:url value="/offers/speedOfferList/{page}" var="speedOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/timeOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(speedOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de velocidad</button>
<spring:url value="/offers/timeOfferList/{page}" var="timeOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(timeOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de franja horaria</button> Ofertas de franja horaria</button>
<h2 style="text-align:center;padding:5px"><fmt:message key="speedOffers"/></h2> <h2 style="text-align:center;padding:5px"><fmt:message key="speedOffers"/></h2>
<c:if test="${empty speedOfferLs }"> <c:if test="${empty speedOfferLs }">
<p id="vacio" >No hay ninguna oferta por tiempo empleado en comer activa.</p> <p id="vacio" >No hay ninguna oferta por tiempo empleado en comer activa.</p>
@ -78,5 +89,22 @@
</c:forEach> </c:forEach>
</tbody> </tbody>
</table> </table>
<c:if test='${page!=0}'>
<spring:url value="/offers/speedOfferList/{page}" var="speedOfferListUrl">
<spring:param name="page" value="${page-1}"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(speedOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Pág. anterior</button>
</c:if>
<c:out value='${page}'></c:out>
<c:if test="${fn:length(speedOfferLs) == 5}">
<spring:url value="/offers/speedOfferList/{page}" var="speedOfferListUrl">
<spring:param name="page" value="${page+1}"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(speedOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Pág. siguiente</button>
</c:if>
</c:if> </c:if>
</cheapy:layout> </cheapy:layout>

View file

@ -9,23 +9,34 @@
<cheapy:layout pageName="ofertas"> <cheapy:layout pageName="ofertas">
<spring:url value="/offers/foodOfferList" var="foodOfferUrl"> <spring:url value="/offers/foodOfferList/{page}" var="foodOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/foodOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(foodOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de plato especifico</button> Ofertas de plato especifico</button>
<spring:url value="/offers/nuOfferList" var="nuOfferUrl"> <spring:url value="/offers/nuOfferList/{page}" var="nuOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/nuOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(nuOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas por número de comensales</button> Ofertas por número de comensales</button>
<spring:url value="/offers/speedOfferList" var="speedOfferUrl"> <spring:url value="/offers/speedOfferList/{page}" var="speedOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url> </spring:url>
<button type="button" role="link" onclick="window.location='/offers/speedOfferList'" style="font-family: 'Lobster'; font-size: 20px;"> <button type="button" role="link" onclick="window.location='${fn:escapeXml(speedOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span> <span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de velocidad</button> Ofertas de velocidad</button>
<spring:url value="/offers/timeOfferList/{page}" var="timeOfferListUrl">
<spring:param name="page" value="0"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(timeOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Ofertas de franja horaria</button>
<h2 style="text-align:center;padding:5px"><fmt:message key="timeOffers"/></h2> <h2 style="text-align:center;padding:5px"><fmt:message key="timeOffers"/></h2>
<c:if test="${empty timeOfferLs }"> <c:if test="${empty timeOfferLs }">
@ -77,6 +88,23 @@
</c:forEach> </c:forEach>
</tbody> </tbody>
</table> </table>
<c:if test='${page!=0}'>
<spring:url value="/offers/timeOfferList/{page}" var="timeOfferListUrl">
<spring:param name="page" value="${page-1}"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(timeOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Pág. anterior</button>
</c:if>
<c:out value='${page}'></c:out>
<c:if test="${fn:length(timeOfferLs) == 5}">
<spring:url value="/offers/foodOfferList/{page}" var="timeOfferListUrl">
<spring:param name="page" value="${page+1}"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(timeOfferListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Pág. siguiente</button>
</c:if>
</c:if> </c:if>
</cheapy:layout> </cheapy:layout>

View file

@ -21,7 +21,7 @@
</thead> </thead>
<tbody> <tbody>
<c:choose> <c:choose>
<c:when test="${fn:length(reviewsLs) == 0}"> <c:when test="${empty reviewsLs}">
<tr><td colspan="4"><em><c:out value="No se ha realizado ninguna valoración por el momento."/></em></td></tr> <tr><td colspan="4"><em><c:out value="No se ha realizado ninguna valoración por el momento."/></em></td></tr>
</c:when> </c:when>
<c:otherwise> <c:otherwise>
@ -56,4 +56,21 @@
</c:choose> </c:choose>
</tbody> </tbody>
</table> </table>
<c:if test='${page!=0}'>
<spring:url value="/reviewsList/{page}" var="reviewsListUrl">
<spring:param name="page" value="${page-1}"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(reviewsListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Pág. anterior</button>
</c:if>
<c:out value='${page}'></c:out>
<c:if test="${fn:length(reviewsLs) == 6}">
<spring:url value="/reviewsList/{page}" var="reviewsListUrl">
<spring:param name="page" value="${page+1}"/>
</spring:url>
<button type="button" role="link" onclick="window.location='${fn:escapeXml(reviewsListUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon glyphicon-edit" aria-hidden="true" style="padding: 5px"> </span>
Pág. siguiente</button>
</c:if>
</cheapy:layout> </cheapy:layout>

View file

@ -61,7 +61,7 @@
</cheapy:menuItem> </cheapy:menuItem>
--> -->
<sec:authorize access="isAuthenticated()"> <sec:authorize access="isAuthenticated()">
<cheapy:menuItem active="${name eq 'reviews'}" url="/reviews" title="opiniones"> <cheapy:menuItem active="${name eq 'reviews'}" url="/reviewsList/0" title="opiniones">
<span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span> <span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span>
<span>Reseñas</span> <span>Reseñas</span>
</cheapy:menuItem> </cheapy:menuItem>