Filtro municipios sin select acabado

This commit is contained in:
gabgutpri@alum.us.es 2021-04-12 20:05:21 +02:00
parent 3d6923f9c6
commit b54203910a
7 changed files with 131 additions and 62 deletions

View file

@ -1,3 +1,4 @@
package org.springframework.cheapy.model; package org.springframework.cheapy.model;
import java.time.LocalTime; import java.time.LocalTime;
@ -5,6 +6,8 @@ import java.util.List;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
@ -19,170 +22,183 @@ import org.springframework.format.annotation.DateTimeFormat;
@Table(name = "clients") @Table(name = "clients")
public class Client extends BaseEntity { 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, // (id, name, email, address, init, finish, telephone, description, code, food,
// usuar) // usuar)
@NotEmpty @NotEmpty
private String name; private String name;
@NotEmpty @NotEmpty
private String email; private String email;
@NotEmpty @NotEmpty
private String address; private String address;
@NotNull
@Enumerated(value = EnumType.STRING)
private Municipio municipio;
// Hora de apertura del local // Hora de apertura del local
@DateTimeFormat(pattern = "HH:mm") @DateTimeFormat(pattern = "HH:mm")
@NotNull(message = "Debe introducir una hora de apertura") @NotNull(message = "Debe introducir una hora de apertura")
private LocalTime init; private LocalTime init;
// Hora de cierre del local // Hora de cierre del local
@DateTimeFormat(pattern = "HH:mm") @DateTimeFormat(pattern = "HH:mm")
@NotNull(message = "Debe introducir una hora de cierre") @NotNull(message = "Debe introducir una hora de cierre")
private LocalTime finish; private LocalTime finish;
@NotEmpty @NotEmpty
@Digits(fraction = 0, integer = 10) @Digits(fraction = 0, integer = 10)
private String telephone; private String telephone;
@NotEmpty @NotEmpty
private String description; private String description;
// Codigo de activacion de cuenta // Codigo de activacion de cuenta
@NotEmpty @NotEmpty
private String code; private String code;
@NotEmpty @NotEmpty
private String food; private String food;
@OneToOne(cascade = CascadeType.ALL) @OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "username", referencedColumnName = "username") @JoinColumn(name = "username", referencedColumnName = "username")
private User usuar; private User usuar;
@OneToMany @OneToMany
private List<FoodOffer> foodOffers; private List<FoodOffer> foodOffers;
@OneToMany @OneToMany
private List<NuOffer> nuOffers; private List<NuOffer> nuOffers;
@OneToMany @OneToMany
private List<SpeedOffer> speedOffers; private List<SpeedOffer> speedOffers;
@OneToMany @OneToMany
private List<TimeOffer> timeOffers; private List<TimeOffer> timeOffers;
public String getName() { public String getName() {
return name; return this.name;
} }
public void setName(String name) { public void setName(final String name) {
this.name = name; this.name = name;
} }
public String getEmail() { public String getEmail() {
return email; return this.email;
} }
public void setEmail(String email) { public void setEmail(final String email) {
this.email = email; this.email = email;
} }
public String getAddress() { public String getAddress() {
return address; return this.address;
} }
public void setAddress(String address) { public void setAddress(final String address) {
this.address = address; this.address = address;
} }
public LocalTime getInit() { public Municipio getMunicipio() {
return init; 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; this.init = init;
} }
public LocalTime getFinish() { public LocalTime getFinish() {
return finish; return this.finish;
} }
public void setFinish(LocalTime finish) { public void setFinish(final LocalTime finish) {
this.finish = finish; this.finish = finish;
} }
public String getTelephone() { public String getTelephone() {
return telephone; return this.telephone;
} }
public void setTelephone(String telephone) { public void setTelephone(final String telephone) {
this.telephone = telephone; this.telephone = telephone;
} }
public String getDescription() { public String getDescription() {
return description; return this.description;
} }
public void setDescription(String description) { public void setDescription(final String description) {
this.description = description; this.description = description;
} }
public String getCode() { public String getCode() {
return code; return this.code;
} }
public void setCode(String code) { public void setCode(final String code) {
this.code = code; this.code = code;
} }
public String getFood() { public String getFood() {
return food; return this.food;
} }
public void setFood(String food) { public void setFood(final String food) {
this.food = food; this.food = food;
} }
public User getUsuar() { public User getUsuar() {
return usuar; return this.usuar;
} }
public void setUsuar(User usuar) { public void setUsuar(final User usuar) {
this.usuar = usuar; this.usuar = usuar;
} }
public List<FoodOffer> getFoodOffers() { 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; this.foodOffers = foodOffers;
} }
public List<NuOffer> getNuOffers() { 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; this.nuOffers = nuOffers;
} }
public List<SpeedOffer> getSpeedOffers() { 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; this.speedOffers = speedOffers;
} }
public List<TimeOffer> getTimeOffers() { 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; this.timeOffers = timeOffers;
} }
} }

View file

@ -0,0 +1,7 @@
package org.springframework.cheapy.model;
public enum Municipio {
Dos_Hermanas, Sevilla
}

View file

@ -34,13 +34,17 @@ public interface FoodOfferRepository extends PagingAndSortingRepository<FoodOffe
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.id =:id AND foodOffer.status!= 'inactive'") @Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.id =:id AND foodOffer.status!= 'inactive'")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<FoodOffer> findFoodOfferActOclByUserId(@Param("id") Integer id); List<FoodOffer> findFoodOfferActOclByUserId(@Param("id") Integer id);
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.name LIKE :name AND foodOffer.status= 'active'") @Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.name LIKE :name AND foodOffer.status= 'active'")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<FoodOffer> findFoodOfferByClientName(String name); List<FoodOffer> findFoodOfferByClientName(String name);
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.food LIKE :name AND foodOffer.status= 'active'") @Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.food LIKE :name AND foodOffer.status= 'active'")
@Transactional(readOnly = true) @Transactional(readOnly = true)
List<FoodOffer> findFoodOfferByClientFood(String name); List<FoodOffer> findFoodOfferByClientFood(String name);
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.municipio =:municip AND foodOffer.status= 'active'")
@Transactional(readOnly = true)
List<FoodOffer> findFoodOfferByClientPlace(String municip);
} }

View file

@ -45,14 +45,18 @@ public class FoodOfferService {
public List<FoodOffer> findFoodOfferActOclByUserId(final int id) { public List<FoodOffer> findFoodOfferActOclByUserId(final int id) {
return this.foodOfferRepository.findFoodOfferActOclByUserId(id); return this.foodOfferRepository.findFoodOfferActOclByUserId(id);
} }
public List<FoodOffer> findFoodOfferByClientName(String name) { public List<FoodOffer> findFoodOfferByClientName(final String name) {
String nameEdit = "%"+name+"%"; String nameEdit = "%" + name + "%";
return this.foodOfferRepository.findFoodOfferByClientName(nameEdit); return this.foodOfferRepository.findFoodOfferByClientName(nameEdit);
} }
public List<FoodOffer> findFoodOfferByClientFood(String name) { public List<FoodOffer> findFoodOfferByClientFood(final String name) {
String nameEdit = "%"+name+"%"; String nameEdit = "%" + name + "%";
return this.foodOfferRepository.findFoodOfferByClientFood(nameEdit); return this.foodOfferRepository.findFoodOfferByClientFood(nameEdit);
} }
public List<FoodOffer> findFoodOfferByClientPlace(final String municip) {
return this.foodOfferRepository.findFoodOfferByClientPlace(municip);
}
} }

View file

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.Municipio;
import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.NuOffer;
import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.SpeedOffer;
import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.model.TimeOffer;
@ -52,15 +53,18 @@ public class OfertaController {
model.put("speedOfferLs", speedOfferLs); model.put("speedOfferLs", speedOfferLs);
model.put("timeOfferLs", timeOfferLs); 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 //Se añade formateador de fecha al modelo
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/offersList"; return "offers/offersList";
} }
@GetMapping("/offersByName") @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<FoodOffer> foodOfferLs = this.foodOfferService.findFoodOfferByClientName(name);
List<NuOffer> nuOfferLs = this.nuOfferService.findNuOfferByClientName(name); List<NuOffer> nuOfferLs = this.nuOfferService.findNuOfferByClientName(name);
@ -71,15 +75,18 @@ public class OfertaController {
model.put("speedOfferLs", speedOfferLs); model.put("speedOfferLs", speedOfferLs);
model.put("timeOfferLs", timeOfferLs); 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 //Se añade formateador de fecha al modelo
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/offersListSearch"; return "offers/offersListSearch";
} }
@GetMapping("/offersByFood") @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<FoodOffer> foodOfferLs = this.foodOfferService.findFoodOfferByClientFood(name);
List<NuOffer> nuOfferLs = this.nuOfferService.findNuOfferByClientFood(name); List<NuOffer> nuOfferLs = this.nuOfferService.findNuOfferByClientFood(name);
@ -90,6 +97,25 @@ public class OfertaController {
model.put("speedOfferLs", speedOfferLs); model.put("speedOfferLs", speedOfferLs);
model.put("timeOfferLs", timeOfferLs); 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 String municip) {
List<FoodOffer> foodOfferLs = this.foodOfferService.findFoodOfferByClientPlace(municip);
model.put("foodOfferLs", foodOfferLs);
// Añade la lista de municipios al desplegable
model.put("municipios", Municipio.values());
//Se añade formateador de fecha al modelo //Se añade formateador de fecha al modelo
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));

View file

@ -19,8 +19,8 @@ INSERT INTO usuarios (id, nombre, apellidos, dni, direccion, telefono, email, us
INSERT INTO usuarios (id, nombre, apellidos, dni, direccion, telefono, email, username) VALUES (3, 'Lolo', 'Lopez', '25486596L', 'C/Macarena', '690670547' ,'Lolo@gmail.com','lolo'); INSERT INTO usuarios (id, nombre, apellidos, dni, direccion, telefono, email, username) VALUES (3, 'Lolo', 'Lopez', '25486596L', 'C/Macarena', '690670547' ,'Lolo@gmail.com','lolo');
INSERT INTO usuarios (id, nombre, apellidos, dni, direccion, telefono, email, username) VALUES (4, 'Pepe', 'Lopez', '12456776V', 'C/Macarena', '690670547', 'Pepe@gmail.com','pepe'); INSERT INTO usuarios (id, nombre, apellidos, dni, direccion, telefono, email, username) VALUES (4, 'Pepe', 'Lopez', '12456776V', 'C/Macarena', '690670547', 'Pepe@gmail.com','pepe');
INSERT INTO clients (id, name, email, address, init, finish, telephone, description, code, food, username) VALUES (1,'bar manoli','manoli@gmail.com','C/Betis','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 (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, init, finish, telephone, description, code, food, username) VALUES (2,'bar david','david@gmail.com','C/Sevilla','09:30:00','22:00:00','608726190', 'description 2', 'code2', 'americana','david'); 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); 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-2', 'active', 1, 'macarrones con tomate', 10);

View file

@ -41,12 +41,20 @@
<form class="example" action="/offersByName"> <form class="example" action="/offersByName">
<input type="text" name="name"> <input type="text" name="name">
<button type="submit"><i class="fa fa-search"></i></button> <button type="submit">Buscar por nombre</button>
</form> </form>
<form class="example" action="/offersByFood"> <form class="example" action="/offersByFood">
<input type="text" name="name"> <input type="text" name="name">
<button type="submit"><i class="fa fa-search"></i></button> <button type="submit">Buscar por comida</button>
</form>
<form class="example" action="/offersByPlace">
<select name="municipios">
<option value="" label="Chose Type" />
<options value="${municipios}"/>
<select>
<button type="submit">Buscar por municipio</button>
</form> </form>
@ -67,6 +75,7 @@
<th><fmt:message key="discount"/></th> <th><fmt:message key="discount"/></th>
<th><fmt:message key="startDate"/></th> <th><fmt:message key="startDate"/></th>
<th><fmt:message key="endDate"/></th> <th><fmt:message key="endDate"/></th>
<th><fmt:message key="municipio"/></th>
<th> </th> <th> </th>
</tr> </tr>
@ -89,6 +98,9 @@
<td> <td>
<c:out value="${localDateTimeFormat.format(foodOffer.end)}"/> <c:out value="${localDateTimeFormat.format(foodOffer.end)}"/>
</td> </td>
<td>
<c:out value="${foodOffer.client.municipio}"/>
</td>
<td> <td>
<spring:url value="/offers/food/{foodOfferId}" var="foodOfferUrl"> <spring:url value="/offers/food/{foodOfferId}" var="foodOfferUrl">