mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 07:45:49 +00:00
codigo casi completo pero no funcional
This commit is contained in:
parent
5bfc714444
commit
65253a15c8
19 changed files with 672 additions and 225 deletions
|
@ -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());
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 <code>Owner</code> 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<FoodOffer, Integer> {
|
||||
|
||||
/**
|
||||
* Retrieve {@link Owner}s from the data store by last name, returning all owners
|
||||
* whose last name <i>starts</i> 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<FoodOffer> 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);
|
||||
|
||||
}
|
|
@ -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 <code>Owner</code> 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<NuOffer, Integer> {
|
||||
|
||||
/**
|
||||
* Retrieve {@link Owner}s from the data store by last name, returning all owners
|
||||
* whose last name <i>starts</i> 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<NuOffer> 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);
|
||||
|
||||
}
|
|
@ -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 <code>Owner</code> 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<SpeedOffer, Integer> {
|
||||
|
||||
/**
|
||||
* Retrieve {@link Owner}s from the data store by last name, returning all owners
|
||||
* whose last name <i>starts</i> 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<SpeedOffer> 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);
|
||||
|
||||
}
|
|
@ -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 <code>Owner</code> 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<TimeOffer, Integer> {
|
||||
|
||||
/**
|
||||
* Retrieve {@link Owner}s from the data store by last name, returning all owners
|
||||
* whose last name <i>starts</i> 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<TimeOffer> 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);
|
||||
|
||||
}
|
|
@ -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<FoodOffer> findAllFoodOffer() { //
|
||||
return this.foodOfferRepository.findAllFoodOffer();
|
||||
|
||||
}
|
||||
|
||||
public void saveOwner(final FoodOffer foodOffer) throws DataAccessException { //
|
||||
this.foodOfferRepository.save(foodOffer);
|
||||
|
||||
}
|
||||
}
|
|
@ -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<NuOffer> findAllNuOffer() { //
|
||||
return this.nuOfferRepository.findAllNuOffer();
|
||||
|
||||
}
|
||||
|
||||
public void saveOwner(final NuOffer nuOffer) throws DataAccessException { //
|
||||
this.nuOfferRepository.save(nuOffer);
|
||||
|
||||
}
|
||||
}
|
|
@ -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<SpeedOffer> findAllSpeedOffer() { //
|
||||
return this.speedOfferRepository.findAllSpeedOffer();
|
||||
|
||||
}
|
||||
|
||||
public void saveOwner(final SpeedOffer speedOffer) throws DataAccessException { //
|
||||
this.speedOfferRepository.save(speedOffer);
|
||||
|
||||
}
|
||||
}
|
|
@ -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<TimeOffer> findAllTimeOffer() { //
|
||||
return this.timeOfferRepository.findAllTimeOffer();
|
||||
|
||||
}
|
||||
|
||||
public void saveOwner(final TimeOffer timeOffer) throws DataAccessException { //
|
||||
this.timeOfferRepository.save(timeOffer);
|
||||
|
||||
}
|
||||
}
|
|
@ -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<User> 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
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -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<String, Object> model) {
|
||||
|
||||
List<FoodOffer> foodOfferLs=this.foodOfferService.findAllFoodOffer();
|
||||
List<NuOffer> nuOfferLs=this.nuOfferService.findAllNuOffer();
|
||||
List<SpeedOffer> speedOfferLs=this.speedOfferService.findAllSpeedOffer();
|
||||
List<TimeOffer> timeOfferLs=this.timeOfferService.findAllTimeOffer();
|
||||
|
||||
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;
|
||||
// }
|
||||
|
||||
|
||||
}
|
|
@ -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";
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
138
src/main/webapp/WEB-INF/jsp/offers/offersList.jsp
Normal file
138
src/main/webapp/WEB-INF/jsp/offers/offersList.jsp
Normal file
|
@ -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" %>
|
||||
|
||||
<cheapy:layout pageName="owners">
|
||||
<h2>Ofertas por plato específico</h2>
|
||||
|
||||
<table id="foodOfferTable" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 150px;">Restaurante</th>
|
||||
<th style="width: 150px;">Plato</th>
|
||||
<th style="width: 150px;">Fecha inicio</th>
|
||||
<th style="width: 200px;">Fecha fin</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="${foodOfferLs}" var="foodOffer">
|
||||
<tr>
|
||||
<td>
|
||||
<spring:url value="/offers/food/{offerId}" var="foodOfferUrl">
|
||||
<spring:param name="offerId" value="${foodOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(foodOfferUrl)}"><c:out value="${foodOffer.client.username}"/></a>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${foodOffer.food}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${foodOffer.start}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${foodOffer.end}"/>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2>Ofertas por número de comensales</h2>
|
||||
|
||||
<table id="nuOfferTable" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 150px;">Restaurante</th>
|
||||
<th style="width: 150px;">Fecha inicio</th>
|
||||
<th style="width: 200px;">Fecha fin</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="${nuOfferLs}" var="nuOffer">
|
||||
<tr>
|
||||
<td>
|
||||
<spring:url value="/offers/nu/{offerId}" var="nuOfferUrl">
|
||||
<spring:param name="offerId" value="${nuOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(nuOfferUrl)}"><c:out value="${nuOffer.client.username}"/></a>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${nuOffer.start}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${nuOffer.end}"/>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2>Ofertas por plato específico</h2>
|
||||
|
||||
<table id="speedOfferTable" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 150px;">Restaurante</th>
|
||||
<th style="width: 150px;">Fecha inicio</th>
|
||||
<th style="width: 200px;">Fecha fin</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="${speedOfferLs}" var="speedOffer">
|
||||
<tr>
|
||||
<td>
|
||||
<spring:url value="/offers/speed/{offerId}" var="speedOfferUrl">
|
||||
<spring:param name="offerId" value="${speedOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(speedOfferUrl)}"><c:out value="${speedOffer.client.username}"/></a>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${speedOffer.start}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${speedOffer.end}"/>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2>Ofertas por plato específico</h2>
|
||||
|
||||
<table id="timeOfferTable" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 150px;">Restaurante</th>
|
||||
<th style="width: 150px;">Fecha inicio</th>
|
||||
<th style="width: 200px;">Fecha fin</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="${timeOfferLs}" var="timeOffer">
|
||||
<tr>
|
||||
<td>
|
||||
<spring:url value="/offers/time/{offerId}" var="timeOfferUrl">
|
||||
<spring:param name="offerId" value="${timeOffer.id}"/>
|
||||
</spring:url>
|
||||
<a href="${fn:escapeXml(timeOfferUrl)}"><c:out value="${timeOffer.client.username}"/></a>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${timeOffer.start}"/>
|
||||
</td>
|
||||
<td>
|
||||
<c:out value="${foodOffer.end}"/>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
</cheapy:layout>
|
|
@ -28,7 +28,7 @@
|
|||
<span>Home</span>
|
||||
</cheapy:menuItem>
|
||||
|
||||
<cheapy:menuItem active="${name eq 'ofertas'}" url="/ofertas"
|
||||
<cheapy:menuItem active="${name eq 'ofertas'}" url="/offers"
|
||||
title="ofertas">
|
||||
<span class="glyphicon glyphicon-cutlery" aria-hidden="true"></span>
|
||||
<span>Ver ofertas</span>
|
||||
|
|
Loading…
Reference in a new issue