032-filtro_municipio-issue#98

032 filtro municipio issue#98
This commit is contained in:
gabgutpri 2021-04-15 13:14:03 +02:00 committed by GitHub
commit 1dcabed523
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 185 additions and 89 deletions

View file

@ -1,3 +1,4 @@
package org.springframework.cheapy.model;
import java.time.LocalTime;
@ -21,121 +22,126 @@ import org.springframework.format.annotation.DateTimeFormat;
@Table(name = "clients")
public class Client extends BaseEntity {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
// (id, name, email, address, init, finish, telephone, description, code, food,
// usuar)
@NotEmpty
private String name;
private String name;
@NotEmpty
private String email;
private String email;
@NotEmpty
private String address;
@Enumerated(value = EnumType.STRING)
private String address;
@NotNull
private Municipio municipio;
@Enumerated(value = EnumType.STRING)
private Municipio municipio;
// Hora de apertura del local
@DateTimeFormat(pattern = "HH:mm")
@NotNull(message = "Debe introducir una hora de apertura")
private LocalTime init;
private LocalTime init;
// Hora de cierre del local
@DateTimeFormat(pattern = "HH:mm")
@NotNull(message = "Debe introducir una hora de cierre")
private LocalTime finish;
private LocalTime finish;
@NotEmpty
@Digits(fraction = 0, integer = 10)
private String telephone;
private String telephone;
@NotEmpty
private String description;
// Codigo de activacion de cuenta
// @NotEmpty
// private String code;
private String description;
@NotEmpty
private String food;
private String food;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "username", referencedColumnName = "username")
private User usuar;
private User usuar;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "code", referencedColumnName = "code")
private Code cod;
@OneToMany
private List<FoodOffer> foodOffers;
private List<FoodOffer> foodOffers;
@OneToMany
private List<NuOffer> nuOffers;
private List<NuOffer> nuOffers;
@OneToMany
private List<SpeedOffer> speedOffers;
private List<SpeedOffer> speedOffers;
@OneToMany
private List<TimeOffer> timeOffers;
private List<TimeOffer> timeOffers;
public String getName() {
return name;
return this.name;
}
public void setName(String name) {
public void setName(final String name) {
this.name = name;
}
public String getEmail() {
return email;
return this.email;
}
public void setEmail(String email) {
public void setEmail(final String email) {
this.email = email;
}
public String getAddress() {
return address;
return this.address;
}
public void setAddress(String address) {
public void setAddress(final String address) {
this.address = address;
}
public LocalTime getInit() {
return init;
public Municipio getMunicipio() {
return this.municipio;
}
public void setInit(LocalTime init) {
public void setMunicipio(final Municipio municipio) {
this.municipio = municipio;
}
public LocalTime getInit() {
return this.init;
}
public void setInit(final LocalTime init) {
this.init = init;
}
public LocalTime getFinish() {
return finish;
return this.finish;
}
public void setFinish(LocalTime finish) {
public void setFinish(final LocalTime finish) {
this.finish = finish;
}
public String getTelephone() {
return telephone;
return this.telephone;
}
public void setTelephone(String telephone) {
public void setTelephone(final String telephone) {
this.telephone = telephone;
}
public String getDescription() {
return description;
return this.description;
}
public void setDescription(String description) {
public void setDescription(final String description) {
this.description = description;
}
@ -156,51 +162,51 @@ public class Client extends BaseEntity {
}
public String getFood() {
return food;
return this.food;
}
public void setFood(String food) {
public void setFood(final String food) {
this.food = food;
}
public User getUsuar() {
return usuar;
return this.usuar;
}
public void setUsuar(User usuar) {
public void setUsuar(final User usuar) {
this.usuar = usuar;
}
public List<FoodOffer> getFoodOffers() {
return foodOffers;
return this.foodOffers;
}
public void setFoodOffers(List<FoodOffer> foodOffers) {
public void setFoodOffers(final List<FoodOffer> foodOffers) {
this.foodOffers = foodOffers;
}
public List<NuOffer> getNuOffers() {
return nuOffers;
return this.nuOffers;
}
public void setNuOffers(List<NuOffer> nuOffers) {
public void setNuOffers(final List<NuOffer> nuOffers) {
this.nuOffers = nuOffers;
}
public List<SpeedOffer> getSpeedOffers() {
return speedOffers;
return this.speedOffers;
}
public void setSpeedOffers(List<SpeedOffer> speedOffers) {
public void setSpeedOffers(final List<SpeedOffer> speedOffers) {
this.speedOffers = speedOffers;
}
public List<TimeOffer> getTimeOffers() {
return timeOffers;
return this.timeOffers;
}
public void setTimeOffers(List<TimeOffer> timeOffers) {
public void setTimeOffers(final List<TimeOffer> timeOffers) {
this.timeOffers = timeOffers;
}
}
}

View file

@ -1,5 +1,6 @@
package org.springframework.cheapy.model;
public enum Municipio {
sevilla,dos_hermanas,carmona,bollullos,pilas,montellano,mairena_aljarafe,mairena_alcor
Dos_Hermanas, Sevilla
}

View file

@ -4,6 +4,7 @@ package org.springframework.cheapy.repository;
import java.util.List;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.Municipio;
import org.springframework.cheapy.model.StatusOffer;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
@ -34,13 +35,17 @@ public interface FoodOfferRepository extends PagingAndSortingRepository<FoodOffe
@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);
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.name LIKE :name AND foodOffer.status= 'active'")
@Transactional(readOnly = true)
List<FoodOffer> findFoodOfferByClientName(String name);
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.food LIKE :name AND foodOffer.status= 'active'")
@Transactional(readOnly = true)
List<FoodOffer> findFoodOfferByClientFood(String name);
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.municipio =:municipio AND foodOffer.status= 'active'")
@Transactional(readOnly = true)
List<FoodOffer> findFoodOfferByClientPlace(Municipio municipio);
}

View file

@ -2,6 +2,8 @@
package org.springframework.cheapy.repository;
import java.util.List;
import org.springframework.cheapy.model.Municipio;
import org.springframework.cheapy.model.NuOffer;
import org.springframework.cheapy.model.StatusOffer;
import org.springframework.data.domain.Pageable;
@ -31,12 +33,16 @@ public interface NuOfferRepository extends PagingAndSortingRepository<NuOffer, I
@Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.id =:id AND nuOffer.status!= 'inactive'")
@Transactional(readOnly = true)
List<NuOffer> findNuOfferActOclByUserId(@Param("id") Integer id);
@Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.name LIKE :name AND nuOffer.status= 'active'")
@Transactional(readOnly = true)
List<NuOffer> findNuOfferByClientName(String name);
@Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.food LIKE :name AND nuOffer.status= 'active'")
@Transactional(readOnly = true)
List<NuOffer> findNuOfferByClientFood(String name);
@Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.municipio =:municipio AND nuOffer.status= 'active'")
@Transactional(readOnly = true)
List<NuOffer> findNuOfferByClientPlace(Municipio municipio);
}

View file

@ -3,6 +3,7 @@ package org.springframework.cheapy.repository;
import java.util.List;
import org.springframework.cheapy.model.Municipio;
import org.springframework.cheapy.model.SpeedOffer;
import org.springframework.cheapy.model.StatusOffer;
import org.springframework.data.domain.Pageable;
@ -34,12 +35,16 @@ public interface SpeedOfferRepository extends PagingAndSortingRepository<SpeedOf
@Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.id =:id AND speedOffer.status!= 'inactive'")
@Transactional(readOnly = true)
List<SpeedOffer> findSpeedOfferActOclByUserId(@Param("id") Integer id);
@Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.name LIKE :name AND speedOffer.status= 'active'")
@Transactional(readOnly = true)
List<SpeedOffer> findSpeedOfferByClientName(String name);
@Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.food LIKE :name AND speedOffer.status= 'active'")
@Transactional(readOnly = true)
List<SpeedOffer> findSpeedOfferByClientFood(String name);
@Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.municipio =:municipio AND speedOffer.status= 'active'")
@Transactional(readOnly = true)
List<SpeedOffer> findSpeedOfferByClientPlace(Municipio municipio);
}

View file

@ -4,6 +4,7 @@ package org.springframework.cheapy.repository;
import java.util.List;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.Municipio;
import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.model.TimeOffer;
import org.springframework.data.domain.Pageable;
@ -33,12 +34,16 @@ public interface TimeOfferRepository extends PagingAndSortingRepository<FoodOffe
@Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.id =:id AND timeOffer.status!= 'inactive'")
@Transactional(readOnly = true)
List<TimeOffer> findTimeOfferActOclByUserId(@Param("id") Integer id);
@Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.name LIKE :name AND timeOffer.status= 'active'")
@Transactional(readOnly = true)
List<TimeOffer> findTimeOfferByClientName(String name);
@Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.food LIKE :name AND timeOffer.status= 'active'")
@Transactional(readOnly = true)
List<TimeOffer> findTimeOfferByClientFood(String name);
@Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.municipio =:municipio AND timeOffer.status= 'active'")
@Transactional(readOnly = true)
List<TimeOffer> findTimeOfferByClientPlace(Municipio municipio);
}

View file

@ -5,6 +5,7 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.Municipio;
import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.repository.FoodOfferRepository;
import org.springframework.dao.DataAccessException;
@ -45,14 +46,18 @@ public class FoodOfferService {
public List<FoodOffer> findFoodOfferActOclByUserId(final int id) {
return this.foodOfferRepository.findFoodOfferActOclByUserId(id);
}
public List<FoodOffer> findFoodOfferByClientName(String name) {
String nameEdit = "%"+name+"%";
public List<FoodOffer> findFoodOfferByClientName(final String name) {
String nameEdit = "%" + name + "%";
return this.foodOfferRepository.findFoodOfferByClientName(nameEdit);
}
public List<FoodOffer> findFoodOfferByClientFood(String name) {
String nameEdit = "%"+name+"%";
public List<FoodOffer> findFoodOfferByClientFood(final String name) {
String nameEdit = "%" + name + "%";
return this.foodOfferRepository.findFoodOfferByClientFood(nameEdit);
}
public List<FoodOffer> findFoodOfferByClientPlace(final Municipio municip) {
return this.foodOfferRepository.findFoodOfferByClientPlace(municip);
}
}

View file

@ -4,6 +4,7 @@ package org.springframework.cheapy.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cheapy.model.Municipio;
import org.springframework.cheapy.model.NuOffer;
import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.repository.NuOfferRepository;
@ -54,14 +55,18 @@ public class NuOfferService {
public List<NuOffer> findNuOfferActOclByUserId(final int id) {
return this.nuOfferRepository.findNuOfferActOclByUserId(id);
}
public List<NuOffer> findNuOfferByClientName(String name) {
String nameEdit = "%"+name+"%";
public List<NuOffer> findNuOfferByClientName(final String name) {
String nameEdit = "%" + name + "%";
return this.nuOfferRepository.findNuOfferByClientName(nameEdit);
}
public List<NuOffer> findNuOfferByClientFood(String name) {
String nameEdit = "%"+name+"%";
public List<NuOffer> findNuOfferByClientFood(final String name) {
String nameEdit = "%" + name + "%";
return this.nuOfferRepository.findNuOfferByClientFood(nameEdit);
}
public List<NuOffer> findNuOfferByClientPlace(final Municipio mun) {
return this.nuOfferRepository.findNuOfferByClientPlace(mun);
}
}

View file

@ -4,6 +4,7 @@ package org.springframework.cheapy.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cheapy.model.Municipio;
import org.springframework.cheapy.model.SpeedOffer;
import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.repository.SpeedOfferRepository;
@ -49,14 +50,18 @@ public class SpeedOfferService {
public List<SpeedOffer> findSpeedOfferActOclByUserId(final int id) {
return this.speedOfferRepository.findSpeedOfferActOclByUserId(id);
}
public List<SpeedOffer> findSpeedOfferByClientName(String name) {
String nameEdit = "%"+name+"%";
public List<SpeedOffer> findSpeedOfferByClientName(final String name) {
String nameEdit = "%" + name + "%";
return this.speedOfferRepository.findSpeedOfferByClientName(nameEdit);
}
public List<SpeedOffer> findSpeedOfferByClientFood(String name) {
String nameEdit = "%"+name+"%";
public List<SpeedOffer> findSpeedOfferByClientFood(final String name) {
String nameEdit = "%" + name + "%";
return this.speedOfferRepository.findSpeedOfferByClientFood(nameEdit);
}
public List<SpeedOffer> findSpeedOfferByClientPlace(final Municipio mun) {
return this.speedOfferRepository.findSpeedOfferByClientPlace(mun);
}
}

View file

@ -4,6 +4,7 @@ package org.springframework.cheapy.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cheapy.model.Municipio;
import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.model.TimeOffer;
import org.springframework.cheapy.repository.TimeOfferRepository;
@ -45,14 +46,18 @@ public class TimeOfferService {
public List<TimeOffer> findTimeOfferActOclByUserId(final int id) {
return this.timeOfferRepository.findTimeOfferActOclByUserId(id);
}
public List<TimeOffer> findTimeOfferByClientName(String name) {
String nameEdit = "%"+name+"%";
public List<TimeOffer> findTimeOfferByClientName(final String name) {
String nameEdit = "%" + name + "%";
return this.timeOfferRepository.findTimeOfferByClientName(nameEdit);
}
public List<TimeOffer> findTimeOfferByClientFood(String name) {
String nameEdit = "%"+name+"%";
public List<TimeOffer> findTimeOfferByClientFood(final String name) {
String nameEdit = "%" + name + "%";
return this.timeOfferRepository.findTimeOfferByClientFood(nameEdit);
}
public List<TimeOffer> findTimeOfferByClientPlace(final Municipio mun) {
return this.timeOfferRepository.findTimeOfferByClientPlace(mun);
}
}

View file

@ -7,7 +7,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.Municipio;
import org.springframework.cheapy.model.NuOffer;
import org.springframework.cheapy.model.Offer;
import org.springframework.cheapy.model.SpeedOffer;
@ -55,15 +58,18 @@ public class OfertaController {
model.put("speedOfferLs", speedOfferLs);
model.put("timeOfferLs", timeOfferLs);
// Añade la lista de municipios al desplegable
model.put("municipios", Municipio.values());
//Se añade formateador de fecha al modelo
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/offersList";
}
@GetMapping("/offersByName")
public String processFindFormByName(final Map<String, Object> model, String name) {
public String processFindFormByName(final Map<String, Object> model, final String name) {
List<FoodOffer> foodOfferLs = this.foodOfferService.findFoodOfferByClientName(name);
List<NuOffer> nuOfferLs = this.nuOfferService.findNuOfferByClientName(name);
@ -74,15 +80,18 @@ public class OfertaController {
model.put("speedOfferLs", speedOfferLs);
model.put("timeOfferLs", timeOfferLs);
// Añade la lista de municipios al desplegable
model.put("municipios", Municipio.values());
//Se añade formateador de fecha al modelo
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/offersListSearch";
}
@GetMapping("/offersByFood")
public String processFindFormByFood(final Map<String, Object> model, String name) {
public String processFindFormByFood(final Map<String, Object> model, final String name) {
List<FoodOffer> foodOfferLs = this.foodOfferService.findFoodOfferByClientFood(name);
List<NuOffer> nuOfferLs = this.nuOfferService.findNuOfferByClientFood(name);
@ -93,6 +102,32 @@ public class OfertaController {
model.put("speedOfferLs", speedOfferLs);
model.put("timeOfferLs", timeOfferLs);
// Añade la lista de municipios al desplegable
model.put("municipios", Municipio.values());
//Se añade formateador de fecha al modelo
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/offersListSearch";
}
@GetMapping("/offersByPlace")
public String processFindFormByPlace(final Map<String, Object> model, final HttpServletRequest request) {
Municipio mun = Municipio.valueOf(request.getParameter("municipio"));
List<FoodOffer> foodOfferLs = this.foodOfferService.findFoodOfferByClientPlace(mun);
List<NuOffer> nuOfferLs = this.nuOfferService.findNuOfferByClientPlace(mun);
List<SpeedOffer> speedOfferLs = this.speedOfferService.findSpeedOfferByClientPlace(mun);
List<TimeOffer> timeOfferLs = this.timeOfferService.findTimeOfferByClientPlace(mun);
model.put("foodOfferLs", foodOfferLs);
model.put("nuOfferLs", nuOfferLs);
model.put("speedOfferLs", speedOfferLs);
model.put("timeOfferLs", timeOfferLs);
// Añade la lista de municipios al desplegable
model.put("municipios", Municipio.values());
//Se añade formateador de fecha al modelo
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));

View file

@ -24,8 +24,8 @@ INSERT INTO codes (id,code,activo) VALUES (2,'code2',FALSE);
INSERT INTO codes (id,code,activo) VALUES (3,'code3',TRUE);
INSERT INTO codes (id,code,activo) VALUES (4,'code4',TRUE);
INSERT INTO clients (id, name, email, address, municipio, init, finish, telephone, description, food, username, code) VALUES (1,'bar manoli','manoli@gmail.com','C/Betis', 'sevilla','10:00','22:00','608726190', 'description 1', 'ESPAÑOLA','manoli', 'code1');
INSERT INTO clients (id, name, email, address, municipio, init, finish, telephone, description, food, username, code) VALUES (2,'bar david','david@gmail.com','C/Sevilla', 'dos_hermanas','09:30','22:00','608726190', 'description 2', 'americana','david', 'code2');
INSERT INTO clients (id, name, email, address, municipio, init, finish, telephone, description, code, food, username) VALUES (1,'bar manoli','manoli@gmail.com','C/Betis', 'Sevilla','10:00:00','22:00:00','608726190', 'description 1', 'code1', 'ESPAÑOLA','manoli');
INSERT INTO clients (id, name, email, address, municipio, init, finish, telephone, description, code, food, username) VALUES (2,'bar david','david@gmail.com', 'C/Sevilla', 'Dos_Hermanas','09:30:00','22:00:00','608726190', 'description 2', 'code2', 'americana','david');
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);

View file

@ -65,6 +65,15 @@
</div>
</form>
<form class="example" action="/offersByPlace">
<select name="municipio">
<option value="">Escoge municipio</option>
<c:forEach items="${municipios}" var="entry">
<option value="${entry}">${entry}</option>
</c:forEach>
</select>
<button type="submit">Buscar por municipio</button>
</form>
<h2 style="text-align:center;padding:5px"><fmt:message key="foodOffers"/></h2>
@ -83,6 +92,7 @@
<th><fmt:message key="discount"/></th>
<th><fmt:message key="startDate"/></th>
<th><fmt:message key="endDate"/></th>
<th><fmt:message key="municipio"/></th>
<th> </th>
</tr>
@ -105,6 +115,9 @@
<td>
<c:out value="${localDateTimeFormat.format(foodOffer.end)}"/>
</td>
<td>
<c:out value="${foodOffer.client.municipio}"/>
</td>
<td>
<spring:url value="/offers/food/{foodOfferId}" var="foodOfferUrl">