mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 15:55:49 +00:00
Filtro municipios sin select acabado
This commit is contained in:
parent
3d6923f9c6
commit
b54203910a
7 changed files with 131 additions and 62 deletions
|
@ -1,3 +1,4 @@
|
|||
|
||||
package org.springframework.cheapy.model;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
@ -5,6 +6,8 @@ import java.util.List;
|
|||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
|
@ -19,170 +22,183 @@ 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;
|
||||
private String address;
|
||||
|
||||
@NotNull
|
||||
@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;
|
||||
private String description;
|
||||
|
||||
// Codigo de activacion de cuenta
|
||||
@NotEmpty
|
||||
private String code;
|
||||
private String code;
|
||||
|
||||
@NotEmpty
|
||||
private String food;
|
||||
private String food;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "username", referencedColumnName = "username")
|
||||
private User usuar;
|
||||
private User usuar;
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
public void setCode(final String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
package org.springframework.cheapy.model;
|
||||
|
||||
public enum Municipio {
|
||||
Dos_Hermanas, Sevilla
|
||||
|
||||
}
|
|
@ -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'")
|
||||
@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 =:municip AND foodOffer.status= 'active'")
|
||||
@Transactional(readOnly = true)
|
||||
List<FoodOffer> findFoodOfferByClientPlace(String municip);
|
||||
|
||||
}
|
||||
|
|
|
@ -45,14 +45,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 String municip) {
|
||||
return this.foodOfferRepository.findFoodOfferByClientPlace(municip);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.springframework.cheapy.model.FoodOffer;
|
||||
import org.springframework.cheapy.model.Municipio;
|
||||
import org.springframework.cheapy.model.NuOffer;
|
||||
import org.springframework.cheapy.model.SpeedOffer;
|
||||
import org.springframework.cheapy.model.TimeOffer;
|
||||
|
@ -52,15 +53,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);
|
||||
|
@ -71,15 +75,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);
|
||||
|
@ -90,6 +97,25 @@ 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 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
|
||||
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
|
||||
|
||||
|
|
|
@ -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 (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, 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 (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);
|
||||
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);
|
||||
|
|
|
@ -41,12 +41,20 @@
|
|||
|
||||
<form class="example" action="/offersByName">
|
||||
<input type="text" name="name">
|
||||
<button type="submit"><i class="fa fa-search"></i></button>
|
||||
<button type="submit">Buscar por nombre</button>
|
||||
</form>
|
||||
|
||||
<form class="example" action="/offersByFood">
|
||||
<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>
|
||||
|
||||
|
||||
|
@ -67,6 +75,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>
|
||||
|
@ -89,6 +98,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">
|
||||
|
|
Loading…
Reference in a new issue