diff --git a/readme.md b/readme.md index ff6d2be15..e69de29bb 100644 --- a/readme.md +++ b/readme.md @@ -1,133 +0,0 @@ -# Spring PetClinic Sample Application [](https://travis-ci.org/spring-projects/spring-petclinic/) - -## Understanding the Spring Petclinic application with a few diagrams -See the presentation here - -## Running petclinic locally -Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/). You can build a jar file and run it from the command line: - - -``` -git clone https://github.com/spring-projects/spring-petclinic.git -cd spring-petclinic -./mvnw package -java -jar target/*.jar -``` - -You can then access petclinic here: http://localhost:8080/ - - - -Or you can run it from Maven directly using the Spring Boot Maven plugin. If you do this it will pick up changes that you make in the project immediately (changes to Java source files require a compile as well - most people use an IDE for this): - -``` -./mvnw spring-boot:run -``` - -## In case you find a bug/suggested improvement for Spring Petclinic -Our issue tracker is available here: https://github.com/spring-projects/spring-petclinic/issues - - -## Database configuration - -In its default configuration, Petclinic uses an in-memory database (H2) which -gets populated at startup with data. The h2 console is automatically exposed at `http://localhost:8080/h2-console` -and it is possible to inspect the content of the database using the `jdbc:h2:mem:testdb` url. - -A similar setup is provided for MySql in case a persistent database configuration is needed. Note that whenever the database type is changed, the app needs to be run with a different profile: `spring.profiles.active=mysql` for MySql. - -You could start MySql locally with whatever installer works for your OS, or with docker: - -``` -docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8 -``` - -Further documentation is provided [here](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt). - -## Working with Petclinic in your IDE - -### Prerequisites -The following items should be installed in your system: -* Java 8 or newer. -* git command line tool (https://help.github.com/articles/set-up-git) -* Your preferred IDE - * Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in `Help -> About` dialog. If m2e is - not there, just follow the install process here: https://www.eclipse.org/m2e/ - * [Spring Tools Suite](https://spring.io/tools) (STS) - * IntelliJ IDEA - * [VS Code](https://code.visualstudio.com) - -### Steps: - -1) On the command line - ``` - git clone https://github.com/spring-projects/spring-petclinic.git - ``` -2) Inside Eclipse or STS - ``` - File -> Import -> Maven -> Existing Maven project - ``` - - Then either build on the command line `./mvnw generate-resources` or using the Eclipse launcher (right click on project and `Run As -> Maven install`) to generate the css. Run the application main method by right clicking on it and choosing `Run As -> Java Application`. - -3) Inside IntelliJ IDEA - In the main menu, choose `File -> Open` and select the Petclinic [pom.xml](pom.xml). Click on the `Open` button. - - CSS files are generated from the Maven build. You can either build them on the command line `./mvnw generate-resources` or right click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`. - - A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application by right clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`. - -4) Navigate to Petclinic - - Visit [http://localhost:8080](http://localhost:8080) in your browser. - - -## Looking for something in particular? - -|Spring Boot Configuration | Class or Java property files | -|--------------------------|---| -|The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) | -|Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources) | -|Caching | [CacheConfiguration](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) | - -## Interesting Spring Petclinic branches and forks - -The Spring Petclinic "main" branch in the [spring-projects](https://github.com/spring-projects/spring-petclinic) -GitHub org is the "canonical" implementation, currently based on Spring Boot and Thymeleaf. There are -[quite a few forks](https://spring-petclinic.github.io/docs/forks.html) in a special GitHub org -[spring-petclinic](https://github.com/spring-petclinic). If you have a special interest in a different technology stack -that could be used to implement the Pet Clinic then please join the community there. - - -## Interaction with other open source projects - -One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found some bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days. -Here is a list of them: - -| Name | Issue | -|------|-------| -| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://jira.springsource.org/browse/SPR-10256) and [SPR-10257](https://jira.springsource.org/browse/SPR-10257) | -| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility |[HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) | -| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://jira.springsource.org/browse/DATAJPA-292) | - - -# Contributing - -The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, features requests and submitting pull requests. - -For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at . If you have not previously done so, please fill out and submit the [Contributor License Agreement](https://cla.pivotal.io/sign/spring). - -# License - -The Spring PetClinic sample application is released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0). - -[spring-petclinic]: https://github.com/spring-projects/spring-petclinic -[spring-framework-petclinic]: https://github.com/spring-petclinic/spring-framework-petclinic -[spring-petclinic-angularjs]: https://github.com/spring-petclinic/spring-petclinic-angularjs -[javaconfig branch]: https://github.com/spring-petclinic/spring-framework-petclinic/tree/javaconfig -[spring-petclinic-angular]: https://github.com/spring-petclinic/spring-petclinic-angular -[spring-petclinic-microservices]: https://github.com/spring-petclinic/spring-petclinic-microservices -[spring-petclinic-reactjs]: https://github.com/spring-petclinic/spring-petclinic-reactjs -[spring-petclinic-graphql]: https://github.com/spring-petclinic/spring-petclinic-graphql -[spring-petclinic-kotlin]: https://github.com/spring-petclinic/spring-petclinic-kotlin -[spring-petclinic-rest]: https://github.com/spring-petclinic/spring-petclinic-rest diff --git a/src/main/java/org/springframework/cheapy/model/FoodOffer.java b/src/main/java/org/springframework/cheapy/model/FoodOffer.java index 3cb6a1e56..ad45ad09f 100644 --- a/src/main/java/org/springframework/cheapy/model/FoodOffer.java +++ b/src/main/java/org/springframework/cheapy/model/FoodOffer.java @@ -17,10 +17,11 @@ package org.springframework.cheapy.model; import javax.persistence.Entity; import javax.persistence.Table; -import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import org.hibernate.validator.constraints.Range; + @Entity @Table(name = "food_offers") public class FoodOffer extends Offer { @@ -28,11 +29,11 @@ public class FoodOffer extends Offer { private static final long serialVersionUID = 1L; //Plato especÃfico - @NotBlank + @NotBlank(message = "Debe rellenar la comida a ofertar") private String food; - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento que proporciona") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discount; public String getFood() { diff --git a/src/main/java/org/springframework/cheapy/model/NuOffer.java b/src/main/java/org/springframework/cheapy/model/NuOffer.java index 6f250737d..d4cf72456 100644 --- a/src/main/java/org/springframework/cheapy/model/NuOffer.java +++ b/src/main/java/org/springframework/cheapy/model/NuOffer.java @@ -6,6 +6,8 @@ import javax.persistence.Table; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; +import org.hibernate.validator.constraints.Range; + @Entity @Table(name = "nu_offers") public class NuOffer extends Offer { @@ -13,31 +15,31 @@ public class NuOffer extends Offer { //Oferta por numero de comensales private static final long serialVersionUID = 1L; - @NotNull + @NotNull(message = "Debe rellenar el tiempo del rango oro") @Min(1) private Integer gold; @Column(name = "discount_gold") - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento del rango oro") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discountGold; - @NotNull + @NotNull(message = "Debe rellenar el tiempo del rango plata") @Min(1) private Integer silver; @Column(name = "discount_silver") - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento del rango plata") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discountSilver; - @NotNull + @NotNull(message = "Debe rellenar el tiempo del rango bronce") @Min(1) private Integer bronze; @Column(name = "discount_bronze") - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento del rango bronce") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discountBronze; public Integer getGold() { diff --git a/src/main/java/org/springframework/cheapy/model/Offer.java b/src/main/java/org/springframework/cheapy/model/Offer.java index 5ae64feba..fd72e2989 100644 --- a/src/main/java/org/springframework/cheapy/model/Offer.java +++ b/src/main/java/org/springframework/cheapy/model/Offer.java @@ -35,13 +35,13 @@ public class Offer extends BaseEntity { // Clase padre @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") - @NotNull - @Future + @NotNull(message = "Debe introducir una fecha de inicio") + @Future(message = "La fecha debe debe ser futura") private LocalDateTime start; @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") - @NotNull - @Future + @NotNull(message = "Debe introducir una fecha de fin") + @Future(message = "La fecha debe debe ser futura") private LocalDateTime end; private String code; diff --git a/src/main/java/org/springframework/cheapy/model/SpeedOffer.java b/src/main/java/org/springframework/cheapy/model/SpeedOffer.java index 84b551829..e9aa4d0e4 100644 --- a/src/main/java/org/springframework/cheapy/model/SpeedOffer.java +++ b/src/main/java/org/springframework/cheapy/model/SpeedOffer.java @@ -6,6 +6,8 @@ import javax.persistence.Table; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; +import org.hibernate.validator.constraints.Range; + @Entity @Table(name = "speed_offers") public class SpeedOffer extends Offer { @@ -13,31 +15,31 @@ public class SpeedOffer extends Offer { // Ofertar por rapidez comiendo private static final long serialVersionUID = 1L; - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el tiempo del rango oro") + @Min(1) private Integer gold; @Column(name = "discount_gold") - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento del rango oro") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discountGold; - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el tiempo del rango plata") + @Min(1) private Integer silver; @Column(name = "discount_silver") - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento del rango plata") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discountSilver; - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el tiempo del rango bronce") + @Min(1) private Integer bronze; @Column(name = "discount_bronze") - @NotNull - @Min(0) + @NotNull(message = "Debe rellenar el descuento del rango bronce") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discountBronze; public Integer getGold() { diff --git a/src/main/java/org/springframework/cheapy/model/TimeOffer.java b/src/main/java/org/springframework/cheapy/model/TimeOffer.java index 44ae5e3d6..5fcfb28a1 100644 --- a/src/main/java/org/springframework/cheapy/model/TimeOffer.java +++ b/src/main/java/org/springframework/cheapy/model/TimeOffer.java @@ -6,6 +6,7 @@ import javax.persistence.Entity; import javax.persistence.Table; import javax.validation.constraints.NotNull; +import org.hibernate.validator.constraints.Range; import org.springframework.format.annotation.DateTimeFormat; @Entity @@ -17,14 +18,15 @@ public class TimeOffer extends Offer { // Oferta por franja horaria @DateTimeFormat(pattern = "HH:mm") - @NotNull + @NotNull(message = "Debe introducir una hora de inicio") private LocalTime init; @DateTimeFormat(pattern = "HH:mm") - @NotNull + @NotNull(message = "Debe introducir una hora de fin") private LocalTime finish; - @NotNull + @NotNull(message = "Debe rellenar el descuento") + @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %") private Integer discount; public LocalTime getInit() { diff --git a/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java b/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java index 5307beeb1..7d0f8d7a8 100644 --- a/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java +++ b/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java @@ -26,12 +26,6 @@ import org.springframework.cheapy.repository.AuthoritiesRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -/** - * Mostly used as a facade for all Petclinic controllers Also a placeholder - * for @Transactional and @Cacheable annotations - * - * @author Michael Isvy - */ @Service public class AuthoritiesService { /* diff --git a/src/main/java/org/springframework/cheapy/service/NuOfferService.java b/src/main/java/org/springframework/cheapy/service/NuOfferService.java index b87093c3d..5268ac2db 100644 --- a/src/main/java/org/springframework/cheapy/service/NuOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/NuOfferService.java @@ -35,6 +35,11 @@ public class NuOfferService { this.nuOfferRepository.save(nuOffer); } + @Transactional + public void saveUpdateNuOffer(final NuOffer nuOfferNew, final NuOffer nuOfferOld) throws DataAccessException { + this.nuOfferRepository.save(nuOfferNew); + } + public List findActiveNuOffer() { return this.nuOfferRepository.findActiveNuOffer(StatusOffer.active); } diff --git a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java index 056c45331..3cd695532 100644 --- a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java @@ -4,8 +4,10 @@ package org.springframework.cheapy.web; import java.time.format.DateTimeFormatter; import java.util.Map; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.StatusOffer; @@ -31,6 +33,33 @@ public class FoodOfferController { this.clientService = clientService; } + private boolean checkIdentity(final int foodOfferId) { + boolean res = false; + Client client = this.clientService.getCurrentClient(); + FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); + Client clientOffer = foodOffer.getClient(); + if (client.equals(clientOffer)) { + res = true; + } + return res; + } + + private boolean checkOffer(final FoodOffer session, final FoodOffer offer) { + boolean res = false; + if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() + && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) { + res = true; + } + return res; + } + + private boolean checkDates(final FoodOffer foodOffer) { + boolean res = false; + if(foodOffer.getEnd().isAfter(foodOffer.getStart())) { + res = true; + } + return res; + } @GetMapping("/offers/food/new") public String initCreationForm(Map model) { @@ -44,6 +73,10 @@ public class FoodOfferController { if (result.hasErrors()) { return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(foodOffer)) { + //Poner aqui mensaje de error + return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; + } Client client = this.clientService.getCurrentClient(); foodOffer.setClient(client); foodOffer.setStatus(StatusOffer.hidden); @@ -51,7 +84,7 @@ public class FoodOfferController { return "redirect:/offers/food/" + foodOffer.getId(); } } - + @GetMapping(value = "/offers/food/{foodOfferId}/activate") public String activateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, ModelMap modelMap) { FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); @@ -63,7 +96,7 @@ public class FoodOfferController { } else { modelMap.addAttribute("message", "You don't have access to this food offer"); } - return "redirect:/offers/food/"+foodOfferId; + return "redirect:/offers/food/" + foodOfferId; } @@ -73,31 +106,53 @@ public class FoodOfferController { FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); model.put("foodOffer", foodOffer); - + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); - - + return "offers/food/foodOffersShow"; } @GetMapping(value = "/offers/food/{foodOfferId}/edit") - public String updateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) { - + public String updateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model, + HttpServletRequest request) { + + if (!this.checkIdentity(foodOfferId)) { + return "error"; + } FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); + if (foodOffer.getStatus().equals(StatusOffer.inactive)) { + return "error"; + } model.addAttribute("foodOffer", foodOffer); + request.getSession().setAttribute("idFood", foodOfferId); return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping(value = "/offers/food/{foodOfferId}/edit") public String updateFoodOffer(@Valid final FoodOffer foodOfferEdit, final BindingResult result, - final ModelMap model) { + final ModelMap model, HttpServletRequest request) { + + if (!this.checkIdentity(foodOfferEdit.getId())) { + return "error"; + } + Integer id = (Integer) request.getSession().getAttribute("idFood"); + FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(id); + if (!this.checkOffer(foodOffer, foodOfferEdit)) { + return "error"; + } if (result.hasErrors()) { model.addAttribute("foodOffer", foodOfferEdit); return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(foodOfferEdit)) { + //Poner aqui mensaje de error + return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; + } + BeanUtils.copyProperties(this.foodOfferService.findFoodOfferById(foodOfferEdit.getId()), foodOfferEdit, + "start", "end", "food", "discount"); this.foodOfferService.saveFoodOffer(foodOfferEdit); return "redirect:/offers/food/" + foodOfferEdit.getId(); } @@ -106,6 +161,9 @@ public class FoodOfferController { @GetMapping(value = "/offers/food/{foodOfferId}/disable") public String disableFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) { + if (!this.checkIdentity(foodOfferId)) { + return "error"; + } FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); model.put("foodOffer", foodOffer); @@ -115,6 +173,9 @@ public class FoodOfferController { @PostMapping(value = "/offers/food/{foodOfferId}/disable") public String disableFoodOfferForm(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) { + if (!this.checkIdentity(foodOfferId)) { + return "error"; + } FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); @@ -122,7 +183,7 @@ public class FoodOfferController { this.foodOfferService.saveFoodOffer(foodOffer); - return "redirect:/offers"; + return "redirect:/myOffers"; } } diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index 371f9c744..7c8826521 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -4,15 +4,18 @@ import java.security.Principal; import java.time.format.DateTimeFormatter; import java.util.Map; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import org.springframework.cheapy.model.NuOffer; +import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; +import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.Client; +import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.NuOfferService; import org.springframework.stereotype.Controller; - import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; @@ -31,6 +34,50 @@ public class NuOfferController { this.nuOfferService = nuOfferService; this.clientService = clientService; } + + private boolean checkIdentity(final int nuOfferId) { + boolean res = false; + Client client = this.clientService.getCurrentClient(); + NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); + Client clientOffer = nuOffer.getClient(); + if (client.equals(clientOffer)) { + res = true; + } + return res; + } + + private boolean checkOffer(final NuOffer session, final NuOffer offer) { + boolean res = false; + if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() + && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) { + res = true; + } + return res; + } + + private boolean checkDates(final NuOffer nuOffer) { + boolean res = false; + if(nuOffer.getEnd().isAfter(nuOffer.getStart())) { + res = true; + } + return res; + } + + private boolean checkConditions(final NuOffer NuOffer) { + boolean res = false; + if(NuOffer.getGold() > NuOffer.getSilver() && NuOffer.getSilver() > NuOffer.getBronze()) { + res = true; + } + return res; + } + + private boolean checkDiscounts(final NuOffer NuOffer) { + boolean res = false; + if(NuOffer.getDiscountGold() > NuOffer.getDiscountSilver() && NuOffer.getDiscountSilver() > NuOffer.getDiscountBronze()) { + res = true; + } + return res; + } @GetMapping("/offers/nu/new") public String initCreationForm(Map model) { @@ -44,6 +91,18 @@ public class NuOfferController { if (result.hasErrors()) { return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(nuOffer)) { + //Poner aqui mensaje de error + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkConditions(nuOffer)) { + //Poner aqui mensaje de error + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkDiscounts(nuOffer)) { + //Poner aqui mensaje de error + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } nuOffer.setStatus(StatusOffer.hidden); Client client = this.clientService.getCurrentClient(); @@ -51,11 +110,11 @@ public class NuOfferController { nuOffer.setClient(client); this.nuOfferService.saveNuOffer(nuOffer); - return "redirect:/offers/nu/"+nuOffer.getId(); + return "redirect:/offers/nu/" + nuOffer.getId(); } } - @GetMapping(value ="/offers/nu/{nuOfferId}/activate") + @GetMapping(value = "/offers/nu/{nuOfferId}/activate") public String activateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap modelMap) { Client client = this.clientService.getCurrentClient(); NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); @@ -63,11 +122,11 @@ public class NuOfferController { nuOffer.setStatus(StatusOffer.active); nuOffer.setCode("NU-" + nuOfferId); this.nuOfferService.saveNuOffer(nuOffer); - + } else { modelMap.addAttribute("message", "You don't have access to this number offer"); } - return "redirect:/offers/nu/"+ nuOffer.getId(); + return "redirect:/offers/nu/" + nuOffer.getId(); } @@ -82,22 +141,53 @@ public class NuOfferController { } @GetMapping(value = "/offers/nu/{nuOfferId}/edit") - public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap model) { - + public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap model, + HttpServletRequest request) { + if (!this.checkIdentity(nuOfferId)) { + return "error"; + } NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); + if (nuOffer.getStatus().equals(StatusOffer.inactive)) { + return "error"; + } model.addAttribute("nuOffer", nuOffer); + request.getSession().setAttribute("idNu", nuOfferId); return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping(value = "/offers/nu/{nuOfferId}/edit") - public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final ModelMap model) { + public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final ModelMap model, + HttpServletRequest request) { + + if (!this.checkIdentity(nuOfferEdit.getId())) { + return "error"; + } + Integer id = (Integer) request.getSession().getAttribute("idNu"); + NuOffer nuOffer = this.nuOfferService.findNuOfferById(id); + if (!this.checkOffer(nuOffer, nuOfferEdit)) { + return "error"; + } if (result.hasErrors()) { model.addAttribute("nuOffer", nuOfferEdit); return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(nuOffer)) { + //Poner aqui mensaje de error + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkConditions(nuOffer)) { + //Poner aqui mensaje de error + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkDiscounts(nuOffer)) { + //Poner aqui mensaje de error + return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + BeanUtils.copyProperties(this.nuOfferService.findNuOfferById(nuOfferEdit.getId()), nuOfferEdit, "start", + "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze"); this.nuOfferService.saveNuOffer(nuOfferEdit); return "redirect:/offers/nu/" + nuOfferEdit.getId(); } @@ -107,6 +197,9 @@ public class NuOfferController { public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { + if (!this.checkIdentity(nuOfferId)) { + return "error"; + } NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); model.put("nuOffer", nuOffer); @@ -117,11 +210,14 @@ public class NuOfferController { public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { + if (!this.checkIdentity(nuOfferId)) { + return "error"; + } NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); nuOffer.setStatus(StatusOffer.inactive); this.nuOfferService.saveNuOffer(nuOffer); - return "redirect:/offers"; + return "redirect:/myOffers"; } diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java index 9451e570b..5b7e5aada 100644 --- a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -3,11 +3,14 @@ package org.springframework.cheapy.web; import java.time.format.DateTimeFormatter; import java.util.Map; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; +import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.Client; +import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.SpeedOfferService; import org.springframework.stereotype.Controller; @@ -30,6 +33,49 @@ public class SpeedOfferController { this.clientService = clientService; } + private boolean checkIdentity(final int speedOfferId) { + boolean res = false; + Client client = this.clientService.getCurrentClient(); + SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); + Client clientOffer = speedOffer.getClient(); + if (client.equals(clientOffer)) { + res = true; + } + return res; + } + + private boolean checkOffer(final SpeedOffer session, final SpeedOffer offer) { + boolean res = false; + if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() + && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) { + res = true; + } + return res; + } + + private boolean checkDates(final SpeedOffer speedOffer) { + boolean res = false; + if(speedOffer.getEnd().isAfter(speedOffer.getStart())) { + res = true; + } + return res; + } + + private boolean checkConditions(final SpeedOffer speedOffer) { + boolean res = false; + if(speedOffer.getGold() < speedOffer.getSilver() && speedOffer.getSilver() < speedOffer.getBronze()) { + res = true; + } + return res; + } + + private boolean checkDiscounts(final SpeedOffer speedOffer) { + boolean res = false; + if(speedOffer.getDiscountGold() > speedOffer.getDiscountSilver() && speedOffer.getDiscountSilver() > speedOffer.getDiscountBronze()) { + res = true; + } + return res; + } @GetMapping("/offers/speed/new") public String initCreationForm(Map model) { @@ -43,6 +89,18 @@ public class SpeedOfferController { if (result.hasErrors()) { return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(speedOffer)) { + //Poner aqui mensaje de error + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkConditions(speedOffer)) { + //Poner aqui mensaje de error + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkDiscounts(speedOffer)) { + //Poner aqui mensaje de error + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } Client client = this.clientService.getCurrentClient(); speedOffer.setClient(client); speedOffer.setStatus(StatusOffer.hidden); @@ -51,7 +109,6 @@ public class SpeedOfferController { } } - @GetMapping(value = "/offers/speed/{speedOfferId}/activate") public String activateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, ModelMap modelMap) { SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); @@ -77,21 +134,53 @@ public class SpeedOfferController { } @GetMapping(value = "/offers/speed/{speedOfferId}/edit") - public String updateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) { - + public String updateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model, HttpServletRequest request) { + + if (!this.checkIdentity(speedOfferId)) { + return "error"; + } SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); + if (speedOffer.getStatus().equals(StatusOffer.inactive)) { + return "error"; + } + model.addAttribute("speedOffer", speedOffer); + request.getSession().setAttribute("idSpeed", speedOfferId); return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping(value = "/offers/speed/{speedOfferId}/edit") - public String updateSpeedOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, final ModelMap model) { - + public String updateSpeedOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, + final ModelMap model, HttpServletRequest request) { + + if (!this.checkIdentity(speedOfferEdit.getId())) { + return "error"; + } + Integer id = (Integer) request.getSession().getAttribute("idSpeed"); + SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(id); + if (!this.checkOffer(speedOffer, speedOfferEdit)) { + return "error"; + } + if (result.hasErrors()) { model.addAttribute("speedOffer", speedOfferEdit); return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(speedOffer)) { + //Poner aqui mensaje de error + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkConditions(speedOffer)) { + //Poner aqui mensaje de error + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkDiscounts(speedOffer)) { + //Poner aqui mensaje de error + return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } + BeanUtils.copyProperties(this.speedOfferService.findSpeedOfferById(speedOfferEdit.getId()), speedOfferEdit, + "start", "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze"); this.speedOfferService.saveSpeedOffer(speedOfferEdit); return "redirect:/offers/speed/" + speedOfferEdit.getId(); } @@ -101,6 +190,9 @@ public class SpeedOfferController { @GetMapping(value = "/offers/speed/{speedOfferId}/disable") public String disableSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) { + if (!this.checkIdentity(speedOfferId)) { + return "error"; + } SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); model.put("speedOffer", speedOffer); @@ -109,7 +201,10 @@ public class SpeedOfferController { @PostMapping(value = "/offers/speed/{speedOfferId}/disable") public String disableSpeedOfferForm(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) { - + + if (!this.checkIdentity(speedOfferId)) { + return "error"; + } SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); @@ -117,7 +212,7 @@ public class SpeedOfferController { this.speedOfferService.saveSpeedOffer(speedOffer); - return "redirect:/offers"; + return "redirect:/myOffers"; } } diff --git a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java index b0aaded83..5b58bed76 100644 --- a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java @@ -1,12 +1,14 @@ package org.springframework.cheapy.web; - import java.time.format.DateTimeFormatter; import java.util.Map; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.Client; +import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.service.ClientService; @@ -21,7 +23,6 @@ import org.springframework.web.bind.annotation.PostMapping; @Controller public class TimeOfferController { - private static final String VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM = "offers/time/createOrUpdateTimeOfferForm"; private final TimeOfferService timeOfferService; private final ClientService clientService; @@ -31,6 +32,42 @@ public class TimeOfferController { this.clientService = clientService; } + private boolean checkIdentity(final int timeOfferId) { + boolean res = false; + Client client = this.clientService.getCurrentClient(); + TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); + Client clientOffer = timeOffer.getClient(); + if (client.equals(clientOffer)) { + res = true; + } + return res; + } + + private boolean checkOffer(final TimeOffer session, final TimeOffer offer) { + boolean res = false; + if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() + && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) { + res = true; + } + return res; + } + + private boolean checkDates(final TimeOffer timeOffer) { + boolean res = false; + if(timeOffer.getEnd().isAfter(timeOffer.getStart())) { + res = true; + } + return res; + } + + private boolean checkTimes(final TimeOffer timeOffer) { + boolean res = false; + if(timeOffer.getFinish().isAfter(timeOffer.getInit())) { + res = true; + } + return res; + } + @GetMapping("/offers/time/new") public String initCreationForm(Map model) { TimeOffer timeOffer = new TimeOffer(); @@ -43,6 +80,16 @@ public class TimeOfferController { if (result.hasErrors()) { return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(timeOffer)) { + //Poner aqui mensaje de error + return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + } + + if(!this.checkTimes(timeOffer)) { + //Poner aqui mensaje de error + return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + } + timeOffer.setStatus(StatusOffer.hidden); Client client = this.clientService.getCurrentClient(); @@ -54,7 +101,7 @@ public class TimeOfferController { } } - @GetMapping(value ="/offers/time/{timeOfferId}/activate") + @GetMapping(value = "/offers/time/{timeOfferId}/activate") public String activateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap modelMap) { Client client = this.clientService.getCurrentClient(); TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); @@ -63,13 +110,11 @@ public class TimeOfferController { timeOffer.setCode("TI-" + timeOfferId); this.timeOfferService.saveTimeOffer(timeOffer); - } else { modelMap.addAttribute("message", "You don't have access to this time offer"); } return "redirect:/offers/time/" + timeOffer.getId(); - } @GetMapping("/offers/time/{timeOfferId}") @@ -80,29 +125,56 @@ public class TimeOfferController { model.put("timeOffer", timeOffer); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); - + return "offers/time/timeOffersShow"; } @GetMapping(value = "/offers/time/{timeOfferId}/edit") - public String updateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) { - + public String updateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model, + HttpServletRequest request) { + if (!this.checkIdentity(timeOfferId)) { + return "error"; + } TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); + if (timeOffer.getStatus().equals(StatusOffer.inactive)) { + return "error"; + } + model.addAttribute("timeOffer", timeOffer); + request.getSession().setAttribute("idTime", timeOfferId); return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping(value = "/offers/time/{timeOfferId}/edit") - public String updateTimeOffer(@Valid final TimeOffer timeOfferEdit, final BindingResult result, final ModelMap model) { - + public String updateTimeOffer(@Valid final TimeOffer timeOfferEdit, final BindingResult result, + final ModelMap model, HttpServletRequest request) { + + if (!this.checkIdentity(timeOfferEdit.getId())) { + return "error"; + } + Integer id = (Integer) request.getSession().getAttribute("idTime"); + TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(id); + if (!this.checkOffer(timeOffer, timeOfferEdit)) { + return "error"; + } if (result.hasErrors()) { model.addAttribute("timeOffer", timeOfferEdit); return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; } else { + if(!this.checkDates(timeOffer)) { + //Poner aqui mensaje de error + return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + } + if(!this.checkTimes(timeOffer)) { + //Poner aqui mensaje de error + return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + } + BeanUtils.copyProperties(this.timeOfferService.findTimeOfferById(timeOfferEdit.getId()), timeOfferEdit, + "start", "end", "init", "finish", "discount"); this.timeOfferService.saveTimeOffer(timeOfferEdit); return "redirect:/offers/time/" + timeOfferEdit.getId(); } @@ -112,6 +184,9 @@ public class TimeOfferController { @GetMapping(value = "/offers/time/{timeOfferId}/disable") public String disableTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) { + if (!this.checkIdentity(timeOfferId)) { + return "error"; + } TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); model.put("timeOffer", timeOffer); @@ -120,7 +195,10 @@ public class TimeOfferController { @PostMapping(value = "/offers/time/{timeOfferId}/disable") public String disableTimeOfferForm(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) { - + + if (!this.checkIdentity(timeOfferId)) { + return "error"; + } TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); @@ -128,8 +206,7 @@ public class TimeOfferController { this.timeOfferService.saveTimeOffer(timeOffer); - return "redirect:/offers"; - + return "redirect:/myOffers"; } diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt index da0aacccf..b4c3b6769 100644 --- a/src/main/resources/banner.txt +++ b/src/main/resources/banner.txt @@ -1,3 +1,5 @@ + + __^__ __^__ ( ___ )------------------------------------( ___ ) | / | | \ | @@ -5,5 +7,4 @@ |___| |___| (_____)------------------------------------(_____) -:: Built with Spring Boot :: ${spring-boot.version} - +-- Built with Spring Boot -- (${spring-boot.version}) diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index 39f0ca7b1..c279eadf3 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -11,8 +11,8 @@ INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Wa INSERT INTO users (dtype,username,password,enabled) VALUES ('User','admin','admin', TRUE ); INSERT INTO authorities VALUES ('admin','admin'); -INSERT INTO users (dtype,username,password,enabled) VALUES ('User','manoli','manoli', TRUE ); +INSERT INTO users (dtype,username,password,enabled) VALUES ('User','manoli','manoli', TRUE ); INSERT INTO authorities VALUES ('manoli','client'); INSERT INTO users (dtype,username,password,enabled) VALUES ('User','david','david', TRUE ); INSERT INTO authorities VALUES ('david','client'); @@ -32,8 +32,18 @@ INSERT INTO usuarios VALUES (4, 'Pepe', 'Lopez', '12456776V', 'C/Macarena', '690 INSERT INTO clients (id, name, email, address, init, finish, telephone, description, code, food, username) VALUES (1,'bar manoli','manoli@gmail.com','C/Betis','10:00','22:00','608726190', 'description 1', 'code1', 'ESPAÑOLA','manoli'); INSERT INTO clients (id, name, email, address, init, finish, telephone, description, code, food, username) VALUES (2,'bar david','david@gmail.com','C/Sevilla','09:30','22:00','608726190', 'description 2', 'code2', 'americana','david'); -INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'FO-1', 'inactive', 1, 'macarrones', 15); -INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'T-1', 'active', 1, '12:00:00', '13:00:00', 10); -INSERT INTO speed_offers(start, end, code, status, 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',1,5,25,10,15,15,10); -INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'NU-1', 'active',1,15,25,10,15,5,10); +INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'FO-1', 'inactive', 1, 'macarrones', 15); +INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'FO-2', 'active', 1, 'macarrones con tomate', 10); +INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden', 1, 'macarrones con queso', 5); +INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'T-1', 'inactive', 1, '12:00:00', '13:00:00', 5); +INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-2', 'active', 1, '12:00:00', '13:00:00', 10); +INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden', 1, '12:00:00', '13:00:00', 15); + +INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'SP-1', 'inactive',1,5,25,10,15,15,10); +INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-2', 'active',1,5,25,10,15,15,10); +INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden',1,5,25,10,15,15,10); + +INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'NU-1', 'inactive',1,15,25,10,15,5,10); +INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-2', 'active',1,15,25,10,15,5,10); +INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden',1,15,25,10,15,5,10); diff --git a/src/main/resources/messages/messages_es.properties b/src/main/resources/messages/messages_es.properties index c93d14f77..dc3680cfd 100644 --- a/src/main/resources/messages/messages_es.properties +++ b/src/main/resources/messages/messages_es.properties @@ -5,12 +5,12 @@ cancel=Cancelar deleteOfferMessage=Confirme que quiere eliminar su oferta listOffers=Ver Ofertas createOffers=Crear Ofertas -foodOffers=Ofertas por plato espec�fico -foodOffer=Oferta por plato espec�fico -nuOffers=Ofertas por n�mero de comensales -nuOffer=Oferta por n�mero de comensales -speedOffers=Ofertas rapidez comiendo -speedOffer=Oferta por comer veloz +foodOffers=Ofertas por plato especÃfico +foodOffer=Oferta por plato especÃfico +nuOffers=Ofertas por número de comensales +nuOffer=Oferta por número de comensales +speedOffers=Ofertas por tiempo empleado en comer +speedOffer=Oferta por tiempo empleado en comer timeOffers=Ofertas por franja horaria timeOffer=Oferta por franja horaria food=Plato @@ -23,23 +23,23 @@ silverGoal=Meta plata silverDiscount=Descuento plata bronzeGoal=Meta bronce bronzeDiscount=Descuento bronce -startDate=Fecha inicio +startDate=Fecha de inicio offerBeginning=Inicio de la oferta -endDate=Fecha fin +endDate=Fecha de fin offerEnding=Fin de la oferta details=Detalles -offerCode=C�digo de la oferta +offerCode=Código de la oferta return=Volver -required=Es requerido Ofertas por franja horaria +required=Es requerido notFound=No ha sido encontrado duplicate=Ya se encuentra en uso -nonNumeric=S�lo debe contener n�meros -duplicateFormSubmission=No se permite el env�o de formularios duplicados -typeMismatch.date=Fecha inv�lida -typeMismatch.birthDate=Fecha inv�lida +nonNumeric=Solo debe contener números +duplicateFormSubmission=No se permite el envÃo de formularios duplicados +typeMismatch.date=Fecha inválida +typeMismatch.birthDate=Fecha inválida createFoodOffers= Crear ofertas por plato espec�fico createNuOffers= Crear ofertas por n�mero de comensales createSpeedOffers= Crear ofertas por rapidez comiendo createTimeOffers= Crear ofertas por franja horaria init= Inicio del intervalo -finish= Fin del intervalo \ No newline at end of file +finish= Fin del intervalo diff --git a/src/main/webapp/WEB-INF/jsp/login.jsp b/src/main/webapp/WEB-INF/jsp/login.jsp index aee0598c1..7c1b61609 100644 --- a/src/main/webapp/WEB-INF/jsp/login.jsp +++ b/src/main/webapp/WEB-INF/jsp/login.jsp @@ -282,24 +282,25 @@ - El usuario y/o la contraseña son incorrectos + El usuario y/o la contraseña son incorrectos - - + + Nombre de usuario o contraseña inválido + - - + + - + + ¿Olvidó su contraseña? + diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp index a2366158e..e396fb9d8 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/createOrUpdateFoodOfferForm.jsp @@ -11,6 +11,7 @@ + diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp index e293dbded..2ab994fb3 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersDisable.jsp @@ -2,15 +2,16 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> -<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> - + - ¿Está seguro de que quiere eliminar su oferta? + ¿Está seguro de que quiere eliminar su oferta? + @@ -20,4 +21,4 @@ Volver - + diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp index cf44e42c3..c86712314 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersShow.jsp @@ -9,7 +9,6 @@ - diff --git a/src/main/webapp/WEB-INF/jsp/offers/nu/createOrUpdateNuOfferForm.jsp b/src/main/webapp/WEB-INF/jsp/offers/nu/createOrUpdateNuOfferForm.jsp index d693e8ae9..b26ff61c5 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/createOrUpdateNuOfferForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/createOrUpdateNuOfferForm.jsp @@ -19,11 +19,11 @@ - + - + - + diff --git a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp index ed9ae26c3..2bb12404f 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersDisable.jsp @@ -2,13 +2,13 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> -<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> - ¿Está seguro de que quiere dar de baja su offer? + ¿Está seguro de que quiere dar de baja su offer? @@ -24,4 +24,4 @@ Volver - + diff --git a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp index 3cd94493f..fbeffec81 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersShow.jsp @@ -9,8 +9,9 @@ - - + + + diff --git a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp index 6173d1f53..bb3a1f033 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersDisable.jsp @@ -2,15 +2,16 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> -<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> - + - ¿Esta seguro de que quiere dar de baja su offer? + �Est� seguro de que quiere dar de baja su oferta? + @@ -24,4 +25,4 @@ Volver - + diff --git a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp index dec6dce11..a2147de9d 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersShow.jsp @@ -9,8 +9,9 @@ - - + + + diff --git a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp index 50fb6d606..1ae33a323 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersDisable.jsp @@ -2,13 +2,13 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> -<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> - ¿Esta seguro de que quiere eliminar su oferta? + �Est� seguro de que quiere eliminar su oferta? @@ -21,4 +21,4 @@ Volver - + diff --git a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp index c596986d8..fa76b0e56 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersShow.jsp @@ -83,5 +83,4 @@ } - diff --git a/src/main/webapp/WEB-INF/tags/htmlHeader.tag b/src/main/webapp/WEB-INF/tags/htmlHeader.tag index a259211ab..4fa699628 100644 --- a/src/main/webapp/WEB-INF/tags/htmlHeader.tag +++ b/src/main/webapp/WEB-INF/tags/htmlHeader.tag @@ -14,7 +14,7 @@ Cheapy :: a Spring Framework demonstration - Cheapy : eat fast, eat cheapy + Cheapy: Eat fast, eat cheapy <%-- CSS generated from LESS --%> diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index 10a512467..df3b03161 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -28,17 +28,23 @@ Inicio - + Ver ofertas - - - Mis ofertas - + + + Mis ofertas + + + + + + + Valóranos +
El usuario y/o la contraseña son incorrectos
El usuario y/o la contraseña son incorrectos
Nombre de usuario o contraseña inválido