From 65253a15c80e17f7ff6f46069bfdc07c496d01f5 Mon Sep 17 00:00:00 2001 From: Abraham Date: Wed, 24 Mar 2021 17:38:56 +0100 Subject: [PATCH 1/7] codigo casi completo pero no funcional --- .../configuration/SecurityConfiguration.java | 3 +- .../cheapy/model/FoodOffer.java | 2 +- .../springframework/cheapy/model/NuOffer.java | 2 +- .../springframework/cheapy/model/Offer.java | 2 +- .../cheapy/model/SpeedOffer.java | 2 +- .../cheapy/model/TimeOffer.java | 2 +- .../repository/FoodOfferRepository.java | 67 ++++++++ .../cheapy/repository/NuOfferRepository.java | 68 ++++++++ .../repository/SpeedOfferRepository.java | 68 ++++++++ .../repository/TimeOfferRepository.java | 68 ++++++++ .../cheapy/service/FoodOfferService.java | 37 +++++ .../cheapy/service/NuOfferService.java | 37 +++++ .../cheapy/service/SpeedOfferService.java | 35 ++++ .../cheapy/service/TimeOfferService.java | 37 +++++ .../cheapy/service/UserService.java | 64 -------- .../cheapy/web/OfertaController.java | 109 +++++++++++++ .../cheapy/web/UserController.java | 154 ------------------ .../webapp/WEB-INF/jsp/offers/offersList.jsp | 138 ++++++++++++++++ src/main/webapp/WEB-INF/tags/menu.tag | 2 +- 19 files changed, 672 insertions(+), 225 deletions(-) create mode 100644 src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java create mode 100644 src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java create mode 100644 src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java create mode 100644 src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java create mode 100644 src/main/java/org/springframework/cheapy/service/FoodOfferService.java create mode 100644 src/main/java/org/springframework/cheapy/service/NuOfferService.java create mode 100644 src/main/java/org/springframework/cheapy/service/SpeedOfferService.java create mode 100644 src/main/java/org/springframework/cheapy/service/TimeOfferService.java delete mode 100644 src/main/java/org/springframework/cheapy/service/UserService.java create mode 100644 src/main/java/org/springframework/cheapy/web/OfertaController.java delete mode 100644 src/main/java/org/springframework/cheapy/web/UserController.java create mode 100644 src/main/webapp/WEB-INF/jsp/offers/offersList.jsp diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index 2fbdc84ad..2b9ce3c1c 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -38,6 +38,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .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("/vets/**").authenticated().anyRequest().denyAll() @@ -58,7 +59,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { public void configure(final AuthenticationManagerBuilder auth) throws Exception { auth.jdbcAuthentication().dataSource(this.dataSource) //[login de admin,owner y vet] .usersByUsernameQuery("select username,password,enabled " + "from users " + "where username = ?") - .usersByUsernameQuery("select username, password, enabled from users where username=?").authoritiesByUsernameQuery("select username, authority " + "from authorities " + "where username = ?") //[login de tallerespaco] + .usersByUsernameQuery("select username, password, enabled from users where username=?").authoritiesByUsernameQuery("select username, authority " + "from authorities " + "where username = ?") .passwordEncoder(this.passwordEncoder()); } diff --git a/src/main/java/org/springframework/cheapy/model/FoodOffer.java b/src/main/java/org/springframework/cheapy/model/FoodOffer.java index b82fed73b..5a03285ef 100644 --- a/src/main/java/org/springframework/cheapy/model/FoodOffer.java +++ b/src/main/java/org/springframework/cheapy/model/FoodOffer.java @@ -22,7 +22,7 @@ import javax.validation.constraints.NotBlank; @Entity @Table(name = "food_offers") public class FoodOffer extends Offer { - +//Plato específico @NotBlank private String food; diff --git a/src/main/java/org/springframework/cheapy/model/NuOffer.java b/src/main/java/org/springframework/cheapy/model/NuOffer.java index 05d66a688..25ebce674 100644 --- a/src/main/java/org/springframework/cheapy/model/NuOffer.java +++ b/src/main/java/org/springframework/cheapy/model/NuOffer.java @@ -23,7 +23,7 @@ import javax.validation.constraints.NotBlank; @Entity @Table(name = "nu_offers") public class NuOffer extends Offer { - +//Oferta por numero de comensales @NotBlank private Integer gold; diff --git a/src/main/java/org/springframework/cheapy/model/Offer.java b/src/main/java/org/springframework/cheapy/model/Offer.java index 4c3921b1b..0e6d23f18 100644 --- a/src/main/java/org/springframework/cheapy/model/Offer.java +++ b/src/main/java/org/springframework/cheapy/model/Offer.java @@ -31,7 +31,7 @@ import org.springframework.format.annotation.DateTimeFormat; @MappedSuperclass public class Offer extends BaseEntity { - +//Clase padre @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") @NotBlank @Future diff --git a/src/main/java/org/springframework/cheapy/model/SpeedOffer.java b/src/main/java/org/springframework/cheapy/model/SpeedOffer.java index 0399d4baf..71e32ae3e 100644 --- a/src/main/java/org/springframework/cheapy/model/SpeedOffer.java +++ b/src/main/java/org/springframework/cheapy/model/SpeedOffer.java @@ -23,7 +23,7 @@ import javax.validation.constraints.NotBlank; @Entity @Table(name = "speed_offers") public class SpeedOffer extends Offer { - +//Ofertar por rapidez comiendo @NotBlank private Integer gold; // x minutos diff --git a/src/main/java/org/springframework/cheapy/model/TimeOffer.java b/src/main/java/org/springframework/cheapy/model/TimeOffer.java index 7f1d3cc6d..ceefc371e 100644 --- a/src/main/java/org/springframework/cheapy/model/TimeOffer.java +++ b/src/main/java/org/springframework/cheapy/model/TimeOffer.java @@ -28,7 +28,7 @@ import org.springframework.format.annotation.DateTimeFormat; @Entity @Table(name = "time_offers") public class TimeOffer extends Offer { - +//Oferta por franja horaria @DateTimeFormat(pattern = "HH:mm") @NotBlank private LocalTime init; diff --git a/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java new file mode 100644 index 000000000..4061e5fc4 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.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.repository; + +import java.util.Collection; +import java.util.List; + +import org.springframework.cheapy.model.FoodOffer; +import org.springframework.cheapy.model.Owner; +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; + +/** + * Repository class for Owner domain objects All method names are compliant + * with Spring Data naming conventions so this interface can easily be extended for Spring + * Data. See: + * https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation + * + * @author Ken Krebs + * @author Juergen Hoeller + * @author Sam Brannen + * @author Michael Isvy + */ +public interface FoodOfferRepository extends Repository { + + /** + * Retrieve {@link Owner}s from the data store by last name, returning all owners + * whose last name starts with the given name. + * @param lastName Value to search for + * @return a Collection of matching {@link Owner}s (or an empty Collection if none + * found) + */ + @Query("SELECT foodOffer FROM FoodOffer foodOffer") + @Transactional(readOnly = true) + List findAllFoodOffer(); + + /** + * Retrieve an {@link Owner} from the data store by id. + * @param id the id to search for + * @return the {@link Owner} if found + */ + @Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE id =:id") + @Transactional(readOnly = true) + FoodOffer findById(@Param("id") Integer id); + + /** + * Save an {@link Owner} to the data store, either inserting or updating it. + * @param owner the {@link Owner} to save + */ + void save(FoodOffer foodOffer); + +} diff --git a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java new file mode 100644 index 000000000..81cdd7d24 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java @@ -0,0 +1,68 @@ +/* + * 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.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.Owner; +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; + +/** + * Repository class for Owner domain objects All method names are compliant + * with Spring Data naming conventions so this interface can easily be extended for Spring + * Data. See: + * https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation + * + * @author Ken Krebs + * @author Juergen Hoeller + * @author Sam Brannen + * @author Michael Isvy + */ +public interface NuOfferRepository extends Repository { + + /** + * Retrieve {@link Owner}s from the data store by last name, returning all owners + * whose last name starts with the given name. + * @param lastName Value to search for + * @return a Collection of matching {@link Owner}s (or an empty Collection if none + * found) + */ + @Query("SELECT nuOffer FROM NuOffer nuOffer") + @Transactional(readOnly = true) + List findAllNuOffer(); + + /** + * Retrieve an {@link Owner} from the data store by id. + * @param id the id to search for + * @return the {@link Owner} if found + */ + @Query("SELECT nuOffer FROM NuOffer nuOffer WHERE id =:id") + @Transactional(readOnly = true) + NuOffer findById(@Param("id") Integer id); + + /** + * Save an {@link Owner} to the data store, either inserting or updating it. + * @param owner the {@link Owner} to save + */ + void save(NuOffer nuOffer); + +} diff --git a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java new file mode 100644 index 000000000..606d1d31a --- /dev/null +++ b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java @@ -0,0 +1,68 @@ +/* + * 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.repository; + +import java.util.Collection; +import java.util.List; + +import org.springframework.cheapy.model.FoodOffer; +import org.springframework.cheapy.model.Owner; +import org.springframework.cheapy.model.SpeedOffer; +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; + +/** + * Repository class for Owner domain objects All method names are compliant + * with Spring Data naming conventions so this interface can easily be extended for Spring + * Data. See: + * https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation + * + * @author Ken Krebs + * @author Juergen Hoeller + * @author Sam Brannen + * @author Michael Isvy + */ +public interface SpeedOfferRepository extends Repository { + + /** + * Retrieve {@link Owner}s from the data store by last name, returning all owners + * whose last name starts with the given name. + * @param lastName Value to search for + * @return a Collection of matching {@link Owner}s (or an empty Collection if none + * found) + */ + @Query("SELECT speedOffer FROM SpeedOffer speedOffer") + @Transactional(readOnly = true) + List findAllSpeedOffer(); + + /** + * Retrieve an {@link Owner} from the data store by id. + * @param id the id to search for + * @return the {@link Owner} if found + */ + @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE id =:id") + @Transactional(readOnly = true) + SpeedOffer findById(@Param("id") Integer id); + + /** + * Save an {@link Owner} to the data store, either inserting or updating it. + * @param owner the {@link Owner} to save + */ + void save(SpeedOffer speedOffer); + +} diff --git a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java new file mode 100644 index 000000000..186746870 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java @@ -0,0 +1,68 @@ +/* + * 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.repository; + +import java.util.Collection; +import java.util.List; + +import org.springframework.cheapy.model.FoodOffer; +import org.springframework.cheapy.model.Owner; +import org.springframework.cheapy.model.TimeOffer; +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; + +/** + * Repository class for Owner domain objects All method names are compliant + * with Spring Data naming conventions so this interface can easily be extended for Spring + * Data. See: + * https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation + * + * @author Ken Krebs + * @author Juergen Hoeller + * @author Sam Brannen + * @author Michael Isvy + */ +public interface TimeOfferRepository extends Repository { + + /** + * Retrieve {@link Owner}s from the data store by last name, returning all owners + * whose last name starts with the given name. + * @param lastName Value to search for + * @return a Collection of matching {@link Owner}s (or an empty Collection if none + * found) + */ + @Query("SELECT timeOffer FROM TimeOffer timeOffer") + @Transactional(readOnly = true) + List findAllTimeOffer(); + + /** + * Retrieve an {@link Owner} from the data store by id. + * @param id the id to search for + * @return the {@link Owner} if found + */ + @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE id =:id") + @Transactional(readOnly = true) + TimeOffer findById(@Param("id") Integer id); + + /** + * Save an {@link Owner} to the data store, either inserting or updating it. + * @param owner the {@link Owner} to save + */ + void save(TimeOffer timeOffer); + +} diff --git a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java new file mode 100644 index 000000000..b55207046 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java @@ -0,0 +1,37 @@ +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.FoodOffer; +import org.springframework.cheapy.model.Owner; +import org.springframework.cheapy.repository.FoodOfferRepository; +import org.springframework.cheapy.repository.OwnerRepository; +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; + } + + public FoodOffer findFoodOfferById(final int id) { + return this.foodOfferRepository.findById(id); + } + + public List findAllFoodOffer() { // + return this.foodOfferRepository.findAllFoodOffer(); + + } + + public void saveOwner(final FoodOffer foodOffer) throws DataAccessException { // + this.foodOfferRepository.save(foodOffer); + + } +} diff --git a/src/main/java/org/springframework/cheapy/service/NuOfferService.java b/src/main/java/org/springframework/cheapy/service/NuOfferService.java new file mode 100644 index 000000000..1029999d5 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/service/NuOfferService.java @@ -0,0 +1,37 @@ +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.Owner; +import org.springframework.cheapy.repository.NuOfferRepository; +import org.springframework.cheapy.repository.OwnerRepository; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +@Service +public class NuOfferService { + private NuOfferRepository nuOfferRepository; + + + @Autowired + public NuOfferService(final NuOfferRepository nuOfferRepository) { + this.nuOfferRepository = nuOfferRepository; + } + + public NuOffer findNuOfferById(final int id) { + return this.nuOfferRepository.findById(id); + } + + public List findAllNuOffer() { // + return this.nuOfferRepository.findAllNuOffer(); + + } + + public void saveOwner(final NuOffer nuOffer) throws DataAccessException { // + this.nuOfferRepository.save(nuOffer); + + } +} diff --git a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java new file mode 100644 index 000000000..bfc70644e --- /dev/null +++ b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java @@ -0,0 +1,35 @@ +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.SpeedOffer; +import org.springframework.cheapy.repository.SpeedOfferRepository; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +@Service +public class SpeedOfferService { + private SpeedOfferRepository speedOfferRepository; + + + @Autowired + public SpeedOfferService(final SpeedOfferRepository speedOfferRepository) { + this.speedOfferRepository = speedOfferRepository; + } + + public SpeedOffer findSpeedOfferById(final int id) { + return this.speedOfferRepository.findById(id); + } + + public List findAllSpeedOffer() { // + return this.speedOfferRepository.findAllSpeedOffer(); + + } + + public void saveOwner(final SpeedOffer speedOffer) throws DataAccessException { // + this.speedOfferRepository.save(speedOffer); + + } +} diff --git a/src/main/java/org/springframework/cheapy/service/TimeOfferService.java b/src/main/java/org/springframework/cheapy/service/TimeOfferService.java new file mode 100644 index 000000000..bb5cacbc6 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/service/TimeOfferService.java @@ -0,0 +1,37 @@ +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.TimeOffer; +import org.springframework.cheapy.model.Owner; +import org.springframework.cheapy.repository.TimeOfferRepository; +import org.springframework.cheapy.repository.OwnerRepository; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +@Service +public class TimeOfferService { + private TimeOfferRepository timeOfferRepository; + + + @Autowired + public TimeOfferService(final TimeOfferRepository timeOfferRepository) { + this.timeOfferRepository = timeOfferRepository; + } + + public TimeOffer findTimeOfferById(final int id) { + return this.timeOfferRepository.findById(id); + } + + public List findAllTimeOffer() { // + return this.timeOfferRepository.findAllTimeOffer(); + + } + + public void saveOwner(final TimeOffer timeOffer) throws DataAccessException { // + this.timeOfferRepository.save(timeOffer); + + } +} diff --git a/src/main/java/org/springframework/cheapy/service/UserService.java b/src/main/java/org/springframework/cheapy/service/UserService.java deleted file mode 100644 index d719f8b47..000000000 --- a/src/main/java/org/springframework/cheapy/service/UserService.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 java.util.Optional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataAccessException; -import org.springframework.cheapy.model.User; -import org.springframework.cheapy.repository.UsuarioRepository; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - - -/** - * Mostly used as a facade for all Petclinic controllers Also a placeholder - * for @Transactional and @Cacheable annotations - * - * @author Michael Isvy - */ - -@Service -public class UserService { -/* - private UserRepository userRepository; - - @Autowired - public UserService(UserRepository userRepository) { - this.userRepository = userRepository; - } - - @Transactional - public void saveUser(User user) throws DataAccessException { - userRepository.save(user); - } - - public Optional findUser(String username) { - return userRepository.findById(username); - } - - @Transactional - public User getCurrentUser() throws DataAccessException { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - String currentPrincipalName = authentication.getName(); //Obtiene el nombre del ususario actual - return this.userRepository.findByUsername(currentPrincipalName); //Obtiene el usuario con ese nombre - } - */ -} diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java new file mode 100644 index 000000000..70d42fb55 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -0,0 +1,109 @@ +/* + * 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; + + +/** + * @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 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) { + this.foodOfferService = foodOfferService; + this.nuOfferService = nuOfferService; + this.speedOfferService = speedOfferService; + this.timeOfferService = timeOfferService; + + } + + + @GetMapping("/offers") + public String processFindForm(BindingResult result, Map model) { + + List foodOfferLs=this.foodOfferService.findAllFoodOffer(); + List nuOfferLs=this.nuOfferService.findAllNuOffer(); + List speedOfferLs=this.speedOfferService.findAllSpeedOffer(); + List timeOfferLs=this.timeOfferService.findAllTimeOffer(); + + model.put("foodOfferLs", foodOfferLs); + model.put("nuOfferLs", nuOfferLs); + model.put("speedOfferLs", speedOfferLs); + model.put("timeOfferLs", timeOfferLs); + + return "offers/offersList"; + + } + +// @GetMapping("/owners/{ownerId}/edit") +// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { +// Owner owner = this.ownerService.findOwnerById(ownerId); +// model.addAttribute(owner); +// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; +// } +// +// @PostMapping("/owners/{ownerId}/edit") +// public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, +// @PathVariable("ownerId") int ownerId) { +// if (result.hasErrors()) { +// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; +// } +// else { +// owner.setId(ownerId); +// this.ownerService.saveOwner(owner); +// return "redirect:/owners/{ownerId}"; +// } +// } +// @GetMapping("/owners/{ownerId}") +// public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { +// ModelAndView mav = new ModelAndView("owners/ownerDetails"); +// Owner owner = this.ownerService.findOwnerById(ownerId); +// +// mav.addObject(owner); +// return mav; +// } + + +} diff --git a/src/main/java/org/springframework/cheapy/web/UserController.java b/src/main/java/org/springframework/cheapy/web/UserController.java deleted file mode 100644 index 97e921a75..000000000 --- a/src/main/java/org/springframework/cheapy/web/UserController.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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.web; - -import javax.persistence.EntityNotFoundException; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cheapy.model.Authorities; -import org.springframework.cheapy.model.User; -import org.springframework.cheapy.service.AuthoritiesService; -import org.springframework.cheapy.service.UserService; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.validation.BindingResult; -import org.springframework.validation.FieldError; -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.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; - -/** - * @author Juergen Hoeller - * @author Ken Krebs - * @author Arjen Poutsma - * @author Michael Isvy - */ -@Controller -public class UserController { - - private UserService userService; - - private AuthoritiesService authoritiesService; - -// @Autowired -// public UserController (UserService userService, AuthoritiesService authoritiesService, -// ClienteService clienteService, FarmaceuticoService farmaceuticoService, ProveedorService proveedorService) { -// this.userService = userService; -// this.authoritiesService = authoritiesService; -// this.clienteService = clienteService; -// this.farmaceuticoService = farmaceuticoService; -// this.proveedorService = proveedorService; -// } -// -// @InitBinder -// public void setAllowedFields(final WebDataBinder dataBinder) { -// dataBinder.setDisallowedFields("id"); -// } -// -// @GetMapping("users") -// private String showUserDetails(ModelMap model) { -// User user = this.userService.getCurrentUser(); -// Authorities authority = this.authoritiesService.findAuthoritiyByUser(user); -// -// if(authority.getAuthority().equals("cliente")) { -// Cliente cliente = this.clienteService.findClienteUser(user); -// model.addAttribute("cliente", cliente); -// }else if(authority.getAuthority().equals("proveedor")) { -// Proveedor proveedor = this.proveedorService.findProveedorUser(user); -// model.addAttribute("proveedor", proveedor); -// }else if(authority.getAuthority().equals("farmaceutico")) { -// Farmaceutico farmaceutico = this.farmaceuticoService.findFarmaceuticoByUser(user); -// model.addAttribute("farmaceutico", farmaceutico); -// } -// -// log.info("El usuario '" + user.getUsername() + "' ha mostrado su informacion personal"); -// return "users/userDetails"; -// } -// -// @GetMapping("/users/new") -// public String newUser(ModelMap model) { -// Cliente cliente = new Cliente(); -// model.addAttribute("cliente", cliente); -// model.addAttribute("dni", new String()); -// return "users/userRegister"; -// } -// -// @PostMapping("/users/new") -// public String creationUser(@ModelAttribute("cliente") Cliente cliente, final BindingResult result, ModelMap model) { -// if (result.hasErrors()) { -// return "users/userRegister"; -// } else if(cliente.getUser() == null) { -// try { -// cliente = this.clienteService.clienteDni(cliente.getDni()); -// }catch(EntityNotFoundException ex) { -// result.rejectValue("dni", "clienteNotFound"); -// return "users/userRegister"; -// } -// cliente.setUser(new User()); -// model.addAttribute("cliente", cliente); -// return "users/userRegister"; -// }else { -// this.userService.saveUser(cliente.getUser()); -// this.authoritiesService.saveAuthorities(cliente.getUser().getUsername(), "cliente"); -// this.clienteService.saveCliente(cliente); -// log.info("El cliente con dni '" + cliente.getDni() + "' se ha registrado como usuario"); -// return "redirect:../"; -// } -// } -// -// @GetMapping("/users/password") -// public String initChangePassword(ModelMap model) { -// User currentUser = this.userService.getCurrentUser(); -// UserValidate user = new UserValidate(currentUser.getUsername(), ""); -// model.addAttribute("user", user); -// return "users/passwordEdit"; -// } -// -// @PostMapping("/users/password") -// public String changePassword(@ModelAttribute("user") UserValidate user, final BindingResult result, ModelMap model) { -// if(result.hasErrors()) { -// return "users/passwordEdit"; -// }else { -// User CurrentUser = this.userService.getCurrentUser(); -// if(CurrentUser.getPassword().equals(user.getPassword()) && user.getNewPassword().equals(user.getValidPassword())) { -// if(!user.getNewPassword().isEmpty()) { -// CurrentUser.setPassword(user.getNewPassword()); -// this.userService.saveUser(CurrentUser); -// log.info("El usuario '" + CurrentUser.getUsername() + "' ha cambiado satisfactoriamente su contraseña"); -// return "redirect:../"; -// }else { -// FieldError err = new FieldError("PassException", "newPassword", "Introduce una nueva contraseña"); -// result.addError(err); -// log.warn("El usuario '" + CurrentUser.getUsername() + "' ha tenido un error 'PassException'"); -// return "users/passwordEdit"; -// } -// }else if(!CurrentUser.getPassword().equals(user.getPassword())){ -// FieldError err = new FieldError("PassException", "password", "Contraseña incorrecta"); -// result.addError(err); -// log.warn("El usuario '" + CurrentUser.getUsername() + "' ha tenido un error 'PassException'"); -// return "users/passwordEdit"; -// }else { -// FieldError err = new FieldError("PassException", "newPassword", "Las contraseñas no coinciden"); -// result.addError(err); -// log.warn("El usuario '" + CurrentUser.getUsername() + "' ha tenido un error 'PassException'"); -// return "users/passwordEdit"; -// } -// } -// } -} diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp new file mode 100644 index 000000000..fd51ca114 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -0,0 +1,138 @@ +<%@ 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" %> + + +

Ofertas por plato específico

+ + + + + + + + + + + + + + + + + + + + + + +
RestaurantePlatoFecha inicioFecha fin
+ + + + + + + + + + +
+ +

Ofertas por número de comensales

+ + + + + + + + + + + + + + + + + + + + +
RestauranteFecha inicioFecha fin
+ + + + + + + + +
+

Ofertas por plato específico

+ + + + + + + + + + + + + + + + + + + + +
RestauranteFecha inicioFecha fin
+ + + + + + + + +
+

Ofertas por plato específico

+ + + + + + + + + + + + + + + + + + + + +
RestauranteFecha inicioFecha fin
+ + + + + + + + +
+
diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index 144904a60..6963454f7 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -28,7 +28,7 @@ Home - Ver ofertas From bf08d78e1a34f8bb36944f68412db7ab892a0566 Mon Sep 17 00:00:00 2001 From: Abraham Date: Wed, 24 Mar 2021 18:16:36 +0100 Subject: [PATCH 2/7] funciona el list de ofertas --- .../cheapy/web/OfertaController.java | 2 +- .../webapp/WEB-INF/jsp/offers/offersList.jsp | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index 70d42fb55..517b1f5d9 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -61,7 +61,7 @@ public class OfertaController { @GetMapping("/offers") - public String processFindForm(BindingResult result, Map model) { + public String processFindForm( Map model) { List foodOfferLs=this.foodOfferService.findAllFoodOffer(); List nuOfferLs=this.nuOfferService.findAllNuOffer(); diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp index fd51ca114..0bdf44add 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -11,7 +11,7 @@ - + @@ -21,12 +21,12 @@ - + --%> @@ -47,7 +47,7 @@
Restaurante Plato Fecha inicio Fecha fin
+ <%-- -
- + @@ -56,12 +56,12 @@ - + --%> @@ -78,7 +78,7 @@
Restaurante Fecha inicio Fecha fin
+ <%-- -
- + @@ -87,12 +87,12 @@ - + --%> @@ -109,7 +109,7 @@
Restaurante Fecha inicio Fecha fin
+ <%-- -
- + @@ -118,17 +118,17 @@ - + --%> From 5a55aa8084c8ee982de67571d3aaf7d92c55bdee Mon Sep 17 00:00:00 2001 From: Abraham Date: Wed, 24 Mar 2021 19:36:56 +0100 Subject: [PATCH 3/7] shows de noOffer y speedOffer completados y funcionales --- .../configuration/SecurityConfiguration.java | 2 +- .../cheapy/web/NuOfferController.java | 104 ++++++++++++++++++ .../cheapy/web/OfertaController.java | 2 +- .../cheapy/web/SpeedOfferController.java | 104 ++++++++++++++++++ src/main/resources/db/mysql/data.sql | 2 + .../WEB-INF/jsp/nuOffers/nuOffersShow.jsp | 56 ++++++++++ .../webapp/WEB-INF/jsp/offers/offersList.jsp | 47 ++++---- .../jsp/speedOffers/speedOffersShow.jsp | 56 ++++++++++ 8 files changed, 349 insertions(+), 24 deletions(-) create mode 100644 src/main/java/org/springframework/cheapy/web/NuOfferController.java create mode 100644 src/main/java/org/springframework/cheapy/web/SpeedOfferController.java create mode 100644 src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index 2b9ce3c1c..1f7d7cd13 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -38,7 +38,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.GET, "/", "/oups").permitAll() .antMatchers("/users/new").permitAll() .antMatchers("/usuarios/new").permitAll() - .antMatchers("/offers").permitAll() + .antMatchers("/offers/**").permitAll() .antMatchers("/admin/**").hasAnyAuthority("admin") .antMatchers("/owners/**").hasAnyAuthority("owner", "admin") .antMatchers("/vets/**").authenticated().anyRequest().denyAll() diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java new file mode 100644 index 000000000..bd6d34844 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -0,0 +1,104 @@ +/* + * 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 NuOfferController { + + //private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; + + private final FoodOfferService foodOfferService; + private final NuOfferService nuOfferService; + private final SpeedOfferService speedOfferService; + private final TimeOfferService timeOfferService; + + + + public NuOfferController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, + final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) { + this.foodOfferService = foodOfferService; + this.nuOfferService = nuOfferService; + this.speedOfferService = speedOfferService; + this.timeOfferService = timeOfferService; + + } + + + @GetMapping("/offers/nu/{nuOfferId}") + public String processShowForm(@PathVariable("nuOfferId") int nuOfferId, Map model) { + + NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId); + + model.put("nuOffer", nuOffer); + + return "nuOffers/nuOffersShow"; + + } + +// @GetMapping("/owners/{ownerId}/edit") +// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { +// Owner owner = this.ownerService.findOwnerById(ownerId); +// model.addAttribute(owner); +// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; +// } +// +// @PostMapping("/owners/{ownerId}/edit") +// public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, +// @PathVariable("ownerId") int ownerId) { +// if (result.hasErrors()) { +// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; +// } +// else { +// owner.setId(ownerId); +// this.ownerService.saveOwner(owner); +// return "redirect:/owners/{ownerId}"; +// } +// } +// @GetMapping("/owners/{ownerId}") +// public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { +// ModelAndView mav = new ModelAndView("owners/ownerDetails"); +// Owner owner = this.ownerService.findOwnerById(ownerId); +// +// mav.addObject(owner); +// return mav; +// } + + +} diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index 517b1f5d9..dcd92f583 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -44,7 +44,7 @@ public class OfertaController { //private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; private final FoodOfferService foodOfferService; - private final NuOfferService nuOfferService; + private final NuOfferService nuOfferService; private final SpeedOfferService speedOfferService; private final TimeOfferService timeOfferService; diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java new file mode 100644 index 000000000..68a377a68 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -0,0 +1,104 @@ +/* + * 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 SpeedOfferController { + + //private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; + + private final FoodOfferService foodOfferService; + private final NuOfferService nuOfferService; + private final SpeedOfferService speedOfferService; + private final TimeOfferService timeOfferService; + + + + public SpeedOfferController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, + final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) { + this.foodOfferService = foodOfferService; + this.nuOfferService = nuOfferService; + this.speedOfferService = speedOfferService; + this.timeOfferService = timeOfferService; + + } + + + @GetMapping("/offers/speed/{speedOfferId}") + public String processShowForm(@PathVariable("speedOfferId") int speedOfferId, Map model) { + + SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId); + + model.put("speedOffer", speedOffer); + + return "speedOffers/speedOffersShow"; + + } + +// @GetMapping("/owners/{ownerId}/edit") +// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { +// Owner owner = this.ownerService.findOwnerById(ownerId); +// model.addAttribute(owner); +// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; +// } +// +// @PostMapping("/owners/{ownerId}/edit") +// public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, +// @PathVariable("ownerId") int ownerId) { +// if (result.hasErrors()) { +// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; +// } +// else { +// owner.setId(ownerId); +// this.ownerService.saveOwner(owner); +// return "redirect:/owners/{ownerId}"; +// } +// } +// @GetMapping("/owners/{ownerId}") +// public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { +// ModelAndView mav = new ModelAndView("owners/ownerDetails"); +// Owner owner = this.ownerService.findOwnerById(ownerId); +// +// mav.addObject(owner); +// return mav; +// } + + +} diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index 3dd3b74c7..b1bab7a65 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -13,6 +13,8 @@ INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Wa 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', 'jkhlljk', 'active', null, 'macarrones', '15%', 10); 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 usuarios(username, password, enabled) values ('admin3', 'admin', true); --insert into authorities(id ,usuario, authority) values (42,'admin3', 'admin'); diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp new file mode 100644 index 000000000..9c4eca9f3 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp @@ -0,0 +1,56 @@ +<%@ 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 número de comensales

+ + +
Restaurante Fecha inicio Fecha fin
+ <%-- - - +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Inicio de la oferta
Fin de la oferta
Meta oro
Descuento oro
Meta plata
Descuento plata
Meta bronce
Descuento bronce
Codigo de la oferta
+ + <%-- + + + Edit Owner --%> + + diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp index 0bdf44add..b7df4694d 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -50,30 +50,31 @@ Fecha inicio Fecha fin + - <%-- - - - - - --%> + - + + + + + Enlace + -

Ofertas por plato específico

+

Ofertas rapidez comiendo

@@ -81,30 +82,32 @@ + - <%-- --%> + +
Fecha inicio Fecha fin
- - - - - + + + + Enlace +
-

Ofertas por plato específico

+

Ofertas por franja horaria

@@ -118,19 +121,19 @@ - <%-- --%> + - + <%-- --%> diff --git a/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp new file mode 100644 index 000000000..4a85df28b --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp @@ -0,0 +1,56 @@ +<%@ 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 comer veloz

+ + +
- - - - - + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Inicio de la oferta
Fin de la oferta
Meta oro
Descuento oro
Meta plata
Descuento plata
Meta bronce
Descuento bronce
Codigo de la oferta
+ + <%-- + + + Edit Owner --%> + + From 88b304f72abb0f9b9a610a6f9740cb07dd1ccb45 Mon Sep 17 00:00:00 2001 From: Antonio Vidal Date: Thu, 25 Mar 2021 18:00:19 +0100 Subject: [PATCH 4/7] 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 5/7] 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 6/7] 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 From 48afa96a078aeee351d491979a9668491c82e509 Mon Sep 17 00:00:00 2001 From: Abraham Date: Thu, 25 Mar 2021 21:08:41 +0100 Subject: [PATCH 7/7] loginfixed --- .../cheapy/model/Authorities.java | 65 +++++++------ .../springframework/cheapy/model/Client.java | 89 +++++++++++++++-- .../springframework/cheapy/model/User.java | 13 +-- .../springframework/cheapy/model/Usuario.java | 95 +++++++++++++++++-- .../cheapy/repository/UsuarioRepository.java | 2 +- src/main/resources/db/mysql/data.sql | 25 ++++- 6 files changed, 233 insertions(+), 56 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/model/Authorities.java b/src/main/java/org/springframework/cheapy/model/Authorities.java index 7ec1f6666..3bcfbbb35 100644 --- a/src/main/java/org/springframework/cheapy/model/Authorities.java +++ b/src/main/java/org/springframework/cheapy/model/Authorities.java @@ -1,47 +1,58 @@ package org.springframework.cheapy.model; import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; +import javax.persistence.Id; import javax.persistence.Table; -import javax.validation.constraints.Size; @Entity @Table(name = "authorities") -public class Authorities extends BaseEntity{ +public class Authorities{ + @Id + String username; - /** - * - */ - private static final long serialVersionUID = 1L; - - @ManyToOne - @JoinColumn(name = "username") - private Usuario user; - - @Size(min = 3, max = 50) - private String authority; - - public Usuario getUser() { - return user; + String authority; + + public String getUsername() { + return username; } - - public void setUser(Usuario usern) { - this.user = usern; + public void setUsername(String username) { + this.username = username; } - public String getAuthority() { return authority; } - public void setAuthority(String authority) { this.authority = authority; } - - public static long getSerialversionuid() { - return serialVersionUID; - } + + +// @ManyToOne +// @JoinColumn(name = "username") +// private Usuario user; +// +// @Size(min = 3, max = 50) +// private String authority; +// +// public Usuario getUser() { +// return user; +// } +// +// public void setUser(Usuario usern) { +// this.user = usern; +// } +// +// public String getAuthority() { +// return authority; +// } +// +// public void setAuthority(String authority) { +// this.authority = authority; +// } +// +// public static long getSerialversionuid() { +// return serialVersionUID; +// } } diff --git a/src/main/java/org/springframework/cheapy/model/Client.java b/src/main/java/org/springframework/cheapy/model/Client.java index b249311ff..7a563dbb2 100644 --- a/src/main/java/org/springframework/cheapy/model/Client.java +++ b/src/main/java/org/springframework/cheapy/model/Client.java @@ -1,25 +1,42 @@ package org.springframework.cheapy.model; +import java.time.LocalTime; import java.util.Set; +import javax.persistence.CascadeType; import javax.persistence.Entity; +import javax.persistence.JoinColumn; import javax.persistence.OneToMany; +import javax.persistence.OneToOne; import javax.persistence.Table; 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 User { - +public class Client extends BaseEntity{ + /** + * + */ + private static final long serialVersionUID = 1L; + + // (id, email, address, init, finish, telephone, description, code, food, usuar) @NotEmpty private String email; @NotEmpty private String address; - @NotEmpty - private String timetable; + //@DateTimeFormat(pattern = "HH:mm") + @NotBlank + private String init; + + //@DateTimeFormat(pattern = "HH:mm") + @NotBlank + private String finish; @NotEmpty @Digits(fraction = 0, integer = 10) @@ -34,6 +51,10 @@ public class Client extends User { @NotEmpty private String food; + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "username", referencedColumnName = "username") + private User usuar; + @OneToMany private Set foodOffers; @@ -46,6 +67,8 @@ public class Client extends User { @OneToMany private Set timeOffers; + + public String getEmail() { return email; } @@ -62,12 +85,29 @@ public class Client extends User { this.address = address; } - public String getTimetable() { - return timetable; + + public String getInit() { + return init; } - public void setTimetable(String timetable) { - this.timetable = timetable; + public void setInit(String init) { + this.init = init; + } + + public String getFinish() { + return finish; + } + + public void setFinish(String finish) { + this.finish = finish; + } + + public User getUsername() { + return usuar; + } + + public void setUsername(User username) { + this.usuar = username; } public String getTelephone() { @@ -101,4 +141,37 @@ public class Client extends User { public void setFood(String food) { this.food = food; } + + public Set getFoodOffers() { + return foodOffers; + } + + public void setFoodOffers(Set foodOffers) { + this.foodOffers = foodOffers; + } + + public Set getNuOffers() { + return nuOffers; + } + + public void setNuOffers(Set nuOffers) { + this.nuOffers = nuOffers; + } + + public Set getSpeedOffers() { + return speedOffers; + } + + public void setSpeedOffers(Set speedOffers) { + this.speedOffers = speedOffers; + } + + public Set getTimeOffers() { + return timeOffers; + } + + public void setTimeOffers(Set timeOffers) { + this.timeOffers = timeOffers; + } + } \ No newline at end of file diff --git a/src/main/java/org/springframework/cheapy/model/User.java b/src/main/java/org/springframework/cheapy/model/User.java index 36d495444..06ff128dd 100644 --- a/src/main/java/org/springframework/cheapy/model/User.java +++ b/src/main/java/org/springframework/cheapy/model/User.java @@ -15,9 +15,9 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; -//@Entity -//@Table(name = "users") -@MappedSuperclass +@Entity +@Table(name = "users") +//@MappedSuperclass public class User{ @Id @@ -46,11 +46,4 @@ public class User{ this.password = password; } -// public Set getAuthority() { -// return authorities; -// } -// -// public void setAuthorities(Set authorities) { -// this.authorities = authorities; -// } } diff --git a/src/main/java/org/springframework/cheapy/model/Usuario.java b/src/main/java/org/springframework/cheapy/model/Usuario.java index 3556ff16c..f6204abeb 100644 --- a/src/main/java/org/springframework/cheapy/model/Usuario.java +++ b/src/main/java/org/springframework/cheapy/model/Usuario.java @@ -5,22 +5,101 @@ 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; +import javax.validation.constraints.NotBlank; @Entity -@Table(name = "users") -public class Usuario extends User{ +@Table(name = "usuarios") +public class Usuario extends BaseEntity{ - @OneToMany(cascade = CascadeType.ALL, mappedBy = "user") - private Set authorities; + /** nombre, apellidos, dni, direccion, telefono, email, username + * (id,nombre, apellidos, dni, direccion, telefono, email, usuar) + */ + private static final long serialVersionUID = 1L; - public Set getAuthorities() { - return authorities; + @NotBlank + private String nombre; + + @NotBlank + private String apellidos; + + @NotBlank + private String dni; + + @NotBlank + private String direccion; + + @NotBlank + //@Pattern(regexp = "([+][^0][\\d]{0,2})?[ ]?([(][\\d]{0,4}[)])?[ ]?([\\d]{6,10})$") + private String telefono; + + @Email + @NotBlank + private String email; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "username", referencedColumnName = "username") + private User usuar; + + public String getNombre() { + return nombre; } - public void setAuthorities(Set authorities) { - this.authorities = authorities; + public void setNombre(String nombre) { + this.nombre = nombre; } + + public String getApellidos() { + return apellidos; + } + + public void setApellidos(String apellidos) { + this.apellidos = apellidos; + } + + public String getDni() { + return dni; + } + + public void setDni(String dni) { + this.dni = dni; + } + + public String getDireccion() { + return direccion; + } + + public void setDireccion(String direccion) { + this.direccion = direccion; + } + + public String getTelefono() { + return telefono; + } + + public void setTelefono(String telefono) { + this.telefono = telefono; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public User getUser() { + return usuar; + } + + public void setUser(User username) { + this.usuar = username; + } + } diff --git a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java index 3b5ffc987..d16d99bf6 100644 --- a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java @@ -7,6 +7,6 @@ import org.springframework.cheapy.model.Usuario; public interface UsuarioRepository extends CrudRepository { - Usuario findByUsername(String currentPrincipalName); + //Usuario findByUsername(String currentPrincipalName); } diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index b1bab7a65..7a294b596 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -19,6 +19,27 @@ 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 ('admin1','4dm1n',TRUE); +--INSERT INTO authorities(id,username,authority) VALUES (1,'admin1','admin'); +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 authorities VALUES ('paco','usuario'); +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 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');