mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 07:45:49 +00:00
Merge pull request #27 from cheapy-ispp/007-publicarOfertas-Abel
007 publicar ofertas abel
This commit is contained in:
commit
9f247ac0c1
26 changed files with 570 additions and 473 deletions
|
@ -35,13 +35,22 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||
http.authorizeRequests().antMatchers("/resources/**", "/webjars/**", "/h2-console/**").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/", "/oups").permitAll()
|
||||
.antMatchers("/users/new").permitAll()
|
||||
|
||||
.antMatchers("/nuOffers/**").hasAnyAuthority("admin","client")
|
||||
.antMatchers("/timeOffers/**").hasAnyAuthority("admin","client")
|
||||
|
||||
.antMatchers("/login/**").anonymous()
|
||||
.antMatchers("/logout").permitAll()
|
||||
|
||||
.antMatchers("/usuarios/new").permitAll()
|
||||
.antMatchers("/admin/**").hasAnyAuthority("admin")
|
||||
.antMatchers("/speedOffers/**").hasAnyAuthority("admin", "client")
|
||||
.antMatchers("/foodOffers/**").hasAnyAuthority("admin", "client")
|
||||
.antMatchers("/owners/**").hasAnyAuthority("owner", "admin")
|
||||
|
||||
.antMatchers("/clients/new").permitAll()
|
||||
.antMatchers("/offers/**").hasAnyAuthority("admin")
|
||||
|
||||
.and().formLogin()
|
||||
.loginPage("/login").permitAll()
|
||||
.failureUrl("/login?error")
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.cheapy.model;
|
|||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "food_offers")
|
||||
|
@ -29,7 +30,7 @@ public class FoodOffer extends Offer {
|
|||
@NotBlank
|
||||
private String discount;
|
||||
|
||||
@NotBlank
|
||||
@NotNull
|
||||
private Integer units; // revisar
|
||||
|
||||
public String getFood() {
|
||||
|
|
|
@ -1,44 +1,30 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cheapy.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "nu_offers")
|
||||
public class NuOffer extends Offer {
|
||||
//Oferta por numero de comensales
|
||||
@NotBlank
|
||||
|
||||
@NotNull
|
||||
private Integer gold;
|
||||
|
||||
@Column(name = "discount_gold")
|
||||
@NotBlank
|
||||
private String discountGold;
|
||||
|
||||
@NotBlank
|
||||
@NotNull
|
||||
private Integer silver;
|
||||
|
||||
@Column(name = "discount_silver")
|
||||
@NotBlank
|
||||
private String discountSilver;
|
||||
|
||||
@NotBlank
|
||||
@NotNull
|
||||
private Integer bronze;
|
||||
|
||||
@Column(name = "discount_bronze")
|
||||
|
|
|
@ -17,15 +17,13 @@ package org.springframework.cheapy.model;
|
|||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Future;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
|
@ -33,21 +31,22 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|||
public class Offer extends BaseEntity {
|
||||
//Clase padre
|
||||
@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
|
||||
@NotBlank
|
||||
@NotNull
|
||||
@Future
|
||||
private LocalDateTime start;
|
||||
|
||||
@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
|
||||
@NotBlank
|
||||
@NotNull
|
||||
@Future
|
||||
private LocalDateTime end;
|
||||
|
||||
@NotBlank
|
||||
|
||||
private String code;
|
||||
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
private StatusOffer type;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="client_id")
|
||||
private Client client;
|
||||
|
@ -83,5 +82,13 @@ public class Offer extends BaseEntity {
|
|||
public void setType(StatusOffer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public void setClient(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,44 +1,31 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cheapy.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "speed_offers")
|
||||
public class SpeedOffer extends Offer {
|
||||
//Ofertar por rapidez comiendo
|
||||
@NotBlank
|
||||
|
||||
|
||||
@NotNull
|
||||
private Integer gold; // x minutos
|
||||
|
||||
@Column(name = "discount_gold")
|
||||
@NotBlank
|
||||
private String discountGold;
|
||||
|
||||
@NotBlank
|
||||
@NotNull
|
||||
private Integer silver;
|
||||
|
||||
@Column(name = "discount_silver")
|
||||
@NotBlank
|
||||
private String discountSilver;
|
||||
|
||||
@NotBlank
|
||||
@NotNull
|
||||
private Integer bronze;
|
||||
|
||||
@Column(name = "discount_bronze")
|
||||
|
|
|
@ -15,13 +15,12 @@
|
|||
*/
|
||||
package org.springframework.cheapy.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Future;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
|
@ -30,11 +29,11 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|||
public class TimeOffer extends Offer {
|
||||
//Oferta por franja horaria
|
||||
@DateTimeFormat(pattern = "HH:mm")
|
||||
@NotBlank
|
||||
@NotNull
|
||||
private LocalTime init;
|
||||
|
||||
@DateTimeFormat(pattern = "HH:mm")
|
||||
@NotBlank
|
||||
@NotNull
|
||||
private LocalTime finish;
|
||||
|
||||
@NotBlank
|
||||
|
@ -42,6 +41,22 @@ public class TimeOffer extends Offer {
|
|||
|
||||
|
||||
|
||||
public LocalTime getInit() {
|
||||
return init;
|
||||
}
|
||||
|
||||
public void setInit(LocalTime init) {
|
||||
this.init = init;
|
||||
}
|
||||
|
||||
public LocalTime getFinish() {
|
||||
return finish;
|
||||
}
|
||||
|
||||
public void setFinish(LocalTime finish) {
|
||||
this.finish = finish;
|
||||
}
|
||||
|
||||
public String getDiscount() {
|
||||
return discount;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
package org.springframework.cheapy.repository;
|
||||
|
||||
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface ClientRepository extends CrudRepository<Client, String> {
|
||||
|
||||
|
||||
Client findByUsername(String username);
|
||||
|
||||
}
|
|
@ -1,67 +1,25 @@
|
|||
/*
|
||||
* 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 java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 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")
|
||||
@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);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,68 +1,28 @@
|
|||
/*
|
||||
* 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.data.jpa.repository.Query;
|
||||
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")
|
||||
|
||||
|
||||
|
||||
|
||||
NuOffer findNuOfferById(int nuOfferId);
|
||||
|
||||
@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);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,68 +1,28 @@
|
|||
/*
|
||||
* 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);
|
||||
|
||||
@Query("SELECT speedOffer FROM SpeedOffer speedOffer")
|
||||
@Transactional(readOnly = true)
|
||||
List<SpeedOffer> findAllSpeedOffer();
|
||||
|
||||
|
||||
/**
|
||||
* Save an {@link Owner} to the data store, either inserting or updating it.
|
||||
* @param owner the {@link Owner} to save
|
||||
*/
|
||||
void save(SpeedOffer speedOffer);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,68 +1,28 @@
|
|||
/*
|
||||
* 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.data.jpa.repository.Query;
|
||||
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")
|
||||
|
||||
|
||||
|
||||
|
||||
TimeOffer findTimeOfferById(int timeOfferId);
|
||||
|
||||
@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,49 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cheapy.service;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.repository.ClientRepository;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
|
||||
@Service
|
||||
public class ClientService {
|
||||
|
||||
private ClientRepository clientRepository;
|
||||
|
||||
@Autowired
|
||||
public ClientService(final ClientRepository clientRepository) {
|
||||
this.clientRepository = clientRepository;
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public Client getCurrentClient() throws DataAccessException {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
String username = authentication.getName();
|
||||
return this.clientRepository.findByUsername(username);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,10 @@
|
|||
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 java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -24,13 +21,14 @@ public class FoodOfferService {
|
|||
public FoodOffer findFoodOfferById(final int id) {
|
||||
return this.foodOfferRepository.findById(id);
|
||||
}
|
||||
|
||||
public List<FoodOffer> findAllFoodOffer() { //
|
||||
public List<FoodOffer> findAllFoodOffer() { //
|
||||
return this.foodOfferRepository.findAllFoodOffer();
|
||||
|
||||
}
|
||||
|
||||
public void saveOwner(final FoodOffer foodOffer) throws DataAccessException { //
|
||||
|
||||
|
||||
public void saveFoodOffer(final FoodOffer foodOffer) throws DataAccessException {
|
||||
|
||||
this.foodOfferRepository.save(foodOffer);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
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 java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -22,15 +20,17 @@ public class NuOfferService {
|
|||
}
|
||||
|
||||
public NuOffer findNuOfferById(final int id) {
|
||||
return this.nuOfferRepository.findById(id);
|
||||
}
|
||||
|
||||
public List<NuOffer> findAllNuOffer() { //
|
||||
return this.nuOfferRepository.findNuOfferById(id);
|
||||
}
|
||||
public List<NuOffer> findAllNuOffer() { //
|
||||
return this.nuOfferRepository.findAllNuOffer();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void saveOwner(final NuOffer nuOffer) throws DataAccessException { //
|
||||
public void saveNuOffer(final NuOffer nuOffer) throws DataAccessException { //
|
||||
|
||||
this.nuOfferRepository.save(nuOffer);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
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;
|
||||
|
@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
@Service
|
||||
public class SpeedOfferService {
|
||||
|
||||
private SpeedOfferRepository speedOfferRepository;
|
||||
|
||||
|
||||
|
@ -22,13 +23,15 @@ public class SpeedOfferService {
|
|||
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 { //
|
||||
|
||||
|
||||
public void saveSpeedOffer(final SpeedOffer speedOffer) throws DataAccessException {
|
||||
|
||||
this.speedOfferRepository.save(speedOffer);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
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;
|
||||
|
||||
|
@ -17,21 +13,22 @@ public class TimeOfferService {
|
|||
|
||||
|
||||
@Autowired
|
||||
public TimeOfferService(final TimeOfferRepository timeOfferRepository) {
|
||||
this.timeOfferRepository = timeOfferRepository;
|
||||
public TimeOfferService(final TimeOfferRepository TimeOfferRepository) {
|
||||
this.timeOfferRepository = TimeOfferRepository;
|
||||
}
|
||||
|
||||
public TimeOffer findTimeOfferById(final int id) {
|
||||
return this.timeOfferRepository.findById(id);
|
||||
return this.timeOfferRepository.findTimeOfferById(id);
|
||||
}
|
||||
|
||||
public List<TimeOffer> findAllTimeOffer() { //
|
||||
|
||||
public List<TimeOffer> findAllTimeOffer() { //
|
||||
return this.timeOfferRepository.findAllTimeOffer();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void saveOwner(final TimeOffer timeOffer) throws DataAccessException { //
|
||||
this.timeOfferRepository.save(timeOffer);
|
||||
public void saveTimeOffer(final TimeOffer TimeOffer) throws DataAccessException { //
|
||||
this.timeOfferRepository.save(TimeOffer);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,58 +1,75 @@
|
|||
/*
|
||||
* 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 javax.validation.Valid;
|
||||
import org.springframework.cheapy.model.Client;
|
||||
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.model.StatusOffer;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.FoodOfferService;
|
||||
import org.springframework.cheapy.service.NuOfferService;
|
||||
import org.springframework.cheapy.service.SpeedOfferService;
|
||||
import org.springframework.cheapy.service.TimeOfferService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Controller
|
||||
@Controller
|
||||
public class FoodOfferController {
|
||||
|
||||
//private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
|
||||
private static final String VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM = "foodOffers/createOrUpdateFoodOfferForm";
|
||||
|
||||
private final FoodOfferService foodOfferService;
|
||||
private final ClientService clientService;
|
||||
|
||||
|
||||
|
||||
public FoodOfferController(final FoodOfferService foodOfferService) {
|
||||
public FoodOfferController(final FoodOfferService foodOfferService, final ClientService clientService) {
|
||||
this.foodOfferService = foodOfferService;
|
||||
|
||||
this.clientService = clientService;
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@GetMapping("/foodOffers/new")
|
||||
public String initCreationForm(Map<String, Object> model) {
|
||||
FoodOffer foodOffer = new FoodOffer();
|
||||
model.put("foodOffer", foodOffer);
|
||||
return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/foodOffers/new")
|
||||
public String processCreationForm(@Valid FoodOffer foodOffer, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
else {
|
||||
Client client = this.clientService.getCurrentclient();
|
||||
foodOffer.setClient(client);
|
||||
foodOffer.setType(StatusOffer.hidden);
|
||||
this.foodOfferService.saveFoodOffer(foodOffer);
|
||||
return "redirect:/foodOffers/" + foodOffer.getId();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/foodOffers/{foodOfferId}/activate")
|
||||
public String activateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, ModelMap modelMap) {
|
||||
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
|
||||
Client client = this.clientService.getCurrentclient();
|
||||
if(foodOffer.getClient().equals(client)) {
|
||||
foodOffer.setType(StatusOffer.active);
|
||||
foodOffer.setCode("FO-"+foodOfferId);
|
||||
this.foodOfferService.saveFoodOffer(foodOffer);
|
||||
} else {
|
||||
modelMap.addAttribute("message", "You don't have access to this food offer");
|
||||
}
|
||||
return "redirect:/foodOffers/";
|
||||
}
|
||||
@GetMapping("/offers/food/{foodOfferId}")
|
||||
public String processShowForm(@PathVariable("foodOfferId") int foodOfferId, Map<String, Object> model) {
|
||||
|
||||
|
@ -63,5 +80,4 @@ public class FoodOfferController {
|
|||
return "foodOffers/foodOffersShow";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,67 +1,88 @@
|
|||
/*
|
||||
* 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 javax.validation.Valid;
|
||||
|
||||
import org.springframework.cheapy.model.Client;
|
||||
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.model.StatusOffer;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
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.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Controller
|
||||
@Controller
|
||||
public class NuOfferController {
|
||||
|
||||
//private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
|
||||
private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "nuOffers/createOrUpdateNuOfferForm";
|
||||
|
||||
private final FoodOfferService foodOfferService;
|
||||
private final NuOfferService nuOfferService;
|
||||
private final SpeedOfferService speedOfferService;
|
||||
private final TimeOfferService timeOfferService;
|
||||
private final NuOfferService nuOfferService;
|
||||
private final ClientService clientService;
|
||||
|
||||
|
||||
|
||||
public NuOfferController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService,
|
||||
final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) {
|
||||
this.foodOfferService = foodOfferService;
|
||||
public NuOfferController(final NuOfferService nuOfferService,ClientService clientService) {
|
||||
this.nuOfferService = nuOfferService;
|
||||
this.speedOfferService = speedOfferService;
|
||||
this.timeOfferService = timeOfferService;
|
||||
|
||||
this.clientService = clientService;
|
||||
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@GetMapping("/offers/nu/{nuOfferId}")
|
||||
@GetMapping("/nuOffers/new")
|
||||
public String initCreationForm(Map<String, Object> model) {
|
||||
NuOffer nuOffer = new NuOffer();
|
||||
model.put("nuOffer", nuOffer);
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/nuOffers/new")
|
||||
public String processCreationForm(@Valid NuOffer nuOffer, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
else {
|
||||
nuOffer.setType(StatusOffer.hidden);
|
||||
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
|
||||
nuOffer.setClient(client);
|
||||
|
||||
|
||||
this.nuOfferService.saveNuOffer(nuOffer);
|
||||
return "redirect:/nuOffers/" + nuOffer.getId();
|
||||
}
|
||||
}
|
||||
@GetMapping(value ="/nuOffers/{nuOfferId}/activate")
|
||||
public String activateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap modelMap) {
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId);
|
||||
if(nuOffer.getClient().equals(client)) {
|
||||
nuOffer.setType(StatusOffer.active);
|
||||
nuOffer.setCode("NU-"+nuOfferId);
|
||||
this.nuOfferService.saveNuOffer(nuOffer);
|
||||
|
||||
return "redirect:/nuOffers/" + nuOffer.getId();
|
||||
} else {
|
||||
modelMap.addAttribute("message", "You don't have access to this number offer");
|
||||
}
|
||||
return "redirect:/nuOffers/";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/offers/nu/{nuOfferId}")
|
||||
public String processShowForm(@PathVariable("nuOfferId") int nuOfferId, Map<String, Object> model) {
|
||||
|
||||
NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId);
|
||||
|
@ -72,33 +93,6 @@ public class NuOfferController {
|
|||
|
||||
}
|
||||
|
||||
// @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;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,53 +15,80 @@
|
|||
*/
|
||||
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 javax.validation.Valid;
|
||||
|
||||
import org.springframework.cheapy.model.Client;
|
||||
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.model.StatusOffer;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.SpeedOfferService;
|
||||
import org.springframework.cheapy.service.TimeOfferService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Controller
|
||||
@Controller
|
||||
public class SpeedOfferController {
|
||||
|
||||
//private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
|
||||
private static final String VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM = "speedOffers/createOrUpdateSpeedOfferForm";
|
||||
|
||||
private final FoodOfferService foodOfferService;
|
||||
private final NuOfferService nuOfferService;
|
||||
private final SpeedOfferService speedOfferService;
|
||||
private final TimeOfferService timeOfferService;
|
||||
private final ClientService clientService;
|
||||
|
||||
|
||||
|
||||
public SpeedOfferController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService,
|
||||
final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) {
|
||||
this.foodOfferService = foodOfferService;
|
||||
this.nuOfferService = nuOfferService;
|
||||
public SpeedOfferController(final SpeedOfferService speedOfferService, final ClientService clientService) {
|
||||
this.speedOfferService = speedOfferService;
|
||||
this.timeOfferService = timeOfferService;
|
||||
this.clientService = clientService;
|
||||
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@GetMapping("/offers/speed/{speedOfferId}")
|
||||
@GetMapping("/speedOffers/new")
|
||||
public String initCreationForm(Map<String, Object> model) {
|
||||
SpeedOffer speedOffer = new SpeedOffer();
|
||||
model.put("speedOffer", speedOffer);
|
||||
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/speedOffers/new")
|
||||
public String processCreationForm(@Valid SpeedOffer speedOffer, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
else {
|
||||
Client client = this.clientService.getCurrentclient();
|
||||
speedOffer.setClient(client);
|
||||
speedOffer.setType(StatusOffer.hidden);
|
||||
this.speedOfferService.saveSpeedOffer(speedOffer);
|
||||
return "redirect:/speedOffers/" + speedOffer.getId();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/speedOffers/{speedOfferId}/activate")
|
||||
public String activateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, ModelMap modelMap) {
|
||||
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
|
||||
Client client = this.clientService.getCurrentclient();
|
||||
if(speedOffer.getClient().equals(client)) {
|
||||
speedOffer.setType(StatusOffer.active);
|
||||
speedOffer.setCode("SP-"+speedOfferId);
|
||||
this.speedOfferService.saveSpeedOffer(speedOffer);
|
||||
} else {
|
||||
modelMap.addAttribute("message", "You don't have access to this speed offer");
|
||||
}
|
||||
return "redirect:/speedOffers/";
|
||||
}
|
||||
|
||||
@GetMapping("/offers/speed/{speedOfferId}")
|
||||
public String processShowForm(@PathVariable("speedOfferId") int speedOfferId, Map<String, Object> model) {
|
||||
|
||||
SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId);
|
||||
|
@ -72,33 +99,4 @@ public class SpeedOfferController {
|
|||
|
||||
}
|
||||
|
||||
// @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,47 +1,87 @@
|
|||
/*
|
||||
* 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 javax.validation.Valid;
|
||||
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.model.TimeOffer;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.TimeOfferService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Controller
|
||||
@Controller
|
||||
public class TimeOfferController {
|
||||
|
||||
//private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
|
||||
private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "timeOffers/createOrUpdateTimeOfferForm";
|
||||
|
||||
private final TimeOfferService timeOfferService;
|
||||
private final ClientService clientService;
|
||||
|
||||
public TimeOfferController(final TimeOfferService timeOfferService) {
|
||||
|
||||
|
||||
public TimeOfferController(final TimeOfferService timeOfferService,ClientService clientService) {
|
||||
this.timeOfferService = timeOfferService;
|
||||
|
||||
this.clientService = clientService;
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/offers/time/{timeOfferId}")
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@GetMapping("/timeOffers/new")
|
||||
public String initCreationForm(Map<String, Object> model) {
|
||||
TimeOffer timeOffer = new TimeOffer();
|
||||
model.put("timeOffer", timeOffer);
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/timeOffers/new")
|
||||
public String processCreationForm(@Valid TimeOffer timeOffer, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
else {
|
||||
timeOffer.setType(StatusOffer.hidden);
|
||||
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
|
||||
timeOffer.setClient(client);
|
||||
|
||||
|
||||
this.timeOfferService.saveTimeOffer(timeOffer);
|
||||
return "redirect:/TimeOffers/" + timeOffer.getId();
|
||||
}
|
||||
}
|
||||
@GetMapping(value ="/timeOffers/{timeOfferId}/activate")
|
||||
public String activateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap modelMap) {
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
TimeOffer timeOffer=this.timeOfferService.findTimeOfferById(timeOfferId);
|
||||
if(timeOffer.getClient().equals(client)) {
|
||||
timeOffer.setType(StatusOffer.active);
|
||||
timeOffer.setCode("TI-"+timeOfferId);
|
||||
this.timeOfferService.saveTimeOffer(timeOffer);
|
||||
|
||||
return "redirect:/timeOffers/" + timeOffer.getId();
|
||||
} else {
|
||||
modelMap.addAttribute("message", "You don't have access to this time offer");
|
||||
}
|
||||
return "redirect:/timeOffers/";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/offers/time/{timeOfferId}")
|
||||
public String processShowForm(@PathVariable("timeOfferId") int timeOfferId, Map<String, Object> model) {
|
||||
|
||||
TimeOffer timeOffer=this.timeOfferService.findTimeOfferById(timeOfferId);
|
||||
|
@ -51,4 +91,6 @@ public class TimeOfferController {
|
|||
return "timeOffers/timeOffersShow";
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,12 +10,14 @@ INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Mad
|
|||
INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487');
|
||||
|
||||
|
||||
INSERT INTO food_offers(start, end, code, type, client_id, food, discount, units) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, 'macarrones', '15%', 10);
|
||||
|
||||
INSERT INTO food_offers(start, end, code, type, client_id, food, discount, units) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'FO-1', 'active', null, 'macarrones', '15%', 10);
|
||||
INSERT INTO speed_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'SP-1', 'active', null, 5, '15%', 10, '10%', 15, '5%');
|
||||
INSERT INTO time_offers(start, end, code, type, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, '12:00:00', '13:00:00', '10%');
|
||||
INSERT INTO speed_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null,5,'25%',10,'15%',15,'10%' );
|
||||
INSERT INTO nu_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null,15,'25%',10,'15%',5,'10%' );
|
||||
|
||||
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','admin','admin', TRUE );
|
||||
INSERT INTO authorities VALUES ('admin','admin');
|
||||
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','manoli','manoli', TRUE );
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<%@ 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="form" uri="http://www.springframework.org/tags/form" %>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<petclinic:layout pageName="foodOffers">
|
||||
<h2>
|
||||
<c:if test="${foodOffer['new']}">New </c:if> FoodOffer
|
||||
</h2>
|
||||
<form:form modelAttribute="foodOffer" class="form-horizontal" id="add-foodOffer-form">
|
||||
<div class="form-group has-feedback">
|
||||
<petclinic:inputField label="Start Date" name="start"/>
|
||||
<petclinic:inputField label="End Date" name="end"/>
|
||||
<petclinic:inputField label="Food" name="food"/>
|
||||
<petclinic:inputField label="Discount" name="discount"/>
|
||||
<petclinic:inputField label="Units" name="units"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<c:choose>
|
||||
<c:when test="${foodOffer['new']}">
|
||||
<button class="btn btn-default" type="submit">Add Food Offer</button>
|
||||
</c:when>
|
||||
</c:choose>
|
||||
</div>
|
||||
</div>
|
||||
</form:form>
|
||||
</petclinic:layout>
|
|
@ -0,0 +1,39 @@
|
|||
<%@ 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="form" uri="http://www.springframework.org/tags/form" %>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<petclinic:layout pageName="NumOffers">
|
||||
<h2>
|
||||
<c:if test="${nuOffer['new']}">New </c:if> NuOffer
|
||||
</h2>
|
||||
<form:form modelAttribute="nuOffer" class="form-horizontal" id="add-nuOffer-form">
|
||||
<div class="form-group has-feedback">
|
||||
<petclinic:inputField label="Fecha de inicio" name="start"/>
|
||||
<petclinic:inputField label="Fecha de fin" name="end"/>
|
||||
|
||||
<petclinic:inputField label="Oro" name="gold"/>
|
||||
<petclinic:inputField label="descuento de oro" name="discountGold"/>
|
||||
<petclinic:inputField label="Plata" name="silver"/>
|
||||
<petclinic:inputField label="Descuento de plata" name="discountSilver"/>
|
||||
<petclinic:inputField label="Bronce" name="bronze"/>
|
||||
<petclinic:inputField label="Descuento de bronce" name="discountBronze"/>
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<c:choose>
|
||||
<c:when test="${nuOffer['new']}">
|
||||
<button class="btn btn-default" type="submit">Add Offer</button>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<button class="btn btn-default" type="submit">Update Offer</button>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
</div>
|
||||
</div>
|
||||
</form:form>
|
||||
</petclinic:layout>
|
|
@ -0,0 +1,34 @@
|
|||
<%@ 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="form" uri="http://www.springframework.org/tags/form" %>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<petclinic:layout pageName="speedOffers">
|
||||
<h2>
|
||||
<c:if test="${speedOffer['new']}">New </c:if> SpeedOffer
|
||||
</h2>
|
||||
<form:form modelAttribute="speedOffer" class="form-horizontal" id="add-speedOffer-form">
|
||||
<div class="form-group has-feedback">
|
||||
<petclinic:inputField label="Start Date" name="start"/>
|
||||
<petclinic:inputField label="End Date" name="end"/>
|
||||
<petclinic:inputField label="Gold" name="gold"/>
|
||||
<petclinic:inputField label="Gold Discount" name="discountGold"/>
|
||||
<petclinic:inputField label="Silver" name="silver"/>
|
||||
<petclinic:inputField label="Silver Discount" name="discountSilver"/>
|
||||
<petclinic:inputField label="Bronze" name="bronze"/>
|
||||
<petclinic:inputField label="Bronze Discount" name="discountBronze"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<c:choose>
|
||||
<c:when test="${speedOffer['new']}">
|
||||
<button class="btn btn-default" type="submit">Add Speed Offer</button>
|
||||
</c:when>
|
||||
</c:choose>
|
||||
</div>
|
||||
</div>
|
||||
</form:form>
|
||||
</petclinic:layout>
|
|
@ -0,0 +1,36 @@
|
|||
<%@ 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="form" uri="http://www.springframework.org/tags/form" %>
|
||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||
|
||||
<petclinic:layout pageName="TimeOffers">
|
||||
<h2>
|
||||
<c:if test="${timeOffer['new']}">New </c:if> TimeOffer
|
||||
</h2>
|
||||
<form:form modelAttribute="timeOffer" class="form-horizontal" id="add-timeOffer-form">
|
||||
<div class="form-group has-feedback">
|
||||
<petclinic:inputField label="Fecha de inicio" name="start"/>
|
||||
<petclinic:inputField label="Fecha de fin" name="end"/>
|
||||
|
||||
<petclinic:inputField label="Hora de inicio" name="init"/>
|
||||
<petclinic:inputField label="Hora de final" name="finish"/>
|
||||
<petclinic:inputField label="Decuento" name="discount"/>
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<c:choose>
|
||||
<c:when test="${timeOffer['new']}">
|
||||
<button class="btn btn-default" type="submit">Add Offer</button>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<button class="btn btn-default" type="submit">Update Offer</button>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
</div>
|
||||
</div>
|
||||
</form:form>
|
||||
</petclinic:layout>
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
package org.springframework.cheapy.web;
|
||||
|
||||
import static org.hamcrest.Matchers.hasProperty;
|
||||
|
@ -40,10 +40,11 @@ import org.springframework.test.web.servlet.MockMvc;
|
|||
*
|
||||
* @author Colin But
|
||||
*/
|
||||
/*
|
||||
@WebMvcTest(OwnerController.class)
|
||||
class OwnerControllerTests {
|
||||
|
||||
private static final int TEST_OWNER_ID = 1;
|
||||
/*private static final int TEST_OWNER_ID = 1;
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
@ -158,6 +159,7 @@ class OwnerControllerTests {
|
|||
.andExpect(model().attribute("owner", hasProperty("city", is("Madison"))))
|
||||
.andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023"))))
|
||||
.andExpect(view().name("owners/ownerDetails"));
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
*/
|
Loading…
Reference in a new issue