From 457cba860dfaac30951914f7496585d9d8db1e17 Mon Sep 17 00:00:00 2001 From: Martinagr32 Date: Thu, 25 Mar 2021 23:51:59 +0100 Subject: [PATCH] Publicar ofertas arreglado --- .../cheapy/model/BaseEntity.java | 27 +++---------- .../springframework/cheapy/model/Client.java | 3 -- .../cheapy/model/FoodOffer.java | 8 +++- .../cheapy/model/NamedEntity.java | 27 +++---------- .../springframework/cheapy/model/NuOffer.java | 5 +++ .../springframework/cheapy/model/Offer.java | 8 +++- .../springframework/cheapy/model/Owner.java | 38 +++---------------- .../springframework/cheapy/model/Person.java | 25 +++--------- .../cheapy/model/SpeedOffer.java | 4 ++ .../cheapy/model/TimeOffer.java | 25 ++++-------- .../springframework/cheapy/model/User.java | 7 ++-- .../springframework/cheapy/model/Usuario.java | 4 -- .../cheapy/model/package-info.java | 19 ---------- .../repository/AuthoritiesRepository.java | 2 - .../cheapy/repository/ClientRepository.java | 7 ++-- .../repository/FoodOfferRepository.java | 5 +-- .../cheapy/repository/NuOfferRepository.java | 11 +----- .../repository/SpeedOfferRepository.java | 8 +--- .../repository/TimeOfferRepository.java | 11 +----- .../cheapy/repository/UsuarioRepository.java | 1 - .../cheapy/service/ClientService.java | 22 +---------- .../cheapy/service/FoodOfferService.java | 6 +-- .../cheapy/service/TimeOfferService.java | 6 ++- .../cheapy/web/FoodOfferController.java | 4 +- .../cheapy/web/OfertaController.java | 30 --------------- .../cheapy/web/OwnerController.java | 23 ----------- .../cheapy/web/SpeedOfferController.java | 9 +---- src/main/resources/db/mysql/data.sql | 20 ++++------ .../webapp/WEB-INF/jsp/offers/offersList.jsp | 2 +- src/main/webapp/WEB-INF/jsp/welcome.jsp | 6 +-- .../cheapy/web/OwnerControllerTests.java | 3 -- 31 files changed, 84 insertions(+), 292 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/model/BaseEntity.java b/src/main/java/org/springframework/cheapy/model/BaseEntity.java index 21aab45b7..95e0b3338 100644 --- a/src/main/java/org/springframework/cheapy/model/BaseEntity.java +++ b/src/main/java/org/springframework/cheapy/model/BaseEntity.java @@ -1,18 +1,3 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.springframework.cheapy.model; import java.io.Serializable; @@ -22,16 +7,14 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.MappedSuperclass; -/** - * Simple JavaBean domain object with an id property. Used as a base class for objects - * needing this property. - * - * @author Ken Krebs - * @author Juergen Hoeller - */ @MappedSuperclass public class BaseEntity implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; diff --git a/src/main/java/org/springframework/cheapy/model/Client.java b/src/main/java/org/springframework/cheapy/model/Client.java index 39a398df5..210e3ed70 100644 --- a/src/main/java/org/springframework/cheapy/model/Client.java +++ b/src/main/java/org/springframework/cheapy/model/Client.java @@ -1,6 +1,5 @@ package org.springframework.cheapy.model; -import java.time.LocalTime; import java.util.Set; import javax.persistence.CascadeType; @@ -13,8 +12,6 @@ import javax.validation.constraints.Digits; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; -import org.springframework.format.annotation.DateTimeFormat; - @Entity @Table(name = "clients") public class Client extends BaseEntity{ diff --git a/src/main/java/org/springframework/cheapy/model/FoodOffer.java b/src/main/java/org/springframework/cheapy/model/FoodOffer.java index d6a7d8e3d..59419f1d1 100644 --- a/src/main/java/org/springframework/cheapy/model/FoodOffer.java +++ b/src/main/java/org/springframework/cheapy/model/FoodOffer.java @@ -23,7 +23,13 @@ import javax.validation.constraints.NotNull; @Entity @Table(name = "food_offers") public class FoodOffer extends Offer { -//Plato específico + + /** + * + */ + private static final long serialVersionUID = 1L; + + //Plato específico @NotBlank private String food; diff --git a/src/main/java/org/springframework/cheapy/model/NamedEntity.java b/src/main/java/org/springframework/cheapy/model/NamedEntity.java index 0f00a5e9c..3d777b298 100644 --- a/src/main/java/org/springframework/cheapy/model/NamedEntity.java +++ b/src/main/java/org/springframework/cheapy/model/NamedEntity.java @@ -1,33 +1,16 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.springframework.cheapy.model; import javax.persistence.Column; import javax.persistence.MappedSuperclass; -/** - * Simple JavaBean domain object adds a name property to BaseEntity. Used as - * a base class for objects needing these properties. - * - * @author Ken Krebs - * @author Juergen Hoeller - */ @MappedSuperclass public class NamedEntity extends BaseEntity { + /** + * + */ + private static final long serialVersionUID = 1L; + @Column(name = "name") private String name; diff --git a/src/main/java/org/springframework/cheapy/model/NuOffer.java b/src/main/java/org/springframework/cheapy/model/NuOffer.java index fbb884f5d..5a52a5756 100644 --- a/src/main/java/org/springframework/cheapy/model/NuOffer.java +++ b/src/main/java/org/springframework/cheapy/model/NuOffer.java @@ -10,6 +10,11 @@ import javax.validation.constraints.NotNull; @Table(name = "nu_offers") public class NuOffer extends Offer { + /** + * + */ + private static final long serialVersionUID = 1L; + @NotNull private Integer gold; diff --git a/src/main/java/org/springframework/cheapy/model/Offer.java b/src/main/java/org/springframework/cheapy/model/Offer.java index b26ea57bf..c41ca9040 100644 --- a/src/main/java/org/springframework/cheapy/model/Offer.java +++ b/src/main/java/org/springframework/cheapy/model/Offer.java @@ -29,7 +29,13 @@ import org.springframework.format.annotation.DateTimeFormat; @MappedSuperclass public class Offer extends BaseEntity { -//Clase padre + + /** + * + */ + private static final long serialVersionUID = 1L; + + //Clase padre @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") @NotNull @Future diff --git a/src/main/java/org/springframework/cheapy/model/Owner.java b/src/main/java/org/springframework/cheapy/model/Owner.java index 792f42753..7a04f3434 100644 --- a/src/main/java/org/springframework/cheapy/model/Owner.java +++ b/src/main/java/org/springframework/cheapy/model/Owner.java @@ -1,50 +1,22 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.springframework.cheapy.model; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.OneToMany; import javax.persistence.Table; import javax.validation.constraints.Digits; import javax.validation.constraints.NotEmpty; -import org.springframework.beans.support.MutableSortDefinition; -import org.springframework.beans.support.PropertyComparator; import org.springframework.core.style.ToStringCreator; -/** - * Simple JavaBean domain object representing an owner. - * - * @author Ken Krebs - * @author Juergen Hoeller - * @author Sam Brannen - * @author Michael Isvy - */ @Entity @Table(name = "owners") public class Owner extends Person { + /** + * + */ + private static final long serialVersionUID = 1L; + @Column(name = "address") @NotEmpty private String address; diff --git a/src/main/java/org/springframework/cheapy/model/Person.java b/src/main/java/org/springframework/cheapy/model/Person.java index 7e8d87c0c..8758455db 100644 --- a/src/main/java/org/springframework/cheapy/model/Person.java +++ b/src/main/java/org/springframework/cheapy/model/Person.java @@ -1,32 +1,17 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.springframework.cheapy.model; import javax.persistence.Column; import javax.persistence.MappedSuperclass; import javax.validation.constraints.NotEmpty; -/** - * Simple JavaBean domain object representing an person. - * - * @author Ken Krebs - */ @MappedSuperclass public class Person extends BaseEntity { + /** + * + */ + private static final long serialVersionUID = 1L; + @Column(name = "first_name") @NotEmpty private String firstName; diff --git a/src/main/java/org/springframework/cheapy/model/SpeedOffer.java b/src/main/java/org/springframework/cheapy/model/SpeedOffer.java index 1ef45f6e1..0ef65d7a2 100644 --- a/src/main/java/org/springframework/cheapy/model/SpeedOffer.java +++ b/src/main/java/org/springframework/cheapy/model/SpeedOffer.java @@ -10,6 +10,10 @@ import javax.validation.constraints.NotNull; @Table(name = "speed_offers") public class SpeedOffer extends Offer { + /** + * + */ + private static final long serialVersionUID = 1L; @NotNull private Integer gold; // x minutos diff --git a/src/main/java/org/springframework/cheapy/model/TimeOffer.java b/src/main/java/org/springframework/cheapy/model/TimeOffer.java index 33da076ab..d9833e0c8 100644 --- a/src/main/java/org/springframework/cheapy/model/TimeOffer.java +++ b/src/main/java/org/springframework/cheapy/model/TimeOffer.java @@ -1,18 +1,3 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.springframework.cheapy.model; import java.time.LocalTime; @@ -27,7 +12,13 @@ import org.springframework.format.annotation.DateTimeFormat; @Entity @Table(name = "time_offers") public class TimeOffer extends Offer { -//Oferta por franja horaria + + /** + * + */ + private static final long serialVersionUID = 1L; + + //Oferta por franja horaria @DateTimeFormat(pattern = "HH:mm") @NotNull private LocalTime init; @@ -39,8 +30,6 @@ public class TimeOffer extends Offer { @NotBlank private String discount; - - public LocalTime getInit() { return init; } diff --git a/src/main/java/org/springframework/cheapy/model/User.java b/src/main/java/org/springframework/cheapy/model/User.java index 7cfc346d1..bd5b2dd30 100644 --- a/src/main/java/org/springframework/cheapy/model/User.java +++ b/src/main/java/org/springframework/cheapy/model/User.java @@ -1,8 +1,9 @@ package org.springframework.cheapy.model; -import javax.persistence.JoinColumn; -import javax.persistence.MappedSuperclass; -import javax.persistence.OneToOne; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.validation.constraints.NotBlank; @Entity @Table(name = "users") diff --git a/src/main/java/org/springframework/cheapy/model/Usuario.java b/src/main/java/org/springframework/cheapy/model/Usuario.java index f6204abeb..9079bc72e 100644 --- a/src/main/java/org/springframework/cheapy/model/Usuario.java +++ b/src/main/java/org/springframework/cheapy/model/Usuario.java @@ -1,12 +1,8 @@ package org.springframework.cheapy.model; -import java.util.Set; - import javax.persistence.CascadeType; import javax.persistence.Entity; -import javax.persistence.Id; import javax.persistence.JoinColumn; -import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.validation.constraints.Email; diff --git a/src/main/java/org/springframework/cheapy/model/package-info.java b/src/main/java/org/springframework/cheapy/model/package-info.java index 620e13c68..1bc54373f 100644 --- a/src/main/java/org/springframework/cheapy/model/package-info.java +++ b/src/main/java/org/springframework/cheapy/model/package-info.java @@ -1,20 +1 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * The classes in this package represent utilities used by the domain. - */ package org.springframework.cheapy.model; diff --git a/src/main/java/org/springframework/cheapy/repository/AuthoritiesRepository.java b/src/main/java/org/springframework/cheapy/repository/AuthoritiesRepository.java index a8adee7f7..8d5f6317c 100644 --- a/src/main/java/org/springframework/cheapy/repository/AuthoritiesRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/AuthoritiesRepository.java @@ -2,8 +2,6 @@ package org.springframework.cheapy.repository; import org.springframework.data.repository.CrudRepository; import org.springframework.cheapy.model.Authorities; -import org.springframework.cheapy.model.User; - public interface AuthoritiesRepository extends CrudRepository{ diff --git a/src/main/java/org/springframework/cheapy/repository/ClientRepository.java b/src/main/java/org/springframework/cheapy/repository/ClientRepository.java index 4c12840c2..764b35184 100644 --- a/src/main/java/org/springframework/cheapy/repository/ClientRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/ClientRepository.java @@ -1,13 +1,14 @@ - package org.springframework.cheapy.repository; - import org.springframework.cheapy.model.Client; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; +import org.springframework.transaction.annotation.Transactional; public interface ClientRepository extends CrudRepository { - + @Query("SELECT client FROM Client client WHERE username =:username") + @Transactional(readOnly = true) Client findByUsername(String username); } diff --git a/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java index 752bb718d..80fadc686 100644 --- a/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java @@ -1,18 +1,15 @@ package org.springframework.cheapy.repository; - import org.springframework.cheapy.model.FoodOffer; -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; - public interface FoodOfferRepository extends Repository { -@Query("SELECT foodOffer FROM FoodOffer foodOffer") + @Query("SELECT foodOffer FROM FoodOffer foodOffer") @Transactional(readOnly = true) List findAllFoodOffer(); diff --git a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java index 39fff01bb..42d437fdb 100644 --- a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java @@ -1,28 +1,19 @@ - package org.springframework.cheapy.repository; -import java.util.Collection; import java.util.List; import org.springframework.cheapy.model.NuOffer; import org.springframework.data.repository.Repository; import org.springframework.data.jpa.repository.Query; import org.springframework.transaction.annotation.Transactional; - public interface NuOfferRepository extends Repository { - - - - NuOffer findNuOfferById(int nuOfferId); - @Query("SELECT nuOffer FROM NuOffer nuOffer") + @Query("SELECT nuOffer FROM NuOffer nuOffer") @Transactional(readOnly = true) List findAllNuOffer(); - - void save(NuOffer nuOffer); } diff --git a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java index c3840912b..aef04d36d 100644 --- a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java @@ -1,8 +1,5 @@ - package org.springframework.cheapy.repository; - -import java.util.Collection; import java.util.List; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.data.jpa.repository.Query; @@ -10,19 +7,16 @@ import org.springframework.data.repository.Repository; import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; - public interface SpeedOfferRepository extends Repository { - @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE id =:id") @Transactional(readOnly = true) SpeedOffer findById(@Param("id") Integer id); - @Query("SELECT speedOffer FROM SpeedOffer speedOffer") + @Query("SELECT speedOffer FROM SpeedOffer speedOffer") @Transactional(readOnly = true) List findAllSpeedOffer(); - void save(SpeedOffer speedOffer); } diff --git a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java index 71717624d..b663057a7 100644 --- a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java @@ -1,28 +1,19 @@ - package org.springframework.cheapy.repository; -import java.util.Collection; import java.util.List; import org.springframework.cheapy.model.TimeOffer; import org.springframework.data.repository.Repository; import org.springframework.data.jpa.repository.Query; import org.springframework.transaction.annotation.Transactional; - public interface TimeOfferRepository extends Repository { - - - - TimeOffer findTimeOfferById(int timeOfferId); - @Query("SELECT timeOffer FROM TimeOffer timeOffer") + @Query("SELECT timeOffer FROM TimeOffer timeOffer") @Transactional(readOnly = true) List findAllTimeOffer(); - - void save(TimeOffer timeOffer); } diff --git a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java index d16d99bf6..1bd7c8ee2 100644 --- a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java @@ -2,7 +2,6 @@ package org.springframework.cheapy.repository; import org.springframework.data.repository.CrudRepository; -import org.springframework.cheapy.model.User; import org.springframework.cheapy.model.Usuario; public interface UsuarioRepository extends CrudRepository { diff --git a/src/main/java/org/springframework/cheapy/service/ClientService.java b/src/main/java/org/springframework/cheapy/service/ClientService.java index 9b197c438..d65649680 100644 --- a/src/main/java/org/springframework/cheapy/service/ClientService.java +++ b/src/main/java/org/springframework/cheapy/service/ClientService.java @@ -1,21 +1,5 @@ -/* - * Copyright 2002-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.springframework.cheapy.service; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.Client; import org.springframework.cheapy.repository.ClientRepository; @@ -25,8 +9,6 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - - @Service public class ClientService { @@ -37,13 +19,11 @@ public class ClientService { this.clientRepository = clientRepository; } - @Transactional public Client getCurrentClient() throws DataAccessException { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - String username = authentication.getName(); + String username = authentication.getName(); return this.clientRepository.findByUsername(username); - } } diff --git a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java index edd61b7f5..d23ffc321 100644 --- a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java @@ -3,16 +3,15 @@ package org.springframework.cheapy.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.repository.FoodOfferRepository; -import java.util.Collection; import java.util.List; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @Service public class FoodOfferService { + private FoodOfferRepository foodOfferRepository; - @Autowired public FoodOfferService(final FoodOfferRepository foodOfferRepository) { this.foodOfferRepository = foodOfferRepository; @@ -23,12 +22,9 @@ public class FoodOfferService { } public List findAllFoodOffer() { // return this.foodOfferRepository.findAllFoodOffer(); - } - public void saveFoodOffer(final FoodOffer foodOffer) throws DataAccessException { - this.foodOfferRepository.save(foodOffer); } diff --git a/src/main/java/org/springframework/cheapy/service/TimeOfferService.java b/src/main/java/org/springframework/cheapy/service/TimeOfferService.java index f544b0515..b7d5904ef 100644 --- a/src/main/java/org/springframework/cheapy/service/TimeOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/TimeOfferService.java @@ -1,5 +1,7 @@ package org.springframework.cheapy.service; +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.repository.TimeOfferRepository; @@ -21,12 +23,12 @@ public class TimeOfferService { return this.timeOfferRepository.findTimeOfferById(id); } - public List findAllTimeOffer() { // + public List findAllTimeOffer() { return this.timeOfferRepository.findAllTimeOffer(); } - public void saveTimeOffer(final TimeOffer TimeOffer) throws DataAccessException { // + public void saveTimeOffer(final TimeOffer TimeOffer) throws DataAccessException { this.timeOfferRepository.save(TimeOffer); diff --git a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java index d9f53a5e6..af191c66d 100644 --- a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java @@ -49,7 +49,7 @@ public class FoodOfferController { return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; } else { - Client client = this.clientService.getCurrentclient(); + Client client = this.clientService.getCurrentClient(); foodOffer.setClient(client); foodOffer.setType(StatusOffer.hidden); this.foodOfferService.saveFoodOffer(foodOffer); @@ -60,7 +60,7 @@ public class FoodOfferController { @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(); + Client client = this.clientService.getCurrentClient(); if(foodOffer.getClient().equals(client)) { foodOffer.setType(StatusOffer.active); foodOffer.setCode("FO-"+foodOfferId); diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index dcd92f583..ffb11b46f 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -1,21 +1,5 @@ -/* - * 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; @@ -28,38 +12,24 @@ 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( Map model) { diff --git a/src/main/java/org/springframework/cheapy/web/OwnerController.java b/src/main/java/org/springframework/cheapy/web/OwnerController.java index d95e5d120..229693415 100644 --- a/src/main/java/org/springframework/cheapy/web/OwnerController.java +++ b/src/main/java/org/springframework/cheapy/web/OwnerController.java @@ -1,18 +1,3 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.springframework.cheapy.web; import java.util.Collection; @@ -21,7 +6,6 @@ import java.util.Map; import javax.validation.Valid; import org.springframework.cheapy.model.Owner; -import org.springframework.cheapy.repository.OwnerRepository; import org.springframework.cheapy.service.OwnerService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -33,12 +17,6 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.servlet.ModelAndView; -/** - * @author Juergen Hoeller - * @author Ken Krebs - * @author Arjen Poutsma - * @author Michael Isvy - */ @Controller public class OwnerController { @@ -137,5 +115,4 @@ public class OwnerController { return mav; } - } diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java index 419dc2ad4..f9678e4bc 100644 --- a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -45,7 +45,6 @@ public class SpeedOfferController { public SpeedOfferController(final SpeedOfferService speedOfferService, final ClientService clientService) { this.speedOfferService = speedOfferService; this.clientService = clientService; - } @InitBinder @@ -66,7 +65,7 @@ public class SpeedOfferController { return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; } else { - Client client = this.clientService.getCurrentclient(); + Client client = this.clientService.getCurrentClient(); speedOffer.setClient(client); speedOffer.setType(StatusOffer.hidden); this.speedOfferService.saveSpeedOffer(speedOffer); @@ -77,7 +76,7 @@ public class SpeedOfferController { @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(); + Client client = this.clientService.getCurrentClient(); if(speedOffer.getClient().equals(client)) { speedOffer.setType(StatusOffer.active); speedOffer.setCode("SP-"+speedOfferId); @@ -92,11 +91,7 @@ public class SpeedOfferController { public String processShowForm(@PathVariable("speedOfferId") int speedOfferId, Map model) { SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId); - model.put("speedOffer", speedOffer); - return "speedOffers/speedOffersShow"; - } - } diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index 4678e73bb..30ae2672e 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -9,15 +9,6 @@ INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', ' INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435'); INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487'); - - -INSERT INTO food_offers(start, end, code, type, client_id, food, discount, units) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'FO-1', 'active', null, 'macarrones', '15%', 10); -INSERT INTO speed_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'SP-1', 'active', null, 5, '15%', 10, '10%', 15, '5%'); -INSERT INTO time_offers(start, end, code, type, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, '12:00:00', '13:00:00', '10%'); -INSERT INTO speed_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null,5,'25%',10,'15%',15,'10%' ); -INSERT INTO nu_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null,15,'25%',10,'15%',5,'10%' ); - - INSERT INTO users (dtype,username,password,enabled) VALUES ('user','admin','admin', TRUE ); INSERT INTO authorities VALUES ('admin','admin'); INSERT INTO users (dtype,username,password,enabled) VALUES ('user','manoli','manoli', TRUE ); @@ -32,10 +23,15 @@ INSERT INTO users (dtype,username,password,enabled) VALUES ('user','pepe','pepe' INSERT INTO authorities VALUES ('pepe','usuario'); INSERT INTO usuarios VALUES (1, 'admin', 'admin', 'admin', 'C/admin', '000000000', 'admin@gmail.com','admin'); +INSERT INTO usuarios VALUES (2, 'Paco', 'Naranjo', '21154416G', 'C/Esperanza', '666973647', 'Paco@gmail.com','paco'); +INSERT INTO usuarios VALUES (3, 'Lolo', 'Lopez', '25486596L', 'C/Macarena', '690670547' ,'Lolo@gmail.com','lolo'); +INSERT INTO usuarios VALUES (4, 'Pepe', 'Lopez', '12456776V', 'C/Macarena', '690670547', 'Pepe@gmail.com','pepe'); INSERT INTO clients VALUES (1,'manoli@gmail.com','C/Betis','10:00','22:00','608726190', 'description 1', 'code1', 'ESPAÑOLA','manoli'); INSERT INTO clients VALUES (2,'david@gmail.com','C/Sevilla','09:30','22:00','608726190', 'description 2', 'code2', 'americana','david'); -INSERT INTO usuarios VALUES (2, 'Paco', 'Naranjo', '21154416G', 'C/Esperanza', '666973647', 'Paco@gmail.com','paco'); -INSERT INTO usuarios VALUES (3, 'Lolo', 'Lopez', '25486596L', 'C/Macarena', '690670547' ,'Lolo@gmail.com','lolo'); -INSERT INTO usuarios VALUES (4, 'Pepe', 'Lopez', '12456776V', 'C/Macarena', '690670547', 'Pepe@gmail.com','pepe'); +INSERT INTO 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%' ); diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp index 54efc214d..d65c50967 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -5,7 +5,7 @@ <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +

Ofertas por plato específico

diff --git a/src/main/webapp/WEB-INF/jsp/welcome.jsp b/src/main/webapp/WEB-INF/jsp/welcome.jsp index fc2db8671..5d48bc8d5 100644 --- a/src/main/webapp/WEB-INF/jsp/welcome.jsp +++ b/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -6,7 +6,7 @@ -

+

@@ -14,8 +14,8 @@
- - +
diff --git a/src/test/java/org/springframework/cheapy/web/OwnerControllerTests.java b/src/test/java/org/springframework/cheapy/web/OwnerControllerTests.java index dc0782a4d..c684187ca 100644 --- a/src/test/java/org/springframework/cheapy/web/OwnerControllerTests.java +++ b/src/test/java/org/springframework/cheapy/web/OwnerControllerTests.java @@ -160,6 +160,3 @@ class OwnerControllerTests { .andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023")))) .andExpect(view().name("owners/ownerDetails")); }*/ - -} -*/ \ No newline at end of file