From 88b304f72abb0f9b9a610a6f9740cb07dd1ccb45 Mon Sep 17 00:00:00 2001 From: Antonio Vidal Date: Thu, 25 Mar 2021 18:00:19 +0100 Subject: [PATCH 1/3] Los shows funcionan pero hay un error con las TimeOffer, parece que los jsp no reconocen el tipo LocalTime --- .../cheapy/web/FoodOfferController.java | 67 +++++++++++++++++++ .../cheapy/web/TimeOfferController.java | 54 +++++++++++++++ .../WEB-INF/jsp/foodOffers/foodOffersShow.jsp | 44 ++++++++++++ .../WEB-INF/jsp/nuOffers/nuOffersShow.jsp | 2 +- .../WEB-INF/jsp/timeOffers/timeOffersShow.jsp | 31 +++++++++ 5 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/springframework/cheapy/web/FoodOfferController.java create mode 100644 src/main/java/org/springframework/cheapy/web/TimeOfferController.java create mode 100644 src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp diff --git a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java new file mode 100644 index 000000000..06afaed26 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java @@ -0,0 +1,67 @@ +/* + * 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.util.List; +import java.util.Map; + +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.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; +import org.springframework.web.bind.annotation.PathVariable; + + +/** + * @author Juergen Hoeller + * @author Ken Krebs + * @author Arjen Poutsma + * @author Michael Isvy + */ +@Controller +public class FoodOfferController { + + //private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; + + private final FoodOfferService foodOfferService; + + + + public FoodOfferController(final FoodOfferService foodOfferService) { + this.foodOfferService = foodOfferService; + + } + + @GetMapping("/offers/food/{foodOfferId}") + public String processShowForm(@PathVariable("foodOfferId") int foodOfferId, Map model) { + + FoodOffer foodOffer=this.foodOfferService.findFoodOfferById(foodOfferId); + + model.put("foodOffer", foodOffer); + + return "foodOffers/foodOffersShow"; + + } + +} diff --git a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java new file mode 100644 index 000000000..703b2b846 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java @@ -0,0 +1,54 @@ +/* + * 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.Map; + +import org.springframework.cheapy.model.TimeOffer; +import org.springframework.cheapy.service.TimeOfferService; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + + +/** + * @author Juergen Hoeller + * @author Ken Krebs + * @author Arjen Poutsma + * @author Michael Isvy + */ +@Controller +public class TimeOfferController { + + //private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; + private final TimeOfferService timeOfferService; + + public TimeOfferController(final TimeOfferService timeOfferService) { + this.timeOfferService = timeOfferService; + + } + + @GetMapping("/offers/time/{timeOfferId}") + public String processShowForm(@PathVariable("timeOfferId") int timeOfferId, Map model) { + + TimeOffer timeOffer=this.timeOfferService.findTimeOfferById(timeOfferId); + + model.put("timeOffer", timeOffer); + + return "timeOffers/timeOffersShow"; + + } +} diff --git a/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp new file mode 100644 index 000000000..0b7c8785a --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp @@ -0,0 +1,44 @@ +<%@ 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" %> + + + +

Oferta por plato específico

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Inicio de la oferta
Fin de la oferta
Plato en oferta
Descuento
Cantidad
Codigo de la oferta
+ + <%-- + + + Edit Owner --%> + +
diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp index 9c4eca9f3..431d2a4d6 100644 --- a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp @@ -4,7 +4,7 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +

Oferta por número de comensales

diff --git a/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp new file mode 100644 index 000000000..a344a6221 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/timeOffers/timeOffersShow.jsp @@ -0,0 +1,31 @@ +<%@ 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" %> + + + +

Oferta por franja horária

+ + + + + + + + + + + + + + + + + + + +
Inicio de la oferta
Fin de la oferta
Descuento
Codigo de la oferta
+ +
From a041e31a504b00071f6d8cbb94b2e012d3f62023 Mon Sep 17 00:00:00 2001 From: Antonio Vidal Date: Thu, 25 Mar 2021 18:30:33 +0100 Subject: [PATCH 2/3] Actualizado el listar. El show de TimeOffer no le gusta los LocalTime --- .../webapp/WEB-INF/jsp/offers/offersList.jsp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp index b7df4694d..54efc214d 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -15,18 +15,12 @@ Plato Fecha inicio Fecha fin - + - <%-- - - - - - --%> @@ -36,6 +30,12 @@ + + + + + Enlace + @@ -115,11 +115,11 @@ Fecha inicio Fecha fin - + - + @@ -128,12 +128,12 @@ - <%-- - + + - - --%> + Enlace + From 9de23998b97cc694e3cde94cf70523dd49e023b8 Mon Sep 17 00:00:00 2001 From: Antonio Vidal Date: Thu, 25 Mar 2021 20:59:24 +0100 Subject: [PATCH 3/3] Arreglos con los login y el authority --- .../configuration/SecurityConfiguration.java | 7 +-- .../cheapy/model/Administrator.java | 5 ++ .../springframework/cheapy/model/Client.java | 2 +- .../springframework/cheapy/model/User.java | 56 +++---------------- .../springframework/cheapy/model/Usuario.java | 29 +++++++++- src/main/resources/db/mysql/data.sql | 6 +- 6 files changed, 49 insertions(+), 56 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index 1f7d7cd13..3ade1b2f7 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -36,11 +36,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { http.authorizeRequests().antMatchers("/resources/**", "/webjars/**", "/h2-console/**").permitAll() .antMatchers(HttpMethod.GET, "/", "/oups").permitAll() - .antMatchers("/users/new").permitAll() - .antMatchers("/usuarios/new").permitAll() - .antMatchers("/offers/**").permitAll() - .antMatchers("/admin/**").hasAnyAuthority("admin") - .antMatchers("/owners/**").hasAnyAuthority("owner", "admin") + .antMatchers("/clients/new").permitAll() + .antMatchers("/offers/**").hasAnyAuthority("admin") .antMatchers("/vets/**").authenticated().anyRequest().denyAll() .and().formLogin() /* .loginPage("/login") */ diff --git a/src/main/java/org/springframework/cheapy/model/Administrator.java b/src/main/java/org/springframework/cheapy/model/Administrator.java index 736908254..44a3ffdf6 100644 --- a/src/main/java/org/springframework/cheapy/model/Administrator.java +++ b/src/main/java/org/springframework/cheapy/model/Administrator.java @@ -6,5 +6,10 @@ import javax.persistence.Table; @Entity @Table(name = "administrators") public class Administrator extends User{ + + /** + * + */ + private static final long serialVersionUID = 1L; } diff --git a/src/main/java/org/springframework/cheapy/model/Client.java b/src/main/java/org/springframework/cheapy/model/Client.java index b249311ff..161b57402 100644 --- a/src/main/java/org/springframework/cheapy/model/Client.java +++ b/src/main/java/org/springframework/cheapy/model/Client.java @@ -10,7 +10,7 @@ import javax.validation.constraints.NotEmpty; @Entity @Table(name = "clients") -public class Client extends User { +public class Client extends BaseEntity{ @NotEmpty private String email; diff --git a/src/main/java/org/springframework/cheapy/model/User.java b/src/main/java/org/springframework/cheapy/model/User.java index 36d495444..3e9854000 100644 --- a/src/main/java/org/springframework/cheapy/model/User.java +++ b/src/main/java/org/springframework/cheapy/model/User.java @@ -1,56 +1,18 @@ package org.springframework.cheapy.model; -import java.util.List; -import java.util.Set; - -import javax.persistence.CascadeType; -import javax.persistence.Entity; -import javax.persistence.Id; +import javax.persistence.JoinColumn; import javax.persistence.MappedSuperclass; -import javax.persistence.OneToMany; import javax.persistence.OneToOne; -import javax.persistence.Table; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; - -//@Entity -//@Table(name = "users") @MappedSuperclass -public class User{ +public class User extends BaseEntity{ - @Id - private String username; - - @NotBlank - private String password; + /** + * + */ + private static final long serialVersionUID = 1L; - boolean enabled; - - - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - -// public Set getAuthority() { -// return authorities; -// } -// -// public void setAuthorities(Set authorities) { -// this.authorities = authorities; -// } + @OneToOne + @JoinColumn(name = "username") + private Usuario usuario; } diff --git a/src/main/java/org/springframework/cheapy/model/Usuario.java b/src/main/java/org/springframework/cheapy/model/Usuario.java index 3556ff16c..572a0821e 100644 --- a/src/main/java/org/springframework/cheapy/model/Usuario.java +++ b/src/main/java/org/springframework/cheapy/model/Usuario.java @@ -5,12 +5,39 @@ 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.NotBlank; @Entity @Table(name = "users") -public class Usuario extends User{ +public class Usuario { + + @Id + private String username; + + @NotBlank + private String password; + + boolean enabled; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } @OneToMany(cascade = CascadeType.ALL, mappedBy = "user") private Set authorities; diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index b1bab7a65..b9d25cbcf 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -19,6 +19,8 @@ INSERT INTO nu_offers(start, end, code, type, client_id, gold, discount_gold, si --insert into usuarios(username, password, enabled) values ('admin3', 'admin', true); --insert into authorities(id ,usuario, authority) values (42,'admin3', 'admin'); -INSERT INTO users(username,password,enabled) VALUES ('admin1','4dm1n',TRUE); -INSERT INTO authorities(id,username,authority) VALUES (1,'admin1','admin'); +INSERT INTO users(username,password,enabled) VALUES ('cliente','cliente',TRUE); +INSERT INTO authorities(id,username,authority) VALUES (1,'cliente','client'); +INSERT INTO clients(email, address, timetable,telephone,description,code,food) VALUES ('cliente@hotmail.com','Calle Tahona nº5','12:00-23:00','954876351','Descripcion','codigo','variado'); +--INSERT INTO authorities(id,username,authority) VALUES (31,'cliente','client'); \ No newline at end of file