Merge branch '018-paginacion-issue#65' into develop

This commit is contained in:
gabgutpri 2021-04-10 18:02:29 +02:00 committed by GitHub
commit 6758905a86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 96 additions and 70 deletions

View file

@ -1,15 +1,17 @@
package org.springframework.cheapy.repository;
import java.util.List;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.StatusOffer;
import java.util.List;
import org.springframework.data.domain.Pageable;
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.transaction.annotation.Transactional;
public interface FoodOfferRepository extends Repository<FoodOffer, Integer> {
public interface FoodOfferRepository extends PagingAndSortingRepository<FoodOffer, Integer> {
@Query("SELECT foodOffer FROM FoodOffer foodOffer")
@Transactional(readOnly = true)
@ -17,18 +19,18 @@ public interface FoodOfferRepository extends Repository<FoodOffer, Integer> {
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE id =:id")
@Transactional(readOnly = true)
FoodOffer findById(@Param("id") Integer id);
FoodOffer findByIdFO(@Param("id") Integer id);
//void save(FoodOffer foodOffer);
void save(FoodOffer foodOffer);
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.status =:status")
@Transactional(readOnly = true)
List<FoodOffer> findActiveFoodOffer(StatusOffer status);
List<FoodOffer> findActiveFoodOffer(StatusOffer status, Pageable p);
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.id =:id")
@Transactional(readOnly = true)
List<FoodOffer> findByUserId(@Param("id") Integer id);
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.id =:id AND foodOffer.status!= 'inactive'")
@Transactional(readOnly = true)
List<FoodOffer> findFoodOfferActOclByUserId(@Param("id") Integer id);

View file

@ -1,43 +1,47 @@
package org.springframework.cheapy.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.repository.FoodOfferRepository;
import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
@Service
public class FoodOfferService {
private FoodOfferRepository foodOfferRepository;
@Autowired
public FoodOfferService(final FoodOfferRepository foodOfferRepository) {
this.foodOfferRepository = foodOfferRepository;
}
public FoodOffer findFoodOfferById(final int id) {
return this.foodOfferRepository.findById(id);
return this.foodOfferRepository.findByIdFO(id);
}
public List<FoodOffer> findAllFoodOffer() { //
public List<FoodOffer> findAllFoodOffer(final Pageable p) { //
return this.foodOfferRepository.findAllFoodOffer();
}
public void saveFoodOffer(final FoodOffer foodOffer) throws DataAccessException {
this.foodOfferRepository.save(foodOffer);
}
public List<FoodOffer> findActiveFoodOffer() {
return this.foodOfferRepository.findActiveFoodOffer(StatusOffer.active);
public List<FoodOffer> findActiveFoodOffer(final Pageable p) {
return this.foodOfferRepository.findActiveFoodOffer(StatusOffer.active, p);
}
public List<FoodOffer> findFoodOfferByUserId(final int id) {
return this.foodOfferRepository.findByUserId(id);
}
public List<FoodOffer> findFoodOfferActOclByUserId(final int id) {
return this.foodOfferRepository.findFoodOfferActOclByUserId(id);
}

View file

@ -1,3 +1,4 @@
package org.springframework.cheapy.web;
import java.time.format.DateTimeFormatter;
@ -13,21 +14,23 @@ import org.springframework.cheapy.service.FoodOfferService;
import org.springframework.cheapy.service.NuOfferService;
import org.springframework.cheapy.service.SpeedOfferService;
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.web.bind.annotation.GetMapping;
@Controller
public class OfertaController {
private final ClientService clientService;
private final ClientService clientService;
private final FoodOfferService foodOfferService;
private final NuOfferService nuOfferService;
private final SpeedOfferService speedOfferService;
private final TimeOfferService timeOfferService;
private final FoodOfferService foodOfferService;
private final NuOfferService nuOfferService;
private final SpeedOfferService speedOfferService;
private final TimeOfferService timeOfferService;
public OfertaController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService,
final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService, ClientService clientService) {
public OfertaController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService, final ClientService clientService) {
this.clientService = clientService;
this.foodOfferService = foodOfferService;
this.nuOfferService = nuOfferService;
@ -36,12 +39,13 @@ public class OfertaController {
}
@GetMapping("/offers")
public String processFindForm( Map<String, Object> model) {
public String processFindForm(final Map<String, Object> model) {
Pageable elements = PageRequest.of(0, 3);
List<FoodOffer> foodOfferLs=this.foodOfferService.findActiveFoodOffer();
List<NuOffer> nuOfferLs=this.nuOfferService.findActiveNuOffer();
List<SpeedOffer> speedOfferLs=this.speedOfferService.findActiveSpeedOffer();
List<TimeOffer> timeOfferLs=this.timeOfferService.findActiveTimeOffer();
List<FoodOffer> foodOfferLs = this.foodOfferService.findActiveFoodOffer(elements);
List<NuOffer> nuOfferLs = this.nuOfferService.findActiveNuOffer();
List<SpeedOffer> speedOfferLs = this.speedOfferService.findActiveSpeedOffer();
List<TimeOffer> timeOfferLs = this.timeOfferService.findActiveTimeOffer();
model.put("foodOfferLs", foodOfferLs);
model.put("nuOfferLs", nuOfferLs);
@ -55,9 +59,8 @@ public class OfertaController {
}
@GetMapping("/myOffers")
public String processMyOffersForm( Map<String, Object> model) {
public String processMyOffersForm(final Map<String, Object> model) {
int actual = this.clientService.getCurrentClient().getId();
@ -75,43 +78,40 @@ public class OfertaController {
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/myOffersList";
}
}
@GetMapping("/offersCreate")
public String createOffers() {
@GetMapping("/offersCreate")
public String createOffers() {
return "offers/offersCreate";
}
// @GetMapping("/owners/{ownerId}/edit")
// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
// Owner owner = this.ownerService.findOwnerById(ownerId);
// model.addAttribute(owner);
// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
// }
//
// @PostMapping("/owners/{ownerId}/edit")
// public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result,
// @PathVariable("ownerId") int ownerId) {
// if (result.hasErrors()) {
// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
// }
// else {
// owner.setId(ownerId);
// this.ownerService.saveOwner(owner);
// return "redirect:/owners/{ownerId}";
// }
// }
// @GetMapping("/owners/{ownerId}")
// public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
// ModelAndView mav = new ModelAndView("owners/ownerDetails");
// Owner owner = this.ownerService.findOwnerById(ownerId);
//
// mav.addObject(owner);
// return mav;
// }
return "offers/offersCreate";
}
// @GetMapping("/owners/{ownerId}/edit")
// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
// Owner owner = this.ownerService.findOwnerById(ownerId);
// model.addAttribute(owner);
// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
// }
//
// @PostMapping("/owners/{ownerId}/edit")
// public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result,
// @PathVariable("ownerId") int ownerId) {
// if (result.hasErrors()) {
// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
// }
// else {
// owner.setId(ownerId);
// this.ownerService.saveOwner(owner);
// return "redirect:/owners/{ownerId}";
// }
// }
// @GetMapping("/owners/{ownerId}")
// public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
// ModelAndView mav = new ModelAndView("owners/ownerDetails");
// Owner owner = this.ownerService.findOwnerById(ownerId);
//
// mav.addObject(owner);
// return mav;
// }
}

View file

@ -24,16 +24,36 @@ INSERT INTO clients (id, name, email, address, init, finish, telephone, descript
INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'FO-1', 'inactive', 1, 'macarrones', 15);
INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'FO-2', 'active', 1, 'macarrones con tomate', 10);
INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'FO-3', 'active', 1, 'Estofado', 10);
INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'FO-4', 'active', 1, 'Puchero', 10);
INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'FO-5', 'active', 2, 'Tumbalobos', 10);
INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'FO-6', 'active', 2, 'Tortilla', 10);
INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'FO-7', 'active', 2, 'Arroz con leche', 10);
INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden', 1, 'macarrones con queso', 5);
INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'T-1', 'inactive', 1, '12:00:00', '13:00:00', 5);
INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-2', 'active', 1, '12:00:00', '13:00:00', 10);
INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-3', 'active', 1, '12:30:00', '14:30:00', 10);
INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-4', 'active', 1, '12:00:00', '13:00:00', 5);
INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-5', 'active', 2, '13:00:00', '16:00:00', 15);
INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-6', 'active', 2, '14:00:00', '17:00:00', 15);
INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-7', 'active', 2, '11:00:00', '20:00:00', 20);
INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden', 1, '12:00:00', '13:00:00', 15);
INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'SP-1', 'inactive',1,5,25,10,15,15,10);
INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-2', 'active',1,5,25,10,15,15,10);
INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-2', 'active',1,35,25,40,15,55,10);
INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-3', 'active',1,25,25,30,15,35,10);
INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-4', 'active',1,15,25,20,15,35,10);
INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-5', 'active',2,15,30,20,15,50,5);
INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-6', 'active',2,15,30,21,15,50,5);
INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-7', 'active',2,15,30,22,15,50,5);
INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden',1,5,25,10,15,15,10);
INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'NU-1', 'inactive',1,15,25,10,15,5,10);
INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-2', 'active',1,15,25,10,15,5,10);
INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-3', 'active',1,15,25,12,15,3,5);
INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-4', 'active',1,15,25,13,15,2,5);
INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-5', 'active',2,20,35,15,15,5,5);
INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-6', 'active',2,20,30,15,10,10,5);
INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-7', 'active',2,20,35,15,15,10,5);
INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden',1,15,25,10,15,5,10);