mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 07:45:49 +00:00
Merge pull request #46 from cheapy-ispp/develop
Actualización de la rama
This commit is contained in:
commit
f10dce2e76
64 changed files with 1954 additions and 830 deletions
5
pom.xml
5
pom.xml
|
@ -69,6 +69,11 @@
|
|||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-taglibs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
|
|
|
@ -36,20 +36,20 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||
.antMatchers(HttpMethod.GET, "/", "/oups").permitAll()
|
||||
.antMatchers("/users/new").permitAll()
|
||||
|
||||
.antMatchers("/nuOffers/**").hasAnyAuthority("admin","client")
|
||||
.antMatchers("/timeOffers/**").hasAnyAuthority("admin","client")
|
||||
|
||||
.antMatchers("/login/**").anonymous()
|
||||
.antMatchers("/logout").permitAll()
|
||||
|
||||
.antMatchers("/usuarios/new").permitAll()
|
||||
.antMatchers("/admin/**").hasAnyAuthority("admin")
|
||||
.antMatchers("/speedOffers/**").hasAnyAuthority("admin", "client")
|
||||
.antMatchers("/foodOffers/**").hasAnyAuthority("admin", "client")
|
||||
|
||||
.antMatchers("/owners/**").hasAnyAuthority("owner", "admin")
|
||||
|
||||
.antMatchers("/offers/**/new").hasAnyAuthority("admin", "client")
|
||||
.antMatchers("/offers/**/activate").hasAnyAuthority("admin","client")
|
||||
|
||||
.antMatchers("/clients/new").permitAll()
|
||||
.antMatchers("/offers/**").hasAnyAuthority("admin")
|
||||
.antMatchers("/offers/**").permitAll()
|
||||
|
||||
|
||||
.and().formLogin()
|
||||
.loginPage("/login").permitAll()
|
||||
|
|
|
@ -1,18 +1,3 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cheapy.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -22,16 +7,14 @@ import javax.persistence.GenerationType;
|
|||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object with an id property. Used as a base class for objects
|
||||
* needing this property.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class BaseEntity implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.springframework.cheapy.model;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
|
@ -13,31 +13,31 @@ import javax.validation.constraints.Digits;
|
|||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
@Entity
|
||||
@Table(name = "clients")
|
||||
public class Client extends BaseEntity{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Client extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// (id, email, address, init, finish, telephone, description, code, food, usuar)
|
||||
// (id, name, email, address, init, finish, telephone, description, code, food,
|
||||
// usuar)
|
||||
|
||||
@NotEmpty
|
||||
private String name;
|
||||
|
||||
@NotEmpty
|
||||
private String email;
|
||||
|
||||
|
||||
@NotEmpty
|
||||
private String address;
|
||||
|
||||
//@DateTimeFormat(pattern = "HH:mm")
|
||||
@NotBlank
|
||||
private String init;
|
||||
// Hora de apertura del local
|
||||
@NotBlank
|
||||
private String init;
|
||||
|
||||
//@DateTimeFormat(pattern = "HH:mm")
|
||||
@NotBlank
|
||||
private String finish;
|
||||
// Hora de cierre del local
|
||||
@NotBlank
|
||||
private String finish;
|
||||
|
||||
@NotEmpty
|
||||
@Digits(fraction = 0, integer = 10)
|
||||
|
@ -46,38 +46,45 @@ public class Client extends BaseEntity{
|
|||
@NotEmpty
|
||||
private String description;
|
||||
|
||||
// Codigo de activacion de cuenta
|
||||
@NotEmpty
|
||||
private String code;
|
||||
|
||||
@NotEmpty
|
||||
private String food;
|
||||
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "username", referencedColumnName = "username")
|
||||
private User usuar;
|
||||
|
||||
|
||||
@OneToMany
|
||||
private Set<FoodOffer> foodOffers;
|
||||
|
||||
private List<FoodOffer> foodOffers;
|
||||
|
||||
@OneToMany
|
||||
private Set<NuOffer> nuOffers;
|
||||
|
||||
private List<NuOffer> nuOffers;
|
||||
|
||||
@OneToMany
|
||||
private Set<SpeedOffer> speedOffers;
|
||||
|
||||
private List<SpeedOffer> speedOffers;
|
||||
|
||||
@OneToMany
|
||||
private Set<TimeOffer> timeOffers;
|
||||
|
||||
|
||||
|
||||
private List<TimeOffer> timeOffers;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
@ -86,7 +93,6 @@ public class Client extends BaseEntity{
|
|||
this.address = address;
|
||||
}
|
||||
|
||||
|
||||
public String getInit() {
|
||||
return init;
|
||||
}
|
||||
|
@ -103,14 +109,6 @@ public class Client extends BaseEntity{
|
|||
this.finish = finish;
|
||||
}
|
||||
|
||||
public User getUsername() {
|
||||
return usuar;
|
||||
}
|
||||
|
||||
public void setUsername(User username) {
|
||||
this.usuar = username;
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
return telephone;
|
||||
}
|
||||
|
@ -143,35 +141,43 @@ public class Client extends BaseEntity{
|
|||
this.food = food;
|
||||
}
|
||||
|
||||
public Set<FoodOffer> getFoodOffers() {
|
||||
public User getUsuar() {
|
||||
return usuar;
|
||||
}
|
||||
|
||||
public void setUsuar(User usuar) {
|
||||
this.usuar = usuar;
|
||||
}
|
||||
|
||||
public List<FoodOffer> getFoodOffers() {
|
||||
return foodOffers;
|
||||
}
|
||||
|
||||
public void setFoodOffers(Set<FoodOffer> foodOffers) {
|
||||
public void setFoodOffers(List<FoodOffer> foodOffers) {
|
||||
this.foodOffers = foodOffers;
|
||||
}
|
||||
|
||||
public Set<NuOffer> getNuOffers() {
|
||||
public List<NuOffer> getNuOffers() {
|
||||
return nuOffers;
|
||||
}
|
||||
|
||||
public void setNuOffers(Set<NuOffer> nuOffers) {
|
||||
public void setNuOffers(List<NuOffer> nuOffers) {
|
||||
this.nuOffers = nuOffers;
|
||||
}
|
||||
|
||||
public Set<SpeedOffer> getSpeedOffers() {
|
||||
public List<SpeedOffer> getSpeedOffers() {
|
||||
return speedOffers;
|
||||
}
|
||||
|
||||
public void setSpeedOffers(Set<SpeedOffer> speedOffers) {
|
||||
public void setSpeedOffers(List<SpeedOffer> speedOffers) {
|
||||
this.speedOffers = speedOffers;
|
||||
}
|
||||
|
||||
public Set<TimeOffer> getTimeOffers() {
|
||||
public List<TimeOffer> getTimeOffers() {
|
||||
return timeOffers;
|
||||
}
|
||||
|
||||
public void setTimeOffers(Set<TimeOffer> timeOffers) {
|
||||
public void setTimeOffers(List<TimeOffer> timeOffers) {
|
||||
this.timeOffers = timeOffers;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,21 +17,23 @@ package org.springframework.cheapy.model;
|
|||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "food_offers")
|
||||
public class FoodOffer extends Offer {
|
||||
//Plato específico
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
//Plato específico
|
||||
@NotBlank
|
||||
private String food;
|
||||
|
||||
@NotBlank
|
||||
private String discount;
|
||||
|
||||
@NotNull
|
||||
private Integer units; // revisar
|
||||
@Min(0)
|
||||
private Integer discount;
|
||||
|
||||
public String getFood() {
|
||||
return food;
|
||||
|
@ -41,20 +43,12 @@ public class FoodOffer extends Offer {
|
|||
this.food = food;
|
||||
}
|
||||
|
||||
public String getDiscount() {
|
||||
public Integer getDiscount() {
|
||||
return discount;
|
||||
}
|
||||
|
||||
public void setDiscount(String discount) {
|
||||
public void setDiscount(Integer discount) {
|
||||
this.discount = discount;
|
||||
}
|
||||
|
||||
public Integer getUnits() {
|
||||
return units;
|
||||
}
|
||||
|
||||
public void setUnits(Integer units) {
|
||||
this.units = units;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,33 +1,16 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cheapy.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object adds a name property to <code>BaseEntity</code>. Used as
|
||||
* a base class for objects needing these properties.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class NamedEntity extends BaseEntity {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
|
|
|
@ -3,33 +3,42 @@ package org.springframework.cheapy.model;
|
|||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "nu_offers")
|
||||
public class NuOffer extends Offer {
|
||||
|
||||
//Oferta por numero de comensales
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
private Integer gold;
|
||||
@Min(1)
|
||||
private Integer gold;
|
||||
|
||||
@Column(name = "discount_gold")
|
||||
@NotBlank
|
||||
private String discountGold;
|
||||
@NotNull
|
||||
@Min(0)
|
||||
private Integer discountGold;
|
||||
|
||||
@NotNull
|
||||
private Integer silver;
|
||||
@Min(1)
|
||||
private Integer silver;
|
||||
|
||||
@Column(name = "discount_silver")
|
||||
@NotBlank
|
||||
private String discountSilver;
|
||||
@NotNull
|
||||
@Min(0)
|
||||
private Integer discountSilver;
|
||||
|
||||
@NotNull
|
||||
private Integer bronze;
|
||||
@Min(1)
|
||||
private Integer bronze;
|
||||
|
||||
@Column(name = "discount_bronze")
|
||||
@NotBlank
|
||||
private String discountBronze;
|
||||
@NotNull
|
||||
@Min(0)
|
||||
private Integer discountBronze;
|
||||
|
||||
public Integer getGold() {
|
||||
return gold;
|
||||
|
@ -39,11 +48,11 @@ public class NuOffer extends Offer {
|
|||
this.gold = gold;
|
||||
}
|
||||
|
||||
public String getDiscountGold() {
|
||||
public Integer getDiscountGold() {
|
||||
return discountGold;
|
||||
}
|
||||
|
||||
public void setDiscountGold(String discountGold) {
|
||||
public void setDiscountGold(Integer discountGold) {
|
||||
this.discountGold = discountGold;
|
||||
}
|
||||
|
||||
|
@ -55,11 +64,11 @@ public class NuOffer extends Offer {
|
|||
this.silver = silver;
|
||||
}
|
||||
|
||||
public String getDiscountSilver() {
|
||||
public Integer getDiscountSilver() {
|
||||
return discountSilver;
|
||||
}
|
||||
|
||||
public void setDiscountSilver(String discountSilver) {
|
||||
public void setDiscountSilver(Integer discountSilver) {
|
||||
this.discountSilver = discountSilver;
|
||||
}
|
||||
|
||||
|
@ -71,12 +80,12 @@ public class NuOffer extends Offer {
|
|||
this.bronze = bronze;
|
||||
}
|
||||
|
||||
public String getDiscountBronze() {
|
||||
public Integer getDiscountBronze() {
|
||||
return discountBronze;
|
||||
}
|
||||
|
||||
public void setDiscountBronze(String discountBronze) {
|
||||
public void setDiscountBronze(Integer discountBronze) {
|
||||
this.discountBronze = discountBronze;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,11 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|||
|
||||
@MappedSuperclass
|
||||
public class Offer extends BaseEntity {
|
||||
//Clase padre
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// Clase padre
|
||||
|
||||
@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
|
||||
@NotNull
|
||||
@Future
|
||||
|
@ -40,15 +44,13 @@ public class Offer extends BaseEntity {
|
|||
@Future
|
||||
private LocalDateTime end;
|
||||
|
||||
|
||||
private String code;
|
||||
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
private StatusOffer type;
|
||||
|
||||
|
||||
private StatusOffer status;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="client_id")
|
||||
@JoinColumn(name = "client_id")
|
||||
private Client client;
|
||||
|
||||
public LocalDateTime getStart() {
|
||||
|
@ -75,14 +77,14 @@ public class Offer extends BaseEntity {
|
|||
this.code = code;
|
||||
}
|
||||
|
||||
public StatusOffer getType() {
|
||||
return type;
|
||||
public StatusOffer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setType(StatusOffer type) {
|
||||
this.type = type;
|
||||
public void setStatus(StatusOffer type) {
|
||||
this.status = type;
|
||||
}
|
||||
|
||||
|
||||
public Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
|
|
@ -1,50 +1,22 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cheapy.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Digits;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object representing an owner.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "owners")
|
||||
public class Owner extends Person {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name = "address")
|
||||
@NotEmpty
|
||||
private String address;
|
||||
|
|
|
@ -1,32 +1,17 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cheapy.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object representing an person.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class Person extends BaseEntity {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name = "first_name")
|
||||
@NotEmpty
|
||||
private String firstName;
|
||||
|
|
|
@ -3,34 +3,42 @@ package org.springframework.cheapy.model;
|
|||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "speed_offers")
|
||||
public class SpeedOffer extends Offer {
|
||||
|
||||
// Ofertar por rapidez comiendo
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
private Integer gold; // x minutos
|
||||
@Min(0)
|
||||
private Integer gold;
|
||||
|
||||
@Column(name = "discount_gold")
|
||||
@NotBlank
|
||||
private String discountGold;
|
||||
@NotNull
|
||||
@Min(0)
|
||||
private Integer discountGold;
|
||||
|
||||
@NotNull
|
||||
@Min(0)
|
||||
private Integer silver;
|
||||
|
||||
@Column(name = "discount_silver")
|
||||
@NotBlank
|
||||
private String discountSilver;
|
||||
@NotNull
|
||||
@Min(0)
|
||||
private Integer discountSilver;
|
||||
|
||||
@NotNull
|
||||
@Min(0)
|
||||
private Integer bronze;
|
||||
|
||||
@Column(name = "discount_bronze")
|
||||
@NotBlank
|
||||
private String discountBronze;
|
||||
@NotNull
|
||||
@Min(0)
|
||||
private Integer discountBronze;
|
||||
|
||||
public Integer getGold() {
|
||||
return gold;
|
||||
|
@ -40,11 +48,11 @@ public class SpeedOffer extends Offer {
|
|||
this.gold = gold;
|
||||
}
|
||||
|
||||
public String getDiscountGold() {
|
||||
public Integer getDiscountGold() {
|
||||
return discountGold;
|
||||
}
|
||||
|
||||
public void setDiscountGold(String discountGold) {
|
||||
public void setDiscountGold(Integer discountGold) {
|
||||
this.discountGold = discountGold;
|
||||
}
|
||||
|
||||
|
@ -56,11 +64,11 @@ public class SpeedOffer extends Offer {
|
|||
this.silver = silver;
|
||||
}
|
||||
|
||||
public String getDiscountSilver() {
|
||||
public Integer getDiscountSilver() {
|
||||
return discountSilver;
|
||||
}
|
||||
|
||||
public void setDiscountSilver(String discountSilver) {
|
||||
public void setDiscountSilver(Integer discountSilver) {
|
||||
this.discountSilver = discountSilver;
|
||||
}
|
||||
|
||||
|
@ -72,12 +80,12 @@ public class SpeedOffer extends Offer {
|
|||
this.bronze = bronze;
|
||||
}
|
||||
|
||||
public String getDiscountBronze() {
|
||||
public Integer getDiscountBronze() {
|
||||
return discountBronze;
|
||||
}
|
||||
|
||||
public void setDiscountBronze(String discountBronze) {
|
||||
public void setDiscountBronze(Integer discountBronze) {
|
||||
this.discountBronze = discountBronze;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,9 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cheapy.model;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
@ -27,7 +11,11 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|||
@Entity
|
||||
@Table(name = "time_offers")
|
||||
public class TimeOffer extends Offer {
|
||||
//Oferta por franja horaria
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// Oferta por franja horaria
|
||||
|
||||
@DateTimeFormat(pattern = "HH:mm")
|
||||
@NotNull
|
||||
private LocalTime init;
|
||||
|
@ -36,10 +24,8 @@ public class TimeOffer extends Offer {
|
|||
@NotNull
|
||||
private LocalTime finish;
|
||||
|
||||
@NotBlank
|
||||
private String discount;
|
||||
|
||||
|
||||
@NotNull
|
||||
private Integer discount;
|
||||
|
||||
public LocalTime getInit() {
|
||||
return init;
|
||||
|
@ -57,11 +43,11 @@ public class TimeOffer extends Offer {
|
|||
this.finish = finish;
|
||||
}
|
||||
|
||||
public String getDiscount() {
|
||||
public Integer getDiscount() {
|
||||
return discount;
|
||||
}
|
||||
|
||||
public void setDiscount(String discount) {
|
||||
public void setDiscount(Integer discount) {
|
||||
this.discount = discount;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package org.springframework.cheapy.model;
|
||||
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
//@MappedSuperclass
|
||||
public class User{
|
||||
|
||||
@Id
|
||||
|
@ -17,10 +17,6 @@ public class User{
|
|||
|
||||
boolean enabled;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
package org.springframework.cheapy.model;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Email;
|
||||
|
|
|
@ -1,20 +1 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The classes in this package represent utilities used by the domain.
|
||||
*/
|
||||
package org.springframework.cheapy.model;
|
||||
|
|
|
@ -2,8 +2,6 @@ package org.springframework.cheapy.repository;
|
|||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.cheapy.model.Authorities;
|
||||
import org.springframework.cheapy.model.User;
|
||||
|
||||
|
||||
public interface AuthoritiesRepository extends CrudRepository<Authorities, Integer>{
|
||||
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
|
||||
package org.springframework.cheapy.repository;
|
||||
|
||||
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public interface ClientRepository extends CrudRepository<Client, String> {
|
||||
|
||||
|
||||
@Query("SELECT client FROM Client client WHERE username =:username")
|
||||
@Transactional(readOnly = true)
|
||||
Client findByUsername(String username);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
package org.springframework.cheapy.repository;
|
||||
|
||||
|
||||
import org.springframework.cheapy.model.FoodOffer;
|
||||
import java.util.Collection;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
public interface FoodOfferRepository extends Repository<FoodOffer, Integer> {
|
||||
|
||||
@Query("SELECT foodOffer FROM FoodOffer foodOffer")
|
||||
@Query("SELECT foodOffer FROM FoodOffer foodOffer")
|
||||
@Transactional(readOnly = true)
|
||||
List<FoodOffer> findAllFoodOffer();
|
||||
|
||||
|
@ -21,5 +20,12 @@ public interface FoodOfferRepository extends Repository<FoodOffer, Integer> {
|
|||
FoodOffer findById(@Param("id") Integer id);
|
||||
|
||||
void save(FoodOffer foodOffer);
|
||||
|
||||
|
||||
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.status =:status")
|
||||
@Transactional(readOnly = true)
|
||||
List<FoodOffer> findActiveFoodOffer(StatusOffer status);
|
||||
|
||||
@Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.id =:id")
|
||||
@Transactional(readOnly = true)
|
||||
List<FoodOffer> findByUserId(@Param("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -1,28 +1,30 @@
|
|||
|
||||
package org.springframework.cheapy.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cheapy.model.FoodOffer;
|
||||
import org.springframework.cheapy.model.NuOffer;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
public interface NuOfferRepository extends Repository<NuOffer, Integer> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NuOffer findNuOfferById(int nuOfferId);
|
||||
|
||||
@Query("SELECT nuOffer FROM NuOffer nuOffer")
|
||||
@Query("SELECT nuOffer FROM NuOffer nuOffer")
|
||||
@Transactional(readOnly = true)
|
||||
List<NuOffer> findAllNuOffer();
|
||||
|
||||
|
||||
|
||||
void save(NuOffer nuOffer);
|
||||
|
||||
|
||||
@Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.status =:status")
|
||||
@Transactional(readOnly = true)
|
||||
List<NuOffer> findActiveNuOffer(StatusOffer status);
|
||||
|
||||
@Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.id =:id")
|
||||
@Transactional(readOnly = true)
|
||||
List<NuOffer> findByUserId(@Param("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -1,28 +1,32 @@
|
|||
|
||||
package org.springframework.cheapy.repository;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cheapy.model.FoodOffer;
|
||||
import org.springframework.cheapy.model.SpeedOffer;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
public interface SpeedOfferRepository extends Repository<SpeedOffer, Integer> {
|
||||
|
||||
|
||||
@Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE id =:id")
|
||||
@Transactional(readOnly = true)
|
||||
SpeedOffer findById(@Param("id") Integer id);
|
||||
|
||||
@Query("SELECT speedOffer FROM SpeedOffer speedOffer")
|
||||
@Query("SELECT speedOffer FROM SpeedOffer speedOffer")
|
||||
@Transactional(readOnly = true)
|
||||
List<SpeedOffer> findAllSpeedOffer();
|
||||
|
||||
|
||||
void save(SpeedOffer speedOffer);
|
||||
|
||||
|
||||
@Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.status =:status")
|
||||
@Transactional(readOnly = true)
|
||||
List<SpeedOffer> findActiveSpeedOffer(StatusOffer status);
|
||||
|
||||
@Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.id =:id")
|
||||
@Transactional(readOnly = true)
|
||||
List<SpeedOffer> findByUserId(@Param("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -1,28 +1,29 @@
|
|||
|
||||
package org.springframework.cheapy.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
import org.springframework.cheapy.model.TimeOffer;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
public interface TimeOfferRepository extends Repository<TimeOffer, Integer> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TimeOffer findTimeOfferById(int timeOfferId);
|
||||
|
||||
@Query("SELECT timeOffer FROM TimeOffer timeOffer")
|
||||
@Query("SELECT timeOffer FROM TimeOffer timeOffer")
|
||||
@Transactional(readOnly = true)
|
||||
List<TimeOffer> findAllTimeOffer();
|
||||
|
||||
|
||||
|
||||
void save(TimeOffer timeOffer);
|
||||
|
||||
|
||||
@Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.status =:status")
|
||||
@Transactional(readOnly = true)
|
||||
List<TimeOffer> findActiveTimeOffer(StatusOffer status);
|
||||
|
||||
@Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.id =:id")
|
||||
@Transactional(readOnly = true)
|
||||
List<TimeOffer> findByUserId(@Param("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
package org.springframework.cheapy.repository;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.cheapy.model.User;
|
||||
import org.springframework.cheapy.model.Usuario;
|
||||
|
||||
public interface UsuarioRepository extends CrudRepository<Usuario, String> {
|
||||
|
|
|
@ -1,21 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cheapy.service;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.repository.ClientRepository;
|
||||
|
@ -25,8 +9,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
|
||||
@Service
|
||||
public class ClientService {
|
||||
|
||||
|
@ -37,13 +19,11 @@ public class ClientService {
|
|||
this.clientRepository = clientRepository;
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public Client getCurrentClient() throws DataAccessException {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
String username = authentication.getName();
|
||||
String username = authentication.getName();
|
||||
return this.clientRepository.findByUsername(username);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,17 +2,17 @@ package org.springframework.cheapy.service;
|
|||
|
||||
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.Collection;
|
||||
import java.util.List;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class FoodOfferService {
|
||||
|
||||
private FoodOfferRepository foodOfferRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
public FoodOfferService(final FoodOfferRepository foodOfferRepository) {
|
||||
this.foodOfferRepository = foodOfferRepository;
|
||||
|
@ -21,15 +21,20 @@ public class FoodOfferService {
|
|||
public FoodOffer findFoodOfferById(final int id) {
|
||||
return this.foodOfferRepository.findById(id);
|
||||
}
|
||||
|
||||
public List<FoodOffer> findAllFoodOffer() { //
|
||||
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> findFoodOfferByUserId(final int id) {
|
||||
return this.foodOfferRepository.findByUserId(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +1,45 @@
|
|||
package org.springframework.cheapy.service;
|
||||
|
||||
package org.springframework.cheapy.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cheapy.model.NuOffer;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
import org.springframework.cheapy.repository.NuOfferRepository;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class NuOfferService {
|
||||
private NuOfferRepository nuOfferRepository;
|
||||
|
||||
private NuOfferRepository nuOfferRepository;
|
||||
|
||||
@Autowired
|
||||
public NuOfferService(final NuOfferRepository nuOfferRepository) {
|
||||
this.nuOfferRepository = nuOfferRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public NuOffer findNuOfferById(final int id) {
|
||||
|
||||
return this.nuOfferRepository.findNuOfferById(id);
|
||||
}
|
||||
public List<NuOffer> findAllNuOffer() { //
|
||||
return this.nuOfferRepository.findAllNuOffer();
|
||||
|
||||
@Transactional
|
||||
public List<NuOffer> findAllNuOffer() {
|
||||
return this.nuOfferRepository.findAllNuOffer();
|
||||
}
|
||||
|
||||
|
||||
public void saveNuOffer(final NuOffer nuOffer) throws DataAccessException { //
|
||||
|
||||
@Transactional
|
||||
public void saveNuOffer(final NuOffer nuOffer) throws DataAccessException {
|
||||
this.nuOfferRepository.save(nuOffer);
|
||||
|
||||
}
|
||||
|
||||
public List<NuOffer> findActiveNuOffer() {
|
||||
return this.nuOfferRepository.findActiveNuOffer(StatusOffer.active);
|
||||
}
|
||||
|
||||
public List<NuOffer> findNuOfferByUserId(final int id) {
|
||||
return this.nuOfferRepository.findByUserId(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
|
||||
package org.springframework.cheapy.service;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cheapy.model.NuOffer;
|
||||
import org.springframework.cheapy.model.SpeedOffer;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
import org.springframework.cheapy.repository.SpeedOfferRepository;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class SpeedOfferService {
|
||||
|
@ -20,19 +22,26 @@ public class SpeedOfferService {
|
|||
this.speedOfferRepository = speedOfferRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public SpeedOffer findSpeedOfferById(final int id) {
|
||||
return this.speedOfferRepository.findById(id);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<SpeedOffer> findAllSpeedOffer() { //
|
||||
return this.speedOfferRepository.findAllSpeedOffer();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void saveSpeedOffer(final SpeedOffer speedOffer) throws DataAccessException {
|
||||
|
||||
@Transactional
|
||||
public void saveSpeedOffer(final SpeedOffer speedOffer) throws DataAccessException { //
|
||||
this.speedOfferRepository.save(speedOffer);
|
||||
|
||||
}
|
||||
|
||||
public List<SpeedOffer> findActiveSpeedOffer() {
|
||||
return this.speedOfferRepository.findActiveSpeedOffer(StatusOffer.active);
|
||||
}
|
||||
|
||||
public List<SpeedOffer> findSpeedOfferByUserId(final int id) {
|
||||
return this.speedOfferRepository.findByUserId(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package org.springframework.cheapy.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
import org.springframework.cheapy.model.TimeOffer;
|
||||
import org.springframework.cheapy.repository.TimeOfferRepository;
|
||||
|
||||
|
@ -21,14 +24,20 @@ public class TimeOfferService {
|
|||
return this.timeOfferRepository.findTimeOfferById(id);
|
||||
}
|
||||
|
||||
public List<TimeOffer> findAllTimeOffer() { //
|
||||
public List<TimeOffer> findAllTimeOffer() {
|
||||
return this.timeOfferRepository.findAllTimeOffer();
|
||||
}
|
||||
|
||||
|
||||
public void saveTimeOffer(final TimeOffer TimeOffer) throws DataAccessException { //
|
||||
public void saveTimeOffer(final TimeOffer TimeOffer) throws DataAccessException {
|
||||
this.timeOfferRepository.save(TimeOffer);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public List<TimeOffer> findActiveTimeOffer() {
|
||||
return this.timeOfferRepository.findActiveTimeOffer(StatusOffer.active);
|
||||
}
|
||||
|
||||
public List<TimeOffer> findTimeOfferByUserId(final int id) {
|
||||
return this.timeOfferRepository.findByUserId(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
|
||||
package org.springframework.cheapy.web;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.model.FoodOffer;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
|
@ -11,73 +14,115 @@ import org.springframework.cheapy.service.FoodOfferService;
|
|||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
@Controller
|
||||
public class FoodOfferController {
|
||||
|
||||
private static final String VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM = "foodOffers/createOrUpdateFoodOfferForm";
|
||||
private static final String VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM = "offers/food/createOrUpdateFoodOfferForm";
|
||||
|
||||
private final FoodOfferService foodOfferService;
|
||||
private final ClientService clientService;
|
||||
|
||||
|
||||
public FoodOfferController(final FoodOfferService foodOfferService, final ClientService clientService) {
|
||||
this.foodOfferService = foodOfferService;
|
||||
this.clientService = clientService;
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@GetMapping("/foodOffers/new")
|
||||
@GetMapping("/offers/food/new")
|
||||
public String initCreationForm(Map<String, Object> model) {
|
||||
FoodOffer foodOffer = new FoodOffer();
|
||||
model.put("foodOffer", foodOffer);
|
||||
return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/foodOffers/new")
|
||||
@PostMapping("/offers/food/new")
|
||||
public String processCreationForm(@Valid FoodOffer foodOffer, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
else {
|
||||
Client client = this.clientService.getCurrentclient();
|
||||
} else {
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
foodOffer.setClient(client);
|
||||
foodOffer.setType(StatusOffer.hidden);
|
||||
foodOffer.setStatus(StatusOffer.hidden);
|
||||
this.foodOfferService.saveFoodOffer(foodOffer);
|
||||
return "redirect:/foodOffers/" + foodOffer.getId();
|
||||
return "redirect:/offers/food/" + foodOffer.getId();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/foodOffers/{foodOfferId}/activate")
|
||||
@GetMapping(value = "/offers/food/{foodOfferId}/activate")
|
||||
public String activateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, ModelMap modelMap) {
|
||||
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
|
||||
Client client = this.clientService.getCurrentclient();
|
||||
if(foodOffer.getClient().equals(client)) {
|
||||
foodOffer.setType(StatusOffer.active);
|
||||
foodOffer.setCode("FO-"+foodOfferId);
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
if (foodOffer.getClient().equals(client)) {
|
||||
foodOffer.setStatus(StatusOffer.active);
|
||||
foodOffer.setCode("FO-" + foodOfferId);
|
||||
this.foodOfferService.saveFoodOffer(foodOffer);
|
||||
} else {
|
||||
modelMap.addAttribute("message", "You don't have access to this food offer");
|
||||
}
|
||||
return "redirect:/foodOffers/";
|
||||
return "redirect:/offers/food/"+foodOfferId;
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/offers/food/{foodOfferId}")
|
||||
public String processShowForm(@PathVariable("foodOfferId") int foodOfferId, Map<String, Object> model) {
|
||||
|
||||
FoodOffer foodOffer=this.foodOfferService.findFoodOfferById(foodOfferId);
|
||||
|
||||
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
|
||||
|
||||
model.put("foodOffer", foodOffer);
|
||||
|
||||
return "foodOffers/foodOffersShow";
|
||||
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
|
||||
|
||||
|
||||
return "offers/food/foodOffersShow";
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/food/{foodOfferId}/edit")
|
||||
public String updateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) {
|
||||
|
||||
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
|
||||
model.addAttribute("foodOffer", foodOffer);
|
||||
return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/offers/food/{foodOfferId}/edit")
|
||||
public String updateFoodOffer(@Valid final FoodOffer foodOfferEdit, final BindingResult result,
|
||||
final ModelMap model) {
|
||||
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("foodOffer", foodOfferEdit);
|
||||
return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
|
||||
} else {
|
||||
this.foodOfferService.saveFoodOffer(foodOfferEdit);
|
||||
return "redirect:/offers/food/" + foodOfferEdit.getId();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/food/{foodOfferId}/disable")
|
||||
public String disableFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) {
|
||||
|
||||
|
||||
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
|
||||
model.put("foodOffer", foodOffer);
|
||||
return "foodOffers/foodOffersDisable";
|
||||
}
|
||||
|
||||
@PostMapping(value = "/offers/food/{foodOfferId}/disable")
|
||||
public String disableFoodOfferForm(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) {
|
||||
|
||||
|
||||
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
|
||||
|
||||
foodOffer.setStatus(StatusOffer.inactive);
|
||||
|
||||
this.foodOfferService.saveFoodOffer(foodOffer);
|
||||
|
||||
return "redirect:/offers";
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,98 +1,128 @@
|
|||
package org.springframework.cheapy.web;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.model.NuOffer;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.NuOfferService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
|
||||
@Controller
|
||||
public class NuOfferController {
|
||||
|
||||
private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "nuOffers/createOrUpdateNuOfferForm";
|
||||
private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "offers/nu/createOrUpdateNuOfferForm";
|
||||
|
||||
private final NuOfferService nuOfferService;
|
||||
private final ClientService clientService;
|
||||
|
||||
|
||||
|
||||
public NuOfferController(final NuOfferService nuOfferService,ClientService clientService) {
|
||||
public NuOfferController(final NuOfferService nuOfferService, final ClientService clientService) {
|
||||
this.nuOfferService = nuOfferService;
|
||||
this.clientService = clientService;
|
||||
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@GetMapping("/nuOffers/new")
|
||||
@GetMapping("/offers/nu/new")
|
||||
public String initCreationForm(Map<String, Object> model) {
|
||||
NuOffer nuOffer = new NuOffer();
|
||||
model.put("nuOffer", nuOffer);
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/nuOffers/new")
|
||||
@PostMapping("/offers/nu/new")
|
||||
public String processCreationForm(@Valid NuOffer nuOffer, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
else {
|
||||
nuOffer.setType(StatusOffer.hidden);
|
||||
|
||||
} else {
|
||||
nuOffer.setStatus(StatusOffer.hidden);
|
||||
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
|
||||
|
||||
nuOffer.setClient(client);
|
||||
|
||||
|
||||
|
||||
this.nuOfferService.saveNuOffer(nuOffer);
|
||||
return "redirect:/nuOffers/" + nuOffer.getId();
|
||||
return "redirect:/offers/nu/"+nuOffer.getId();
|
||||
}
|
||||
}
|
||||
@GetMapping(value ="/nuOffers/{nuOfferId}/activate")
|
||||
|
||||
@GetMapping(value ="/offers/nu/{nuOfferId}/activate")
|
||||
public String activateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap modelMap) {
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId);
|
||||
if(nuOffer.getClient().equals(client)) {
|
||||
nuOffer.setType(StatusOffer.active);
|
||||
nuOffer.setCode("NU-"+nuOfferId);
|
||||
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
|
||||
if (nuOffer.getClient().equals(client)) {
|
||||
nuOffer.setStatus(StatusOffer.active);
|
||||
nuOffer.setCode("NU-" + nuOfferId);
|
||||
this.nuOfferService.saveNuOffer(nuOffer);
|
||||
|
||||
return "redirect:/nuOffers/" + nuOffer.getId();
|
||||
} else {
|
||||
modelMap.addAttribute("message", "You don't have access to this number offer");
|
||||
}
|
||||
return "redirect:/nuOffers/";
|
||||
|
||||
modelMap.addAttribute("message", "You don't have access to this number offer");
|
||||
}
|
||||
return "redirect:/offers/nu/"+ nuOffer.getId();
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/offers/nu/{nuOfferId}")
|
||||
|
||||
@GetMapping("/offers/nu/{nuOfferId}")
|
||||
public String processShowForm(@PathVariable("nuOfferId") int nuOfferId, Map<String, Object> model) {
|
||||
|
||||
NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId);
|
||||
|
||||
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
|
||||
model.put("nuOffer", nuOffer);
|
||||
|
||||
return "nuOffers/nuOffersShow";
|
||||
|
||||
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
|
||||
return "offers/nu/nuOffersShow";
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/nu/{nuOfferId}/edit")
|
||||
public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap model) {
|
||||
|
||||
|
||||
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
|
||||
model.addAttribute("nuOffer", nuOffer);
|
||||
return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/offers/nu/{nuOfferId}/edit")
|
||||
public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final ModelMap model) {
|
||||
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("nuOffer", nuOfferEdit);
|
||||
return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
|
||||
} else {
|
||||
this.nuOfferService.saveNuOffer(nuOfferEdit);
|
||||
return "redirect:/offers/nu/" + nuOfferEdit.getId();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/nu/{nuOfferId}/disable")
|
||||
public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal,
|
||||
final ModelMap model) {
|
||||
|
||||
|
||||
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
|
||||
model.put("nuOffer", nuOffer);
|
||||
return "nuOffers/nuOffersDisable";
|
||||
}
|
||||
|
||||
@PostMapping(value = "/offers/nu/{nuOfferId}/disable")
|
||||
public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal,
|
||||
final ModelMap model) {
|
||||
|
||||
|
||||
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
|
||||
nuOffer.setStatus(StatusOffer.inactive);
|
||||
this.nuOfferService.saveNuOffer(nuOffer);
|
||||
return "redirect:/offers";
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,21 +1,6 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cheapy.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -23,60 +8,74 @@ import org.springframework.cheapy.model.FoodOffer;
|
|||
import org.springframework.cheapy.model.NuOffer;
|
||||
import org.springframework.cheapy.model.SpeedOffer;
|
||||
import org.springframework.cheapy.model.TimeOffer;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
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.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Controller
|
||||
public class OfertaController {
|
||||
|
||||
//private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
|
||||
|
||||
|
||||
private final ClientService clientService;
|
||||
|
||||
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) {
|
||||
final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService, ClientService clientService) {
|
||||
this.clientService = clientService;
|
||||
this.foodOfferService = foodOfferService;
|
||||
this.nuOfferService = nuOfferService;
|
||||
this.speedOfferService = speedOfferService;
|
||||
this.timeOfferService = timeOfferService;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/offers")
|
||||
public String processFindForm( Map<String, Object> model) {
|
||||
|
||||
List<FoodOffer> foodOfferLs=this.foodOfferService.findAllFoodOffer();
|
||||
List<NuOffer> nuOfferLs=this.nuOfferService.findAllNuOffer();
|
||||
List<SpeedOffer> speedOfferLs=this.speedOfferService.findAllSpeedOffer();
|
||||
List<TimeOffer> timeOfferLs=this.timeOfferService.findAllTimeOffer();
|
||||
List<FoodOffer> foodOfferLs=this.foodOfferService.findActiveFoodOffer();
|
||||
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);
|
||||
model.put("speedOfferLs", speedOfferLs);
|
||||
model.put("timeOfferLs", timeOfferLs);
|
||||
|
||||
//Se añade formateador de fecha al modelo
|
||||
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
|
||||
|
||||
return "offers/offersList";
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/myOffers")
|
||||
public String processMyOffersForm( Map<String, Object> model) {
|
||||
|
||||
int actual = this.clientService.getCurrentClient().getId();
|
||||
|
||||
List<FoodOffer> foodOfferLs = this.foodOfferService.findFoodOfferByUserId(actual);
|
||||
List<NuOffer> nuOfferLs = this.nuOfferService.findNuOfferByUserId(actual);
|
||||
List<SpeedOffer> speedOfferLs = this.speedOfferService.findSpeedOfferByUserId(actual);
|
||||
List<TimeOffer> timeOfferLs = this.timeOfferService.findTimeOfferByUserId(actual);
|
||||
|
||||
model.put("foodOfferLs", foodOfferLs);
|
||||
model.put("nuOfferLs", nuOfferLs);
|
||||
model.put("speedOfferLs", speedOfferLs);
|
||||
model.put("timeOfferLs", timeOfferLs);
|
||||
|
||||
//Se añade formateador de fecha al modelo
|
||||
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
|
||||
|
||||
return "offers/myOffersList";
|
||||
|
||||
}
|
||||
// @GetMapping("/owners/{ownerId}/edit")
|
||||
// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
||||
// Owner owner = this.ownerService.findOwnerById(ownerId);
|
||||
|
|
|
@ -1,18 +1,3 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cheapy.web;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -21,7 +6,6 @@ import java.util.Map;
|
|||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.cheapy.model.Owner;
|
||||
import org.springframework.cheapy.repository.OwnerRepository;
|
||||
import org.springframework.cheapy.service.OwnerService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
|
@ -33,12 +17,6 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Controller
|
||||
public class OwnerController {
|
||||
|
||||
|
@ -137,5 +115,4 @@ public class OwnerController {
|
|||
return mav;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,43 +1,26 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cheapy.web;
|
||||
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.model.SpeedOffer;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.SpeedOfferService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
@Controller
|
||||
public class SpeedOfferController {
|
||||
|
||||
private static final String VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM = "speedOffers/createOrUpdateSpeedOfferForm";
|
||||
private static final String VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM = "offers/speed/createOrUpdateSpeedOfferForm";
|
||||
|
||||
private final SpeedOfferService speedOfferService;
|
||||
private final ClientService clientService;
|
||||
|
@ -45,58 +28,96 @@ public class SpeedOfferController {
|
|||
public SpeedOfferController(final SpeedOfferService speedOfferService, final ClientService clientService) {
|
||||
this.speedOfferService = speedOfferService;
|
||||
this.clientService = clientService;
|
||||
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@GetMapping("/speedOffers/new")
|
||||
@GetMapping("/offers/speed/new")
|
||||
public String initCreationForm(Map<String, Object> model) {
|
||||
SpeedOffer speedOffer = new SpeedOffer();
|
||||
model.put("speedOffer", speedOffer);
|
||||
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/speedOffers/new")
|
||||
@PostMapping("/offers/speed/new")
|
||||
public String processCreationForm(@Valid SpeedOffer speedOffer, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
else {
|
||||
Client client = this.clientService.getCurrentclient();
|
||||
} else {
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
speedOffer.setClient(client);
|
||||
speedOffer.setType(StatusOffer.hidden);
|
||||
speedOffer.setStatus(StatusOffer.hidden);
|
||||
this.speedOfferService.saveSpeedOffer(speedOffer);
|
||||
return "redirect:/speedOffers/" + speedOffer.getId();
|
||||
return "redirect:/offers/speed/" + speedOffer.getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/speedOffers/{speedOfferId}/activate")
|
||||
@GetMapping(value = "/offers/speed/{speedOfferId}/activate")
|
||||
public String activateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, ModelMap modelMap) {
|
||||
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
|
||||
Client client = this.clientService.getCurrentclient();
|
||||
if(speedOffer.getClient().equals(client)) {
|
||||
speedOffer.setType(StatusOffer.active);
|
||||
speedOffer.setCode("SP-"+speedOfferId);
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
if (speedOffer.getClient().equals(client)) {
|
||||
speedOffer.setStatus(StatusOffer.active);
|
||||
speedOffer.setCode("SP-" + speedOfferId);
|
||||
this.speedOfferService.saveSpeedOffer(speedOffer);
|
||||
} else {
|
||||
modelMap.addAttribute("message", "You don't have access to this speed offer");
|
||||
}
|
||||
return "redirect:/speedOffers/";
|
||||
return "redirect:/offers/speed/" + speedOffer.getId();
|
||||
}
|
||||
|
||||
@GetMapping("/offers/speed/{speedOfferId}")
|
||||
|
||||
@GetMapping("/offers/speed/{speedOfferId}")
|
||||
public String processShowForm(@PathVariable("speedOfferId") int speedOfferId, Map<String, Object> model) {
|
||||
|
||||
SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId);
|
||||
|
||||
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
|
||||
model.put("speedOffer", speedOffer);
|
||||
|
||||
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
|
||||
return "offers/speed/speedOffersShow";
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/speed/{speedOfferId}/edit")
|
||||
public String updateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) {
|
||||
|
||||
return "speedOffers/speedOffersShow";
|
||||
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
|
||||
model.addAttribute("speedOffer", speedOffer);
|
||||
return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/offers/speed/{speedOfferId}/edit")
|
||||
public String updateSpeedOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, final ModelMap model) {
|
||||
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("speedOffer", speedOfferEdit);
|
||||
return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
|
||||
} else {
|
||||
this.speedOfferService.saveSpeedOffer(speedOfferEdit);
|
||||
return "redirect:/offers/speed/" + speedOfferEdit.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/speed/{speedOfferId}/disable")
|
||||
public String disableSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) {
|
||||
|
||||
|
||||
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
|
||||
model.put("speedOffer", speedOffer);
|
||||
return "speedOffers/speedOffersDisable";
|
||||
}
|
||||
|
||||
@PostMapping(value = "/offers/speed/{speedOfferId}/disable")
|
||||
public String disableSpeedOfferForm(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) {
|
||||
|
||||
|
||||
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
|
||||
|
||||
speedOffer.setStatus(StatusOffer.inactive);
|
||||
|
||||
this.speedOfferService.saveSpeedOffer(speedOffer);
|
||||
|
||||
return "redirect:/offers";
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,96 +1,136 @@
|
|||
package org.springframework.cheapy.web;
|
||||
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.model.TimeOffer;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
import org.springframework.cheapy.model.TimeOffer;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.TimeOfferService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
|
||||
@Controller
|
||||
public class TimeOfferController {
|
||||
|
||||
private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "timeOffers/createOrUpdateTimeOfferForm";
|
||||
|
||||
private static final String VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM = "offers/time/createOrUpdateTimeOfferForm";
|
||||
private final TimeOfferService timeOfferService;
|
||||
private final ClientService clientService;
|
||||
|
||||
|
||||
|
||||
public TimeOfferController(final TimeOfferService timeOfferService,ClientService clientService) {
|
||||
public TimeOfferController(final TimeOfferService timeOfferService, ClientService clientService) {
|
||||
this.timeOfferService = timeOfferService;
|
||||
this.clientService = clientService;
|
||||
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@GetMapping("/timeOffers/new")
|
||||
@GetMapping("/offers/time/new")
|
||||
public String initCreationForm(Map<String, Object> model) {
|
||||
TimeOffer timeOffer = new TimeOffer();
|
||||
model.put("timeOffer", timeOffer);
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/timeOffers/new")
|
||||
@PostMapping("/offers/time/new")
|
||||
public String processCreationForm(@Valid TimeOffer timeOffer, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
else {
|
||||
timeOffer.setType(StatusOffer.hidden);
|
||||
|
||||
return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
} else {
|
||||
timeOffer.setStatus(StatusOffer.hidden);
|
||||
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
|
||||
|
||||
timeOffer.setClient(client);
|
||||
|
||||
|
||||
|
||||
this.timeOfferService.saveTimeOffer(timeOffer);
|
||||
return "redirect:/TimeOffers/" + timeOffer.getId();
|
||||
return "redirect:/offers/time/" + timeOffer.getId();
|
||||
}
|
||||
}
|
||||
@GetMapping(value ="/timeOffers/{timeOfferId}/activate")
|
||||
|
||||
@GetMapping(value ="/offers/time/{timeOfferId}/activate")
|
||||
public String activateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap modelMap) {
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
TimeOffer timeOffer=this.timeOfferService.findTimeOfferById(timeOfferId);
|
||||
if(timeOffer.getClient().equals(client)) {
|
||||
timeOffer.setType(StatusOffer.active);
|
||||
timeOffer.setCode("TI-"+timeOfferId);
|
||||
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
|
||||
if (timeOffer.getClient().equals(client)) {
|
||||
timeOffer.setStatus(StatusOffer.active);
|
||||
timeOffer.setCode("TI-" + timeOfferId);
|
||||
this.timeOfferService.saveTimeOffer(timeOffer);
|
||||
|
||||
|
||||
return "redirect:/timeOffers/" + timeOffer.getId();
|
||||
} else {
|
||||
modelMap.addAttribute("message", "You don't have access to this time offer");
|
||||
}
|
||||
return "redirect:/timeOffers/";
|
||||
|
||||
modelMap.addAttribute("message", "You don't have access to this time offer");
|
||||
}
|
||||
return "redirect:/offers/time/" + timeOffer.getId();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/offers/time/{timeOfferId}")
|
||||
|
||||
@GetMapping("/offers/time/{timeOfferId}")
|
||||
public String processShowForm(@PathVariable("timeOfferId") int timeOfferId, Map<String, Object> model) {
|
||||
|
||||
TimeOffer timeOffer=this.timeOfferService.findTimeOfferById(timeOfferId);
|
||||
|
||||
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
|
||||
|
||||
model.put("timeOffer", timeOffer);
|
||||
|
||||
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
|
||||
|
||||
return "timeOffers/timeOffersShow";
|
||||
return "offers/time/timeOffersShow";
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/time/{timeOfferId}/edit")
|
||||
public String updateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) {
|
||||
|
||||
|
||||
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
|
||||
model.addAttribute("timeOffer", timeOffer);
|
||||
return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/offers/time/{timeOfferId}/edit")
|
||||
public String updateTimeOffer(@Valid final TimeOffer timeOfferEdit, final BindingResult result, final ModelMap model) {
|
||||
|
||||
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("timeOffer", timeOfferEdit);
|
||||
return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
|
||||
} else {
|
||||
this.timeOfferService.saveTimeOffer(timeOfferEdit);
|
||||
return "redirect:/offers/time/" + timeOfferEdit.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/time/{timeOfferId}/disable")
|
||||
public String disableTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) {
|
||||
|
||||
|
||||
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
|
||||
model.put("timeOffer", timeOffer);
|
||||
return "timeOffers/timeOffersDisable";
|
||||
}
|
||||
|
||||
@PostMapping(value = "/offers/time/{timeOfferId}/disable")
|
||||
public String disableTimeOfferForm(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) {
|
||||
|
||||
|
||||
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
|
||||
|
||||
timeOffer.setStatus(StatusOffer.inactive);
|
||||
|
||||
this.timeOfferService.saveTimeOffer(timeOffer);
|
||||
|
||||
return "redirect:/offers";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -47,10 +47,10 @@
|
|||
|
||||
@pagination-active-bg: @spring-brown;
|
||||
@pagination-active-border: @spring-blue;
|
||||
@table-border-color: @spring-brown;
|
||||
@table-border-color: rgb(0, 64, 128);
|
||||
|
||||
.table > thead > tr > th {
|
||||
background-color: lighten(@spring-brown, 3%);
|
||||
.table > thead > tr > th {
|
||||
background-color: rgb(40, 140, 215);
|
||||
color: @spring-light-grey;
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,131 @@ img.img-responsive{
|
|||
|
||||
|
||||
.btn-home button:hover {
|
||||
background-color: rgb(0, 64, 128);
|
||||
background-color: rgb(40, 140, 215);
|
||||
}
|
||||
|
||||
#foodOfferTable th {
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
#nuOfferTable th {
|
||||
width: 33%;
|
||||
}
|
||||
|
||||
#speedOfferTable th {
|
||||
width: 33%;
|
||||
}
|
||||
|
||||
#timeOfferTable th {
|
||||
width: 33%;
|
||||
}
|
||||
|
||||
.btn-detalles button {
|
||||
background-color: rgb(0, 64, 128);
|
||||
border: 1px solid rgb(0, 0, 160);
|
||||
color: white;
|
||||
padding: 10px 24px;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.btn-detalles button:not(:last-child) {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
|
||||
.btn-detalles button:hover {
|
||||
background-color: rgb(40, 140, 215);
|
||||
}
|
||||
|
||||
.btn-return{
|
||||
display: table;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.btn-return button {
|
||||
background-color: rgb(0, 64, 128);
|
||||
border: 1px solid rgb(0, 0, 160);
|
||||
color: white;
|
||||
padding: 10px 24px;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
left: 0%;
|
||||
}
|
||||
|
||||
.btn-return button:not(:last-child) {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
|
||||
.btn-return button:hover {
|
||||
background-color: rgb(40, 140, 215);
|
||||
}
|
||||
|
||||
#foodOfferTable td{
|
||||
vertical-align:middle;
|
||||
}
|
||||
|
||||
#nuOfferTable td{
|
||||
vertical-align:middle;
|
||||
}
|
||||
|
||||
#speedOfferTable td{
|
||||
vertical-align:middle;
|
||||
}
|
||||
|
||||
#timeOfferTable td{
|
||||
vertical-align:middle;
|
||||
}
|
||||
|
||||
#nuOffer-table tr:nth-child(3){
|
||||
background-color: rgb(255, 215, 0);
|
||||
}
|
||||
|
||||
#nuOffer-table tr:nth-child(4){
|
||||
background-color: rgb(255, 215, 0);
|
||||
}
|
||||
|
||||
#nuOffer-table tr:nth-child(5){
|
||||
background-color: rgb(192, 192, 192);
|
||||
}
|
||||
|
||||
#nuOffer-table tr:nth-child(6){
|
||||
background-color: rgb(192, 192, 192);
|
||||
}
|
||||
|
||||
#nuOffer-table tr:nth-child(7){
|
||||
background-color: rgb(204, 128, 51);
|
||||
}
|
||||
|
||||
#nuOffer-table tr:nth-child(8){
|
||||
background-color: rgb(204, 128, 51);
|
||||
}
|
||||
|
||||
#speedOffer-table tr:nth-child(3){
|
||||
background-color: rgb(255, 215, 0);
|
||||
}
|
||||
|
||||
#speedOffer-table tr:nth-child(4){
|
||||
background-color: rgb(255, 215, 0);
|
||||
}
|
||||
|
||||
#speedOffer-table tr:nth-child(5){
|
||||
background-color: rgb(192, 192, 192);
|
||||
}
|
||||
|
||||
#speedOffer-table tr:nth-child(6){
|
||||
background-color: rgb(192, 192, 192);
|
||||
}
|
||||
|
||||
#speedOffer-table tr:nth-child(7){
|
||||
background-color: rgb(204, 128, 51);
|
||||
}
|
||||
|
||||
#speedOffer-table tr:nth-child(8){
|
||||
background-color: rgb(204, 128, 51);
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
|
|
|
@ -9,33 +9,31 @@ INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '
|
|||
INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435');
|
||||
INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487');
|
||||
|
||||
|
||||
|
||||
INSERT INTO food_offers(start, end, code, type, client_id, food, discount, units) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'FO-1', 'active', null, 'macarrones', '15%', 10);
|
||||
INSERT INTO speed_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'SP-1', 'active', null, 5, '15%', 10, '10%', 15, '5%');
|
||||
INSERT INTO time_offers(start, end, code, type, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, '12:00:00', '13:00:00', '10%');
|
||||
INSERT INTO speed_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null,5,'25%',10,'15%',15,'10%' );
|
||||
INSERT INTO nu_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null,15,'25%',10,'15%',5,'10%' );
|
||||
|
||||
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','admin','admin', TRUE );
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','admin','admin', TRUE );
|
||||
INSERT INTO authorities VALUES ('admin','admin');
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','manoli','manoli', TRUE );
|
||||
INSERT INTO authorities VALUES ('manoli','cliente');
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','david','david', TRUE );
|
||||
INSERT INTO authorities VALUES ('david','cliente');
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','paco','paco', TRUE );
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','manoli','manoli', TRUE );
|
||||
|
||||
INSERT INTO authorities VALUES ('manoli','client');
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','david','david', TRUE );
|
||||
INSERT INTO authorities VALUES ('david','client');
|
||||
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','paco','paco', TRUE );
|
||||
INSERT INTO authorities VALUES ('paco','usuario');
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','lolo','lolo', TRUE );
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','lolo','lolo', TRUE );
|
||||
INSERT INTO authorities VALUES ('lolo','usuario');
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','pepe','pepe', TRUE );
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','pepe','pepe', TRUE );
|
||||
INSERT INTO authorities VALUES ('pepe','usuario');
|
||||
|
||||
INSERT INTO usuarios VALUES (1, 'admin', 'admin', 'admin', 'C/admin', '000000000', 'admin@gmail.com','admin');
|
||||
|
||||
INSERT INTO clients VALUES (1,'manoli@gmail.com','C/Betis','10:00','22:00','608726190', 'description 1', 'code1', 'ESPAÑOLA','manoli');
|
||||
INSERT INTO clients VALUES (2,'david@gmail.com','C/Sevilla','09:30','22:00','608726190', 'description 2', 'code2', 'americana','david');
|
||||
|
||||
INSERT INTO usuarios VALUES (2, 'Paco', 'Naranjo', '21154416G', 'C/Esperanza', '666973647', 'Paco@gmail.com','paco');
|
||||
INSERT INTO usuarios VALUES (3, 'Lolo', 'Lopez', '25486596L', 'C/Macarena', '690670547' ,'Lolo@gmail.com','lolo');
|
||||
INSERT INTO usuarios 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','22: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','22:00','608726190', 'description 2', 'code2', 'americana','david');
|
||||
|
||||
INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'FO-1', 'inactive', 1, 'macarrones', 15);
|
||||
INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'T-1', 'active', 1, '12:00:00', '13:00:00', 10);
|
||||
INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'SP-1', 'active',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-06-15 12:00:00', '2021-06-16 12:00:00', 'NU-1', 'active',1,15,25,10,15,5,10);
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
welcome=Welcome
|
||||
welcome=Welcome to
|
||||
listOffers=List Offers
|
||||
|
||||
required=is required
|
||||
notFound=has not been found
|
||||
duplicate=is already in use
|
||||
|
|
|
@ -1,8 +1,34 @@
|
|||
welcome=Bienvenido a
|
||||
required=Es requerido
|
||||
listOffers=Ver Ofertas
|
||||
foodOffers=Ofertas por plato especifico
|
||||
foodOffer=Oferta por plato especifico
|
||||
nuOffers=Ofertas por numero de comensales
|
||||
nuOffer=Oferta por numero de comensales
|
||||
speedOffers=Ofertas rapidez comiendo
|
||||
speedOffer=Oferta por comer veloz
|
||||
timeOffers=Ofertas por franja horaria
|
||||
timeOffer=Oferta por franja horaria
|
||||
food=Plato
|
||||
foodInOffer=Plato en oferta
|
||||
cuantity=Cantidad
|
||||
discount=Descuento
|
||||
goldGoal=Meta oro
|
||||
goldDiscount=Descuento oro
|
||||
silverGoal=Meta plata
|
||||
silverDiscount=Descuento plata
|
||||
bronzeGoal=Meta bronce
|
||||
bronzeDiscount=Descuento bronce
|
||||
startDate=Fecha inicio
|
||||
offerBeginning=Inicio de la oferta
|
||||
endDate=Fecha fin
|
||||
offerEnding=Fin de la oferta
|
||||
details=Detalles
|
||||
offerCode=Codigo de la oferta
|
||||
return=Volver
|
||||
required=Es requeridOfertas por franja horariao
|
||||
notFound=No ha sido encontrado
|
||||
duplicate=Ya se encuentra en uso
|
||||
nonNumeric=Sólo debe contener numeros
|
||||
duplicateFormSubmission=No se permite el envío de formularios duplicados
|
||||
typeMismatch.date=Fecha invalida
|
||||
typeMismatch.birthDate=Fecha invalida
|
||||
typeMismatch.birthDate=Fecha invalida
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<cheapy:layout pageName="error">
|
||||
|
||||
<h2>Algo malo ha pasado...</h2>
|
||||
<h2 style="text-align:center">Algo malo ha pasado...</h2>
|
||||
|
||||
<spring:url value="/resources/images/Logo Cheapy.png" htmlEscape="true" var="cheapyImage"/>
|
||||
<img class="img-responsive" src="${cheapyImage}"/>
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<cheapy:layout pageName="foodOffer">
|
||||
|
||||
<h2>Oferta por plato específico</h2>
|
||||
|
||||
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>Inicio de la oferta</th>
|
||||
<td><b><c:out value="${foodOffer.start}"/></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Fin de la oferta</th>
|
||||
<td><c:out value="${foodOffer.end}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Plato en oferta</th>
|
||||
<td><c:out value="${foodOffer.food}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Descuento</th>
|
||||
<td><c:out value="${foodOffer.discount}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Cantidad</th>
|
||||
<td><c:out value="${foodOffer.units}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Codigo de la oferta</th>
|
||||
<td><c:out value="${foodOffer.code}"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<%-- <spring:url value="{ownerId}/edit" var="editUrl">
|
||||
<spring:param name="ownerId" value="${owner.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Edit Owner</a> --%>
|
||||
|
||||
</cheapy:layout>
|
|
@ -1,56 +0,0 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<cheapy:layout pageName="nuOffer">
|
||||
|
||||
<h2>Oferta por número de comensales</h2>
|
||||
|
||||
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>Inicio de la oferta</th>
|
||||
<td><b><c:out value="${nuOffer.start}"/></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Fin de la oferta</th>
|
||||
<td><c:out value="${nuOffer.end}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Meta oro</th>
|
||||
<td><c:out value="${nuOffer.gold}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Descuento oro</th>
|
||||
<td><c:out value="${nuOffer.discountGold}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Meta plata</th>
|
||||
<td><c:out value="${nuOffer.silver}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Descuento plata</th>
|
||||
<td><c:out value="${nuOffer.discountSilver}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Meta bronce</th>
|
||||
<td><c:out value="${nuOffer.bronze}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Descuento bronce</th>
|
||||
<td><c:out value="${nuOffer.discountBronze}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Codigo de la oferta</th>
|
||||
<td><c:out value="${nuOffer.code}"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<%-- <spring:url value="{ownerId}/edit" var="editUrl">
|
||||
<spring:param name="ownerId" value="${owner.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Edit Owner</a> --%>
|
||||
|
||||
</cheapy:layout>
|
|
@ -12,18 +12,23 @@
|
|||
</h2>
|
||||
<form:form modelAttribute="foodOffer" class="form-horizontal" id="add-foodOffer-form">
|
||||
<div class="form-group has-feedback">
|
||||
<form:hidden path="id"/>
|
||||
<form:hidden path="code"/>
|
||||
<form:hidden path="status"/>
|
||||
<petclinic:inputField label="Start Date" name="start"/>
|
||||
<petclinic:inputField label="End Date" name="end"/>
|
||||
<petclinic:inputField label="Food" name="food"/>
|
||||
<petclinic:inputField label="Discount" name="discount"/>
|
||||
<petclinic:inputField label="Units" name="units"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<c:choose>
|
||||
<c:when test="${foodOffer['new']}">
|
||||
<button class="btn btn-default" type="submit">Add Food Offer</button>
|
||||
<button class="btn btn-default" type="submit">Crear oferta</button>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<button class="btn btn-default" type="submit">Modificar</button>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,23 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true"%>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags"%>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
|
||||
|
||||
<petclinic:layout pageName="foodOffer">
|
||||
|
||||
<jsp:body>
|
||||
<h2> ¿Esta seguro de que quiere eliminar su oferta? </h2>
|
||||
|
||||
<form:form modelAttribute="foodOffer" class="form-horizontal">
|
||||
<input type="hidden" name="food" value="${food_offer.food}" />
|
||||
<input type="hidden" name="discount" value="${food_offer.discount}" />
|
||||
|
||||
<button class="btn btn-default" type="submit">Eliminar Oferta</button>
|
||||
</form:form>
|
||||
|
||||
<a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a>
|
||||
|
||||
</jsp:body>
|
||||
</petclinic:layout>
|
58
src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp
Normal file
58
src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp
Normal file
|
@ -0,0 +1,58 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
|
||||
|
||||
<cheapy:layout pageName="foodOffer">
|
||||
|
||||
|
||||
<h2 style="text-align:center;padding:5px"><fmt:message key="foodOffer"/></h2>
|
||||
|
||||
|
||||
|
||||
<table class="table table-striped" id="foodOfferTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><fmt:message key="offerBeginning"/></th>
|
||||
<td><c:out value="${localDateTimeFormat.format(foodOffer.start)}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="offerEnding"/></th>
|
||||
<td><c:out value="${localDateTimeFormat.format(foodOffer.end)}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="foodInOffer"/></th>
|
||||
<td><c:out value="${foodOffer.food}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="discount"/></th>
|
||||
<td><c:out value="${foodOffer.discount}"/></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><fmt:message key="offerCode"/></th>
|
||||
<td><c:out value="${foodOffer.code}"/></td>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
<div class="btn-return">
|
||||
<button type="button" role="link" onclick="window.location='/offers'" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="return"/> </button>
|
||||
</div>
|
||||
|
||||
<spring:url value="{foodOfferId}/edit" var="editUrl">
|
||||
<spring:param name="foodOfferId" value="${foodOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar oferta</a>
|
||||
|
||||
<spring:url value="{foodOfferId}/disable" var="editUrl">
|
||||
<spring:param name="foodOfferId" value="${foodOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar oferta</a>
|
||||
|
||||
</cheapy:layout>
|
158
src/main/webapp/WEB-INF/jsp/offers/myOffersList.jsp
Normal file
158
src/main/webapp/WEB-INF/jsp/offers/myOffersList.jsp
Normal file
|
@ -0,0 +1,158 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
|
||||
|
||||
<cheapy:layout pageName="myOffers">
|
||||
<h2 style="text-align:center;padding:5px"><fmt:message key="foodOffers"/></h2>
|
||||
|
||||
<table id="foodOfferTable" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<!-- <th style="width: 150px;">Restaurante</th> -->
|
||||
<th><fmt:message key="food"/></th>
|
||||
<th><fmt:message key="startDate"/></th>
|
||||
<th><fmt:message key="endDate"/></th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="${foodOfferLs}" var="foodOffer">
|
||||
<tr>
|
||||
<td>
|
||||
<c:out value="${foodOffer.food}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${localDateTimeFormat.format(foodOffer.start)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${localDateTimeFormat.format(foodOffer.end)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<spring:url value="/offers/food/{foodOfferId}" var="foodOfferUrl">
|
||||
<spring:param name="foodOfferId" value="${foodOffer.id}"/>
|
||||
</spring:url>
|
||||
<div class="btn-detalles">
|
||||
<button type="button" role="link" onclick="window.location='${fn:escapeXml(foodOfferUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-info-sign" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="details"/></button>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2 style="text-align:center;padding:5px"><fmt:message key="nuOffers"/></h2>
|
||||
|
||||
<table id="nuOfferTable" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<!-- <th style="width: 150px;">Restaurante</th> -->
|
||||
<th><fmt:message key="startDate"/></th>
|
||||
<th><fmt:message key="endDate"/></th>
|
||||
<th> </th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="${nuOfferLs}" var="nuOffer">
|
||||
<tr>
|
||||
|
||||
<td>
|
||||
<c:out value="${localDateTimeFormat.format(nuOffer.start)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${localDateTimeFormat.format(nuOffer.end)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<spring:url value="/offers/nu/{nuOfferId}" var="nuOfferUrl">
|
||||
<spring:param name="nuOfferId" value="${nuOffer.id}"/>
|
||||
</spring:url>
|
||||
<div class="btn-detalles">
|
||||
<button type="button" role="link" onclick="window.location='${fn:escapeXml(nuOfferUrl)}'" class="btn-detalles" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-info-sign" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="details"/> </button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2 style="text-align:center;padding:5px"><fmt:message key="speedOffers"/></h2>
|
||||
|
||||
<table id="speedOfferTable" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<!-- <th style="width: 150px;">Restaurante</th> -->
|
||||
<th><fmt:message key="startDate"/></th>
|
||||
<th><fmt:message key="endDate"/></th>
|
||||
<th> </th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="${speedOfferLs}" var="speedOffer">
|
||||
<tr>
|
||||
|
||||
<td>
|
||||
<c:out value="${localDateTimeFormat.format(speedOffer.start)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${localDateTimeFormat.format(speedOffer.end)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<spring:url value="/offers/speed/{speedOfferId}" var="speedOfferUrl">
|
||||
<spring:param name="speedOfferId" value="${speedOffer.id}"/>
|
||||
</spring:url>
|
||||
<div class="btn-detalles">
|
||||
<button type="button" role="link" onclick="window.location='${fn:escapeXml(speedOfferUrl)}'" class="btn-detalles" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-info-sign" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="details"/> </button>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2 style="text-align:center;padding:5px"><fmt:message key="timeOffers"/></h2>
|
||||
|
||||
<table id="timeOfferTable" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<!-- <th style="width: 150px;">Restaurante</th> -->
|
||||
<th><fmt:message key="startDate"/></th>
|
||||
<th><fmt:message key="endDate"/></th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="${timeOfferLs}" var="timeOffer">
|
||||
<tr>
|
||||
|
||||
<td>
|
||||
<c:out value="${localDateTimeFormat.format(timeOffer.start)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${localDateTimeFormat.format(timeOffer.end)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<spring:url value="/offers/time/{timeOfferId}" var="timeOfferUrl">
|
||||
<spring:param name="timeOfferId" value="${timeOffer.id}"/>
|
||||
</spring:url>
|
||||
<div class="btn-detalles">
|
||||
<button type="button" role="link" onclick="window.location='${fn:escapeXml(timeOfferUrl)}'" class="btn-detalles" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-info-sign" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="details"/> </button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
</cheapy:layout>
|
|
@ -12,6 +12,9 @@
|
|||
</h2>
|
||||
<form:form modelAttribute="nuOffer" class="form-horizontal" id="add-nuOffer-form">
|
||||
<div class="form-group has-feedback">
|
||||
<form:hidden path="id"/>
|
||||
<form:hidden path="code"/>
|
||||
<form:hidden path="status"/>
|
||||
<petclinic:inputField label="Fecha de inicio" name="start"/>
|
||||
<petclinic:inputField label="Fecha de fin" name="end"/>
|
||||
|
||||
|
@ -27,10 +30,10 @@
|
|||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<c:choose>
|
||||
<c:when test="${nuOffer['new']}">
|
||||
<button class="btn btn-default" type="submit">Add Offer</button>
|
||||
<button class="btn btn-default" type="submit">Crear oferta</button>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<button class="btn btn-default" type="submit">Update Offer</button>
|
||||
<button class="btn btn-default" type="submit">Modificar</button>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
</div>
|
27
src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp
Normal file
27
src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp
Normal file
|
@ -0,0 +1,27 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true"%>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags"%>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
|
||||
|
||||
<petclinic:layout pageName="nuOffer">
|
||||
|
||||
<jsp:body>
|
||||
<h2> ¿Esta seguro de que quiere dar de baja su offer? </h2>
|
||||
|
||||
<form:form modelAttribute="nuOffer" class="form-horizontal">
|
||||
<input type="hidden" name="gold" value="${nu_offer.gold}" />
|
||||
<input type="hidden" name="discountGold" value="${nu_offer.discount_gold}" />
|
||||
<input type="hidden" name="silver" value="${nu_offer.silver}" />
|
||||
<input type="hidden" name="discountSilver" value="${nu_offer.discount_silver}" />
|
||||
<input type="hidden" name="bronze" value="${nu_offer.bronze}" />
|
||||
<input type="hidden" name="discountBronze" value="${nu_offer.discount_bronze}" />
|
||||
|
||||
<button class="btn btn-default" type="submit">Dar de baja</button>
|
||||
</form:form>
|
||||
|
||||
<a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a>
|
||||
|
||||
</jsp:body>
|
||||
</petclinic:layout>
|
69
src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp
Normal file
69
src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp
Normal file
|
@ -0,0 +1,69 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
|
||||
|
||||
<cheapy:layout pageName="nuOffer">
|
||||
|
||||
<h2 style="text-align:center;padding:5px"><fmt:message key="nuOffer"/></h2>
|
||||
|
||||
|
||||
<table class="table table-striped" id="nuOffer-table">
|
||||
<tr>
|
||||
<th><fmt:message key="offerBeginning"/></th>
|
||||
<td><c:out value="${localDateTimeFormat.format(nuOffer.start)}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="offerEnding"/></th>
|
||||
<td><c:out value="${localDateTimeFormat.format(nuOffer.end)}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="goldGoal"/></th>
|
||||
<td><c:out value="${nuOffer.gold}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="goldDiscount"/></th>
|
||||
<td><c:out value="${nuOffer.discountGold}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="silverGoal"/></th>
|
||||
<td><c:out value="${nuOffer.silver}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="silverDiscount"/></th>
|
||||
<td><c:out value="${nuOffer.discountSilver}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Meta bronce</th>
|
||||
<td><c:out value="${nuOffer.bronze}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="bronzeDiscount"/></th>
|
||||
<td><c:out value="${nuOffer.discountBronze}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="offerCode"/></th>
|
||||
<td><c:out value="${nuOffer.code}"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="btn-return">
|
||||
<button type="button" role="link" onclick="window.location='/offers'" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="return"/> </button>
|
||||
</div>
|
||||
|
||||
<spring:url value="{nuOfferId}/edit" var="editUrl">
|
||||
<spring:param name="nuOfferId" value="${nuOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar oferta</a>
|
||||
|
||||
<spring:url value="{nuOfferId}/disable" var="editUrl">
|
||||
<spring:param name="nuOfferId" value="${nuOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar oferta</a>
|
||||
|
||||
</cheapy:layout>
|
|
@ -4,17 +4,18 @@
|
|||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
|
||||
|
||||
<cheapy:layout pageName="owners">
|
||||
<h2>Ofertas por plato específico</h2>
|
||||
<cheapy:layout pageName="ofertas">
|
||||
<h2 style="text-align:center;padding:5px"><fmt:message key="foodOffers"/></h2>
|
||||
|
||||
<table id="foodOfferTable" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<!-- <th style="width: 150px;">Restaurante</th> -->
|
||||
<th style="width: 150px;">Plato</th>
|
||||
<th style="width: 150px;">Fecha inicio</th>
|
||||
<th style="width: 200px;">Fecha fin</th>
|
||||
<th><fmt:message key="food"/></th>
|
||||
<th><fmt:message key="startDate"/></th>
|
||||
<th><fmt:message key="endDate"/></th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -25,16 +26,20 @@
|
|||
<c:out value="${foodOffer.food}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${foodOffer.start}"/>
|
||||
<c:out value="${localDateTimeFormat.format(foodOffer.start)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${foodOffer.end}"/>
|
||||
<c:out value="${localDateTimeFormat.format(foodOffer.end)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<spring:url value="/offers/food/{foodOfferId}" var="foodOfferUrl">
|
||||
<spring:param name="foodOfferId" value="${foodOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(foodOfferUrl)}"/>Enlace</a>
|
||||
<spring:url value="/offers/food/{foodOfferId}" var="foodOfferUrl">
|
||||
<spring:param name="foodOfferId" value="${foodOffer.id}"/>
|
||||
</spring:url>
|
||||
<div class="btn-detalles">
|
||||
<button type="button" role="link" onclick="window.location='${fn:escapeXml(foodOfferUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-info-sign" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="details"/></button>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
@ -42,14 +47,14 @@
|
|||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2>Ofertas por número de comensales</h2>
|
||||
<h2 style="text-align:center;padding:5px"><fmt:message key="nuOffers"/></h2>
|
||||
|
||||
<table id="nuOfferTable" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<!-- <th style="width: 150px;">Restaurante</th> -->
|
||||
<th style="width: 150px;">Fecha inicio</th>
|
||||
<th style="width: 200px;">Fecha fin</th>
|
||||
<th><fmt:message key="startDate"/></th>
|
||||
<th><fmt:message key="endDate"/></th>
|
||||
<th> </th>
|
||||
|
||||
</tr>
|
||||
|
@ -59,29 +64,33 @@
|
|||
<tr>
|
||||
|
||||
<td>
|
||||
<c:out value="${nuOffer.start}"/>
|
||||
<c:out value="${localDateTimeFormat.format(nuOffer.start)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${nuOffer.end}"/>
|
||||
<c:out value="${localDateTimeFormat.format(nuOffer.end)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<spring:url value="/offers/nu/{nuOfferId}" var="nuOfferUrl">
|
||||
<spring:param name="nuOfferId" value="${nuOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(nuOfferUrl)}"/>Enlace</a>
|
||||
<spring:url value="/offers/nu/{nuOfferId}" var="nuOfferUrl">
|
||||
<spring:param name="nuOfferId" value="${nuOffer.id}"/>
|
||||
</spring:url>
|
||||
<div class="btn-detalles">
|
||||
<button type="button" role="link" onclick="window.location='${fn:escapeXml(nuOfferUrl)}'" class="btn-detalles" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-info-sign" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="details"/> </button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2>Ofertas rapidez comiendo</h2>
|
||||
<h2 style="text-align:center;padding:5px"><fmt:message key="speedOffers"/></h2>
|
||||
|
||||
<table id="speedOfferTable" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<!-- <th style="width: 150px;">Restaurante</th> -->
|
||||
<th style="width: 150px;">Fecha inicio</th>
|
||||
<th style="width: 200px;">Fecha fin</th>
|
||||
<th><fmt:message key="startDate"/></th>
|
||||
<th><fmt:message key="endDate"/></th>
|
||||
<th> </th>
|
||||
|
||||
</tr>
|
||||
|
@ -91,30 +100,34 @@
|
|||
<tr>
|
||||
|
||||
<td>
|
||||
<c:out value="${speedOffer.start}"/>
|
||||
<c:out value="${localDateTimeFormat.format(speedOffer.start)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${speedOffer.end}"/>
|
||||
<c:out value="${localDateTimeFormat.format(speedOffer.end)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<spring:url value="/offers/speed/{speedOfferId}" var="speedOfferUrl">
|
||||
<spring:param name="speedOfferId" value="${speedOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(speedOfferUrl)}"/>Enlace</a>
|
||||
<div class="btn-detalles">
|
||||
<button type="button" role="link" onclick="window.location='${fn:escapeXml(speedOfferUrl)}'" class="btn-detalles" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-info-sign" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="details"/> </button>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2>Ofertas por franja horaria</h2>
|
||||
<h2 style="text-align:center;padding:5px"><fmt:message key="timeOffers"/></h2>
|
||||
|
||||
<table id="timeOfferTable" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<!-- <th style="width: 150px;">Restaurante</th> -->
|
||||
<th style="width: 150px;">Fecha inicio</th>
|
||||
<th style="width: 200px;">Fecha fin</th>
|
||||
<th><fmt:message key="startDate"/></th>
|
||||
<th><fmt:message key="endDate"/></th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -123,16 +136,20 @@
|
|||
<tr>
|
||||
|
||||
<td>
|
||||
<c:out value="${timeOffer.start}"/>
|
||||
<c:out value="${localDateTimeFormat.format(timeOffer.start)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${timeOffer.end}"/>
|
||||
<c:out value="${localDateTimeFormat.format(timeOffer.end)}"/>
|
||||
</td>
|
||||
<td>
|
||||
<spring:url value="/offers/time/{timeOfferId}" var="timeOfferUrl">
|
||||
<spring:url value="/offers/time/{timeOfferId}" var="timeOfferUrl">
|
||||
<spring:param name="timeOfferId" value="${timeOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(timeOfferUrl)}"/>Enlace</a>
|
||||
<div class="btn-detalles">
|
||||
<button type="button" role="link" onclick="window.location='${fn:escapeXml(timeOfferUrl)}'" class="btn-detalles" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-info-sign" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="details"/> </button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
</h2>
|
||||
<form:form modelAttribute="speedOffer" class="form-horizontal" id="add-speedOffer-form">
|
||||
<div class="form-group has-feedback">
|
||||
<form:hidden path="id"/>
|
||||
<form:hidden path="code"/>
|
||||
<form:hidden path="status"/>
|
||||
<petclinic:inputField label="Start Date" name="start"/>
|
||||
<petclinic:inputField label="End Date" name="end"/>
|
||||
<petclinic:inputField label="Gold" name="gold"/>
|
||||
|
@ -25,8 +28,11 @@
|
|||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<c:choose>
|
||||
<c:when test="${speedOffer['new']}">
|
||||
<button class="btn btn-default" type="submit">Add Speed Offer</button>
|
||||
<button class="btn btn-default" type="submit">Crear oferta</button>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<button class="btn btn-default" type="submit">Modificar</button>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,27 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true"%>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags"%>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
|
||||
|
||||
<petclinic:layout pageName="speedOffer">
|
||||
|
||||
<jsp:body>
|
||||
<h2> ¿Esta seguro de que quiere dar de baja su offer? </h2>
|
||||
|
||||
<form:form modelAttribute="speedOffer" class="form-horizontal">
|
||||
<input type="hidden" name="gold" value="${nu_offer.gold}" />
|
||||
<input type="hidden" name="discountGold" value="${nu_offer.discount_gold}" />
|
||||
<input type="hidden" name="silver" value="${nu_offer.silver}" />
|
||||
<input type="hidden" name="discountSilver" value="${nu_offer.discount_silver}" />
|
||||
<input type="hidden" name="bronze" value="${nu_offer.bronze}" />
|
||||
<input type="hidden" name="discountBronze" value="${nu_offer.discount_bronze}" />
|
||||
|
||||
<button class="btn btn-default" type="submit">Dar de baja</button>
|
||||
</form:form>
|
||||
|
||||
<a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a>
|
||||
|
||||
</jsp:body>
|
||||
</petclinic:layout>
|
69
src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp
Normal file
69
src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp
Normal file
|
@ -0,0 +1,69 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
|
||||
|
||||
<cheapy:layout pageName="speedOffer">
|
||||
|
||||
<h2 style="text-align:center;padding:5px"><fmt:message key="speedOffer"/></h2>
|
||||
|
||||
|
||||
<table class="table table-striped" id="speedOffer-table">
|
||||
<tr>
|
||||
<th><fmt:message key="offerBeginning"/></th>
|
||||
<td><c:out value="${localDateTimeFormat.format(speedOffer.start)}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="offerEnding"/></th>
|
||||
<td><c:out value="${localDateTimeFormat.format(speedOffer.end)}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="goldGoal"/></th>
|
||||
<td><c:out value="${speedOffer.gold}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="goldDiscount"/></th>
|
||||
<td><c:out value="${speedOffer.discountGold}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="silverGoal"/></th>
|
||||
<td><c:out value="${speedOffer.silver}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="silverDiscount"/></th>
|
||||
<td><c:out value="${speedOffer.discountSilver}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="bronzeGoal"/></th>
|
||||
<td><c:out value="${speedOffer.bronze}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="bronzeDiscount"/></th>
|
||||
<td><c:out value="${speedOffer.discountBronze}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="offerCode"/></th>
|
||||
<td><c:out value="${speedOffer.code}"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="btn-return">
|
||||
<button type="button" role="link" onclick="window.location='/offers'" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="return"/> </button>
|
||||
</div>
|
||||
|
||||
<spring:url value="{speedOfferId}/edit" var="editUrl">
|
||||
<spring:param name="speedOfferId" value="${speedOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar oferta</a>
|
||||
|
||||
<spring:url value="{speedOfferId}/disable" var="editUrl">
|
||||
<spring:param name="speedOfferId" value="${speedOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar oferta</a>
|
||||
|
||||
</cheapy:layout>
|
|
@ -12,12 +12,16 @@
|
|||
</h2>
|
||||
<form:form modelAttribute="timeOffer" class="form-horizontal" id="add-timeOffer-form">
|
||||
<div class="form-group has-feedback">
|
||||
<form:hidden path="id"/>
|
||||
<form:hidden path="code"/>
|
||||
<form:hidden path="status"/>
|
||||
<petclinic:inputField label="Fecha de inicio" name="start"/>
|
||||
<petclinic:inputField label="Fecha de fin" name="end"/>
|
||||
|
||||
<petclinic:inputField label="Hora de inicio" name="init"/>
|
||||
<petclinic:inputField label="Hora de final" name="finish"/>
|
||||
<petclinic:inputField label="Decuento" name="discount"/>
|
||||
<petclinic:inputField label="Descuento" name="discount"/>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
|
@ -0,0 +1,24 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true"%>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags"%>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
|
||||
|
||||
<petclinic:layout pageName="foodOffer">
|
||||
|
||||
<jsp:body>
|
||||
<h2> ¿Esta seguro de que quiere eliminar su oferta? </h2>
|
||||
|
||||
<form:form modelAttribute="foodOffer" class="form-horizontal">
|
||||
<input type="hidden" name="init" value="${time_offer.init}" />
|
||||
<input type="hidden" name="finish" value="${time_offer.finish}" />
|
||||
<input type="hidden" name="discount" value="${time_offer.discount}" />
|
||||
|
||||
<button class="btn btn-default" type="submit">Eliminar Oferta</button>
|
||||
</form:form>
|
||||
|
||||
<a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a>
|
||||
|
||||
</jsp:body>
|
||||
</petclinic:layout>
|
51
src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp
Normal file
51
src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp
Normal file
|
@ -0,0 +1,51 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet'>
|
||||
|
||||
<cheapy:layout pageName="timeOffer">
|
||||
|
||||
<h2 style="text-align:center;padding:5px"><fmt:message key="timeOffer"/></h2>
|
||||
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><fmt:message key="offerBeginning"/></th>
|
||||
<td><c:out value="${localDateTimeFormat.format(timeOffer.start)}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="offerEnding"/></th>
|
||||
<td><c:out value="${localDateTimeFormat.format(timeOffer.end)}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="discount"/></th>
|
||||
<td><c:out value="${timeOffer.discount}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="offerCode"/></th>
|
||||
<td><c:out value="${timeOffer.code}"/></td>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
<spring:url value="{timeOfferId}/edit" var="editUrl">
|
||||
<spring:param name="timeOfferId" value="${timeOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Editar oferta</a>
|
||||
|
||||
<spring:url value="{timeOfferId}/disable" var="editUrl">
|
||||
<spring:param name="timeOfferId" value="${timeOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Desactivar oferta</a>
|
||||
|
||||
<div class="btn-return">
|
||||
<button type="button" role="link" onclick="window.location='/offers'" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="return"/> </button>
|
||||
</div>
|
||||
|
||||
</cheapy:layout>
|
|
@ -1,56 +0,0 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<cheapy:layout pageName="speedOffer">
|
||||
|
||||
<h2>Oferta por comer veloz</h2>
|
||||
|
||||
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>Inicio de la oferta</th>
|
||||
<td><b><c:out value="${speedOffer.start}"/></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Fin de la oferta</th>
|
||||
<td><c:out value="${speedOffer.end}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Meta oro</th>
|
||||
<td><c:out value="${speedOffer.gold}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Descuento oro</th>
|
||||
<td><c:out value="${speedOffer.discountGold}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Meta plata</th>
|
||||
<td><c:out value="${speedOffer.silver}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Descuento plata</th>
|
||||
<td><c:out value="${speedOffer.discountSilver}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Meta bronce</th>
|
||||
<td><c:out value="${speedOffer.bronze}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Descuento bronce</th>
|
||||
<td><c:out value="${speedOffer.discountBronze}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Codigo de la oferta</th>
|
||||
<td><c:out value="${speedOffer.code}"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<%-- <spring:url value="{ownerId}/edit" var="editUrl">
|
||||
<spring:param name="ownerId" value="${owner.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(editUrl)}" class="btn btn-default">Edit Owner</a> --%>
|
||||
|
||||
</cheapy:layout>
|
|
@ -1,31 +0,0 @@
|
|||
<%@ page session="false" trimDirectiveWhitespaces="true" %>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<cheapy:layout pageName="timeOffer">
|
||||
|
||||
<h2>Oferta por franja horária</h2>
|
||||
|
||||
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>Inicio de la oferta</th>
|
||||
<td><b><c:out value="${timeOffer.start}"/></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Fin de la oferta</th>
|
||||
<td><c:out value="${timeOffer.end}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Descuento</th>
|
||||
<td><c:out value="${timeOffer.discount}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Codigo de la oferta</th>
|
||||
<td><c:out value="${timeOffer.code}"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</cheapy:layout>
|
|
@ -6,7 +6,7 @@
|
|||
<!-- %@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %-->
|
||||
|
||||
<cheapy:layout pageName="home">
|
||||
<h2 class="text-center" style="font-family: 'Lobster'; font-size: 50px; color: rgb(0, 64, 128); padding:20px"><fmt:message key="welcome"/></h2>
|
||||
<h2 class="text-center" style="font-family: 'Lobster'; font-size: 60px; color: rgb(0, 64, 128); padding:30px"><fmt:message key="welcome"/></h2>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="img-home">
|
||||
|
@ -14,8 +14,9 @@
|
|||
<img class="img-responsive" src="${cheapyImage}"/>
|
||||
</div>
|
||||
<div class="btn-home">
|
||||
<button type="button"><span class="glyphicon glyphicon-cutlery" aria-hidden="true" style="padding: 5px"></span> Ver Ofertas</button>
|
||||
|
||||
<button type="button" role="link" onclick="window.location='/offers'" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon-cutlery" aria-hidden="true" style="padding: 5px"> </span>
|
||||
<fmt:message key="listOffers"/> </button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<cheapy:menuItem active="${name eq 'home'}" url="/"
|
||||
title="home page">
|
||||
<span class="glyphicon glyphicon-home" aria-hidden="true"></span>
|
||||
<span>Home</span>
|
||||
<span>Inicio</span>
|
||||
</cheapy:menuItem>
|
||||
|
||||
<cheapy:menuItem active="${name eq 'ofertas'}" url="/offers"
|
||||
|
@ -34,12 +34,19 @@
|
|||
<span>Ver ofertas</span>
|
||||
</cheapy:menuItem>
|
||||
|
||||
<sec:authorize access="hasAnyAuthority('client')">
|
||||
<cheapy:menuItem active="${name eq 'ofertas'}" url="/myOffers" title="misOfertas">
|
||||
<span class="glyphicon glyphicon-cutlery" aria-hidden="true"></span>
|
||||
<span>Mis ofertas</span>
|
||||
</cheapy:menuItem>
|
||||
</sec:authorize>
|
||||
<!--
|
||||
<cheapy:menuItem active="${name eq 'contactanos'}" url="/contactanos"
|
||||
title="contactanos">
|
||||
<span class="glyphicon glyphicon-earphone" aria-hidden="true"></span>
|
||||
<span>Contáctanos</span>
|
||||
</cheapy:menuItem>
|
||||
|
||||
-->
|
||||
|
||||
|
||||
</ul>
|
||||
|
@ -48,7 +55,7 @@
|
|||
<ul class="nav navbar-nav navbar-right">
|
||||
<sec:authorize access="!isAuthenticated()">
|
||||
<li><a href="<c:url value="/login" />">Login</a></li>
|
||||
<li><a href="<c:url value="/users/new" />">Register</a></li>
|
||||
<!--<li><a href="<c:url value="/users/new" />">Register</a></li>-->
|
||||
</sec:authorize>
|
||||
<sec:authorize access="isAuthenticated()">
|
||||
<li class="dropdown"><a href="#" class="dropdown-toggle"
|
||||
|
@ -59,10 +66,10 @@
|
|||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<div class="navbar-login">
|
||||
<div class="row">
|
||||
<div class="col-lg-4">
|
||||
<div class="row" >
|
||||
<div class="col-lg-4" style="">
|
||||
<p class="text-center">
|
||||
<span class="glyphicon glyphicon-user icon-size"></span>
|
||||
<span class="glyphicon glyphicon-user icon-size" ></span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-lg-8">
|
||||
|
@ -71,7 +78,7 @@
|
|||
</p>
|
||||
<form action="/logout" method=post>
|
||||
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
|
||||
<input type="submit" value="logout">
|
||||
<input type="submit" value="logout" style="align-content:center;color:white;background-color:#004080;padding:10px; border:none; text-align:center">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12 text-center"><img src="<spring:url value="/resources/images/eslogan.png" htmlEscape="true" />"
|
||||
alt="Sponsored by Pivotal"/></div>
|
||||
alt="Eat fast, eat cheapy"/></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
package org.springframework.cheapy.web;
|
||||
|
||||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.cheapy.configuration.SecurityConfiguration;
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.model.FoodOffer;
|
||||
import org.springframework.cheapy.model.User;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.FoodOfferService;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
|
||||
|
||||
@WebMvcTest(value = FoodOfferController.class,
|
||||
excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = WebSecurityConfigurer.class),
|
||||
excludeAutoConfiguration = SecurityConfiguration.class)
|
||||
class FoodOfferControllerTest {
|
||||
|
||||
private static final int TEST_CLIENT_ID = 1;
|
||||
private static final int TEST_FOODOFFER_ID = 1;
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
private FoodOfferService foodOfferService;
|
||||
|
||||
@MockBean
|
||||
private ClientService clientService;
|
||||
|
||||
private FoodOffer fo1;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
User user1 = new User();
|
||||
user1.setUsername("user1");
|
||||
user1.setPassword("user1");
|
||||
Client client1 = new Client();;
|
||||
client1.setId(TEST_CLIENT_ID);
|
||||
client1.setName("client1");
|
||||
client1.setEmail("client1");
|
||||
client1.setAddress("client1");
|
||||
client1.setInit("01:00");
|
||||
client1.setFinish("01:01");
|
||||
client1.setTelephone("123456789");
|
||||
client1.setDescription("client1");
|
||||
client1.setCode("client1");
|
||||
client1.setFood("client1");
|
||||
client1.setUsuar(user1);
|
||||
BDDMockito.given(this.clientService.getCurrentClient()).willReturn(client1);
|
||||
|
||||
FoodOffer fo1test = new FoodOffer();
|
||||
fo1test.setId(TEST_FOODOFFER_ID);
|
||||
fo1test.setStart(LocalDateTime.of(2021, 12, 23, 12, 30));
|
||||
fo1test.setEnd(LocalDateTime.of(2022, 12, 23, 12, 30));
|
||||
fo1test.setFood("fo1test");
|
||||
fo1test.setDiscount(1);
|
||||
fo1test.setClient(client1);
|
||||
this.fo1 = fo1test;
|
||||
BDDMockito.given(this.foodOfferService.findFoodOfferById(TEST_FOODOFFER_ID)).willReturn(this.fo1);
|
||||
|
||||
}
|
||||
|
||||
@WithMockUser(value = "spring", authorities = "client")
|
||||
@Test
|
||||
void testInitCreationForm() throws Exception {
|
||||
mockMvc.perform(get("/offers/food/new"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(model().attributeExists("foodOffer"))
|
||||
.andExpect(view().name("offers/food/createOrUpdateFoodOfferForm"));
|
||||
}
|
||||
|
||||
@WithMockUser(value = "spring", authorities = "client")
|
||||
@Test
|
||||
void testProcessCreationFormSuccess() throws Exception {
|
||||
mockMvc.perform(post("/offers/food/new")
|
||||
.with(csrf())
|
||||
.param("start", "23/12/2021 12:30")
|
||||
.param("end", "23/12/2022 12:30")
|
||||
.param("food", "food")
|
||||
.param("discount", "10"))
|
||||
.andExpect(status().is3xxRedirection());
|
||||
}
|
||||
|
||||
@WithMockUser(value = "spring", authorities = "client")
|
||||
@Test
|
||||
void testProcessCreationFormHasErrors() throws Exception {
|
||||
mockMvc.perform(post("/offers/food/new")
|
||||
.with(csrf())
|
||||
.param("start", "lsqdufhlqhf")
|
||||
.param("end", "")
|
||||
.param("food", "")
|
||||
.param("discount", ""))
|
||||
.andExpect(model().attributeHasErrors("foodOffer"))
|
||||
.andExpect(model().attributeHasFieldErrors("foodOffer", "start"))
|
||||
.andExpect(model().attributeHasFieldErrors("foodOffer", "end"))
|
||||
.andExpect(model().attributeHasFieldErrors("foodOffer", "food"))
|
||||
.andExpect(model().attributeHasFieldErrors("foodOffer", "discount"))
|
||||
.andExpect(view().name("offers/food/createOrUpdateFoodOfferForm"));
|
||||
}
|
||||
|
||||
@WithMockUser(value = "user1", authorities = "client")
|
||||
@Test
|
||||
void testActivateSuccess() throws Exception {
|
||||
mockMvc.perform(get("/offers/food/{foodOfferId}/activate", TEST_FOODOFFER_ID))
|
||||
.andExpect(status().is3xxRedirection())
|
||||
.andExpect(view().name("redirect:/offers/food/"+TEST_FOODOFFER_ID));
|
||||
}
|
||||
|
||||
@WithMockUser(value = "user1", authorities = "client")
|
||||
@Test
|
||||
void testActivateHasErrors() throws Exception {
|
||||
mockMvc.perform(get("/offers/food/{foodOfferId}/activate", TEST_FOODOFFER_ID+1))
|
||||
.andExpect(view().name("exception"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
package org.springframework.cheapy.web;
|
||||
|
||||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.cheapy.configuration.SecurityConfiguration;
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.model.NuOffer;
|
||||
import org.springframework.cheapy.model.User;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.NuOfferService;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
@WebMvcTest(value = NuOfferController.class,
|
||||
excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = WebSecurityConfigurer.class),
|
||||
excludeAutoConfiguration = SecurityConfiguration.class)
|
||||
class NuOfferControllerTest {
|
||||
|
||||
private static final int TEST_CLIENT_ID = 1;
|
||||
private static final int TEST_NUOFFER_ID = 1;
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
private NuOfferService nuOfferService;
|
||||
|
||||
@MockBean
|
||||
private ClientService clientService;
|
||||
|
||||
private NuOffer nu1;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
User user1 = new User();
|
||||
user1.setUsername("user1");
|
||||
user1.setPassword("user1");
|
||||
Client client1 = new Client();
|
||||
client1.setId(TEST_CLIENT_ID);
|
||||
client1.setName("client1");
|
||||
client1.setEmail("client1");
|
||||
client1.setAddress("client1");
|
||||
client1.setInit("01:00");
|
||||
client1.setFinish("01:01");
|
||||
client1.setTelephone("123456789");
|
||||
client1.setDescription("client1");
|
||||
client1.setCode("client1");
|
||||
client1.setFood("client1");
|
||||
client1.setUsuar(user1);
|
||||
BDDMockito.given(this.clientService.getCurrentClient()).willReturn(client1);
|
||||
|
||||
NuOffer nu1test = new NuOffer();
|
||||
nu1test.setId(TEST_NUOFFER_ID);
|
||||
nu1test.setStart(LocalDateTime.of(2021, 12, 23, 12, 30));
|
||||
nu1test.setEnd(LocalDateTime.of(2022, 12, 23, 12, 30));
|
||||
nu1test.setGold(5);
|
||||
nu1test.setDiscountGold(15);
|
||||
nu1test.setSilver(10);
|
||||
nu1test.setDiscountSilver(10);
|
||||
nu1test.setBronze(15);
|
||||
nu1test.setDiscountBronze(5);
|
||||
nu1test.setClient(client1);
|
||||
this.nu1 = nu1test;
|
||||
BDDMockito.given(this.nuOfferService.findNuOfferById(TEST_NUOFFER_ID)).willReturn(this.nu1);
|
||||
}
|
||||
|
||||
@WithMockUser(value = "spring", authorities = "client")
|
||||
@Test
|
||||
void testInitCreationForm() throws Exception {
|
||||
mockMvc.perform(get("/offers/nu/new"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(model().attributeExists("nuOffer"))
|
||||
.andExpect(view().name("offers/nu/createOrUpdateNuOfferForm"));
|
||||
}
|
||||
|
||||
@WithMockUser(value = "spring", authorities = "client")
|
||||
@Test
|
||||
void testProcessCreationFormSuccess() throws Exception {
|
||||
mockMvc.perform(post("/offers/nu/new")
|
||||
.with(SecurityMockMvcRequestPostProcessors.csrf())
|
||||
.param("start", "23/12/2021 12:30")
|
||||
.param("end", "23/12/2022 12:30")
|
||||
.param("gold", "5")
|
||||
.param("discountGold", "15")
|
||||
.param("silver", "10")
|
||||
.param("discountSilver", "10")
|
||||
.param("bronze", "15")
|
||||
.param("discountBronze", "5"))
|
||||
.andExpect(status().is3xxRedirection());
|
||||
}
|
||||
|
||||
@WithMockUser(value = "spring", authorities = "client")
|
||||
@Test
|
||||
void testProcessCreationFormHasErrors() throws Exception {
|
||||
mockMvc.perform(post("/offers/nu/new")
|
||||
.with(csrf())
|
||||
.param("start", "lsqdufhlqhf")
|
||||
.param("end", "")
|
||||
.param("gold", "gold")
|
||||
.param("discountGold", "")
|
||||
.param("silver", "")
|
||||
.param("discountSilver", "")
|
||||
.param("bronze", "")
|
||||
.param("discountBronze", ""))
|
||||
.andExpect(model().attributeHasErrors("nuOffer"))
|
||||
.andExpect(model().attributeHasFieldErrors("nuOffer", "start"))
|
||||
.andExpect(model().attributeHasFieldErrors("nuOffer", "end"))
|
||||
.andExpect(model().attributeHasFieldErrors("nuOffer", "gold"))
|
||||
.andExpect(model().attributeHasFieldErrors("nuOffer", "discountGold"))
|
||||
.andExpect(model().attributeHasFieldErrors("nuOffer", "silver"))
|
||||
.andExpect(model().attributeHasFieldErrors("nuOffer", "discountSilver"))
|
||||
.andExpect(model().attributeHasFieldErrors("nuOffer", "bronze"))
|
||||
.andExpect(model().attributeHasFieldErrors("nuOffer", "discountBronze"))
|
||||
.andExpect(view().name("offers/nu/createOrUpdateNuOfferForm"));
|
||||
}
|
||||
|
||||
@WithMockUser(value = "user1", authorities = "client")
|
||||
@Test
|
||||
void testActivateSuccess() throws Exception {
|
||||
mockMvc.perform(get("/offers/nu/{nuOfferId}/activate", TEST_NUOFFER_ID))
|
||||
.andExpect(status().is3xxRedirection())
|
||||
.andExpect(view().name("redirect:/offers/nu/"+TEST_NUOFFER_ID));
|
||||
}
|
||||
|
||||
@WithMockUser(value = "user1", authorities = "client")
|
||||
@Test
|
||||
void testActivateHasErrors() throws Exception {
|
||||
mockMvc.perform(get("/offers/nu/{nuOfferId}/activate", TEST_NUOFFER_ID+1))
|
||||
.andExpect(view().name("exception"));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -160,6 +160,3 @@ class OwnerControllerTests {
|
|||
.andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023"))))
|
||||
.andExpect(view().name("owners/ownerDetails"));
|
||||
}*/
|
||||
|
||||
}
|
||||
*/
|
|
@ -0,0 +1,150 @@
|
|||
package org.springframework.cheapy.web;
|
||||
|
||||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.cheapy.configuration.SecurityConfiguration;
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.model.SpeedOffer;
|
||||
import org.springframework.cheapy.model.User;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.SpeedOfferService;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
|
||||
|
||||
@WebMvcTest(value = SpeedOfferController.class,
|
||||
excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = WebSecurityConfigurer.class),
|
||||
excludeAutoConfiguration = SecurityConfiguration.class)
|
||||
class SpeedOfferControllerTest {
|
||||
|
||||
private static final int TEST_CLIENT_ID = 1;
|
||||
private static final int TEST_SPEEDOFFER_ID = 1;
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
private SpeedOfferService speedOfferService;
|
||||
|
||||
@MockBean
|
||||
private ClientService clientService;
|
||||
|
||||
private SpeedOffer sp1;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
User user1 = new User();
|
||||
user1.setUsername("user1");
|
||||
user1.setPassword("user1");
|
||||
Client client1 = new Client();
|
||||
client1.setId(TEST_CLIENT_ID);
|
||||
client1.setName("client1");
|
||||
client1.setEmail("client1");
|
||||
client1.setAddress("client1");
|
||||
client1.setInit("01:00");
|
||||
client1.setFinish("01:01");
|
||||
client1.setTelephone("123456789");
|
||||
client1.setDescription("client1");
|
||||
client1.setCode("client1");
|
||||
client1.setFood("client1");
|
||||
client1.setUsuar(user1);
|
||||
BDDMockito.given(this.clientService.getCurrentClient()).willReturn(client1);
|
||||
|
||||
SpeedOffer sp1test = new SpeedOffer();
|
||||
sp1test.setId(TEST_SPEEDOFFER_ID);
|
||||
sp1test.setStart(LocalDateTime.of(2021, 12, 23, 12, 30));
|
||||
sp1test.setEnd(LocalDateTime.of(2022, 12, 23, 12, 30));
|
||||
sp1test.setGold(5);
|
||||
sp1test.setDiscountGold(15);
|
||||
sp1test.setSilver(10);
|
||||
sp1test.setDiscountSilver(10);
|
||||
sp1test.setBronze(15);
|
||||
sp1test.setDiscountBronze(5);
|
||||
sp1test.setClient(client1);
|
||||
this.sp1 = sp1test;
|
||||
BDDMockito.given(this.speedOfferService.findSpeedOfferById(TEST_SPEEDOFFER_ID)).willReturn(this.sp1);
|
||||
|
||||
}
|
||||
|
||||
@WithMockUser(value = "spring", authorities = "client")
|
||||
@Test
|
||||
void testInitCreationForm() throws Exception {
|
||||
mockMvc.perform(get("/offers/speed/new"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(model().attributeExists("speedOffer"))
|
||||
.andExpect(view().name("offers/speed/createOrUpdateSpeedOfferForm"));
|
||||
}
|
||||
|
||||
@WithMockUser(value = "spring", authorities = "client")
|
||||
@Test
|
||||
void testProcessCreationFormSuccess() throws Exception {
|
||||
mockMvc.perform(post("/offers/speed/new")
|
||||
.with(csrf())
|
||||
.param("start", "23/12/2021 12:30")
|
||||
.param("end", "23/12/2022 12:30")
|
||||
.param("gold", "5")
|
||||
.param("discountGold", "15")
|
||||
.param("silver", "10")
|
||||
.param("discountSilver", "10")
|
||||
.param("bronze", "15")
|
||||
.param("discountBronze", "5"))
|
||||
.andExpect(status().is3xxRedirection());
|
||||
}
|
||||
|
||||
@WithMockUser(value = "spring", authorities = "client")
|
||||
@Test
|
||||
void testProcessCreationFormHasErrors() throws Exception {
|
||||
mockMvc.perform(post("/offers/speed/new")
|
||||
.with(csrf())
|
||||
.param("start", "lsqdufhlqhf")
|
||||
.param("end", "")
|
||||
.param("gold", "gold")
|
||||
.param("discountGold", "")
|
||||
.param("silver", "")
|
||||
.param("discountSilver", "")
|
||||
.param("bronze", "")
|
||||
.param("discountBronze", ""))
|
||||
.andExpect(model().attributeHasErrors("speedOffer"))
|
||||
.andExpect(model().attributeHasFieldErrors("speedOffer", "start"))
|
||||
.andExpect(model().attributeHasFieldErrors("speedOffer", "end"))
|
||||
.andExpect(model().attributeHasFieldErrors("speedOffer", "gold"))
|
||||
.andExpect(model().attributeHasFieldErrors("speedOffer", "discountGold"))
|
||||
.andExpect(model().attributeHasFieldErrors("speedOffer", "silver"))
|
||||
.andExpect(model().attributeHasFieldErrors("speedOffer", "discountSilver"))
|
||||
.andExpect(model().attributeHasFieldErrors("speedOffer", "bronze"))
|
||||
.andExpect(model().attributeHasFieldErrors("speedOffer", "discountBronze"))
|
||||
.andExpect(view().name("offers/speed/createOrUpdateSpeedOfferForm"));
|
||||
}
|
||||
|
||||
@WithMockUser(value = "user1", authorities = "client")
|
||||
@Test
|
||||
void testActivateSuccess() throws Exception {
|
||||
mockMvc.perform(get("/offers/speed/{speedOfferId}/activate", TEST_SPEEDOFFER_ID))
|
||||
.andExpect(status().is3xxRedirection())
|
||||
.andExpect(view().name("redirect:/offers/speed/"+TEST_SPEEDOFFER_ID));
|
||||
}
|
||||
|
||||
@WithMockUser(value = "user1", authorities = "client")
|
||||
@Test
|
||||
void testActivateHasErrors() throws Exception {
|
||||
mockMvc.perform(get("/offers/speed/{speedOfferId}/activate", TEST_SPEEDOFFER_ID+1))
|
||||
.andExpect(view().name("exception"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
package org.springframework.cheapy.web;
|
||||
|
||||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.cheapy.configuration.SecurityConfiguration;
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.model.TimeOffer;
|
||||
import org.springframework.cheapy.model.User;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.TimeOfferService;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
@WebMvcTest(value = TimeOfferController.class,
|
||||
excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = WebSecurityConfigurer.class),
|
||||
excludeAutoConfiguration = SecurityConfiguration.class)
|
||||
class TimeOfferControllerTest {
|
||||
|
||||
private static final int TEST_CLIENT_ID = 1;
|
||||
private static final int TEST_TIMEOFFER_ID = 1;
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
private TimeOfferService timeOfferService;
|
||||
|
||||
@MockBean
|
||||
private ClientService clientService;
|
||||
|
||||
private TimeOffer time1;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
User user1 = new User();
|
||||
user1.setUsername("user1");
|
||||
user1.setPassword("user1");
|
||||
Client client1 = new Client();
|
||||
client1.setId(TEST_CLIENT_ID);
|
||||
client1.setName("client1");
|
||||
client1.setEmail("client1");
|
||||
client1.setAddress("client1");
|
||||
client1.setInit("01:00");
|
||||
client1.setFinish("01:01");
|
||||
client1.setTelephone("123456789");
|
||||
client1.setDescription("client1");
|
||||
client1.setCode("client1");
|
||||
client1.setFood("client1");
|
||||
client1.setUsuar(user1);
|
||||
BDDMockito.given(this.clientService.getCurrentClient()).willReturn(client1);
|
||||
|
||||
TimeOffer time1test = new TimeOffer();
|
||||
time1test.setId(TEST_TIMEOFFER_ID);
|
||||
time1test.setStart(LocalDateTime.of(2021, 12, 23, 12, 30));
|
||||
time1test.setEnd(LocalDateTime.of(2022, 12, 23, 12, 30));
|
||||
time1test.setInit(LocalTime.of(12, 00));
|
||||
time1test.setFinish(LocalTime.of(13, 00));
|
||||
time1test.setDiscount(10);
|
||||
time1test.setClient(client1);
|
||||
this.time1 = time1test;
|
||||
BDDMockito.given(this.timeOfferService.findTimeOfferById(TEST_TIMEOFFER_ID)).willReturn(this.time1);
|
||||
}
|
||||
|
||||
@WithMockUser(value = "spring", authorities = "client")
|
||||
@Test
|
||||
void testInitCreationForm() throws Exception {
|
||||
mockMvc.perform(get("/offers/time/new"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(model().attributeExists("timeOffer"))
|
||||
.andExpect(view().name("offers/time/createOrUpdateTimeOfferForm"));
|
||||
}
|
||||
|
||||
@WithMockUser(value = "spring", authorities = "client")
|
||||
@Test
|
||||
void testProcessCreationFormSuccess() throws Exception {
|
||||
mockMvc.perform(post("/offers/time/new")
|
||||
.with(SecurityMockMvcRequestPostProcessors.csrf())
|
||||
.param("start", "23/12/2021 12:30")
|
||||
.param("end", "23/12/2022 12:30")
|
||||
.param("init", "12:30")
|
||||
.param("finish", "13:30")
|
||||
.param("discount", "10"))
|
||||
.andExpect(status().is3xxRedirection());
|
||||
}
|
||||
|
||||
@WithMockUser(value = "spring", authorities = "client")
|
||||
@Test
|
||||
void testProcessCreationFormHasErrors() throws Exception {
|
||||
mockMvc.perform(post("/offers/time/new")
|
||||
.with(csrf())
|
||||
.param("start", "lsqdufhlqhf")
|
||||
.param("end", "")
|
||||
.param("init", "gold")
|
||||
.param("finish", "")
|
||||
.param("discount", ""))
|
||||
.andExpect(model().attributeHasErrors("timeOffer"))
|
||||
.andExpect(model().attributeHasFieldErrors("timeOffer", "start"))
|
||||
.andExpect(model().attributeHasFieldErrors("timeOffer", "end"))
|
||||
.andExpect(model().attributeHasFieldErrors("timeOffer", "init"))
|
||||
.andExpect(model().attributeHasFieldErrors("timeOffer", "finish"))
|
||||
.andExpect(model().attributeHasFieldErrors("timeOffer", "discount"))
|
||||
.andExpect(view().name("offers/time/createOrUpdateTimeOfferForm"));
|
||||
}
|
||||
|
||||
@WithMockUser(value = "user1", authorities = "client")
|
||||
@Test
|
||||
void testActivateSuccess() throws Exception {
|
||||
mockMvc.perform(get("/offers/time/{timeOfferId}/activate", TEST_TIMEOFFER_ID))
|
||||
.andExpect(status().is3xxRedirection())
|
||||
.andExpect(view().name("redirect:/offers/time/"+TEST_TIMEOFFER_ID));
|
||||
}
|
||||
|
||||
@WithMockUser(value = "user1", authorities = "client")
|
||||
@Test
|
||||
void testActivateHasErrors() throws Exception {
|
||||
mockMvc.perform(get("/offers/time/{timeOfferId}/activate", TEST_TIMEOFFER_ID+1))
|
||||
.andExpect(view().name("exception"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue