Merge pull request #50 from cheapy-ispp/013-validaciones

013 validaciones
This commit is contained in:
Thiloparn 2021-04-02 20:32:06 +02:00 committed by GitHub
commit 21b0d9e292
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 493 additions and 270 deletions

133
readme.md
View file

@ -1,133 +0,0 @@
# Spring PetClinic Sample Application [![Build Status](https://travis-ci.org/spring-projects/spring-petclinic.png?branch=main)](https://travis-ci.org/spring-projects/spring-petclinic/)
## Understanding the Spring Petclinic application with a few diagrams
<a href="https://speakerdeck.com/michaelisvy/spring-petclinic-sample-application">See the presentation here</a>
## 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/
<img width="1042" alt="petclinic-screenshot" src="https://cloud.githubusercontent.com/assets/838318/19727082/2aee6d6c-9b8e-11e6-81fe-e889a5ddfded.png">
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 <https://editorconfig.org>. 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

View file

@ -17,10 +17,11 @@ package org.springframework.cheapy.model;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Range;
@Entity @Entity
@Table(name = "food_offers") @Table(name = "food_offers")
public class FoodOffer extends Offer { public class FoodOffer extends Offer {
@ -28,11 +29,11 @@ public class FoodOffer extends Offer {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
//Plato específico //Plato específico
@NotBlank @NotBlank(message = "Debe rellenar la comida a ofertar")
private String food; private String food;
@NotNull @NotNull(message = "Debe rellenar el descuento que proporciona")
@Min(0) @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %")
private Integer discount; private Integer discount;
public String getFood() { public String getFood() {

View file

@ -6,6 +6,8 @@ import javax.persistence.Table;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Range;
@Entity @Entity
@Table(name = "nu_offers") @Table(name = "nu_offers")
public class NuOffer extends Offer { public class NuOffer extends Offer {
@ -13,31 +15,31 @@ public class NuOffer extends Offer {
//Oferta por numero de comensales //Oferta por numero de comensales
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@NotNull @NotNull(message = "Debe rellenar el tiempo del rango oro")
@Min(1) @Min(1)
private Integer gold; private Integer gold;
@Column(name = "discount_gold") @Column(name = "discount_gold")
@NotNull @NotNull(message = "Debe rellenar el descuento del rango oro")
@Min(0) @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %")
private Integer discountGold; private Integer discountGold;
@NotNull @NotNull(message = "Debe rellenar el tiempo del rango plata")
@Min(1) @Min(1)
private Integer silver; private Integer silver;
@Column(name = "discount_silver") @Column(name = "discount_silver")
@NotNull @NotNull(message = "Debe rellenar el descuento del rango plata")
@Min(0) @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %")
private Integer discountSilver; private Integer discountSilver;
@NotNull @NotNull(message = "Debe rellenar el tiempo del rango bronce")
@Min(1) @Min(1)
private Integer bronze; private Integer bronze;
@Column(name = "discount_bronze") @Column(name = "discount_bronze")
@NotNull @NotNull(message = "Debe rellenar el descuento del rango bronce")
@Min(0) @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %")
private Integer discountBronze; private Integer discountBronze;
public Integer getGold() { public Integer getGold() {

View file

@ -35,13 +35,13 @@ public class Offer extends BaseEntity {
// Clase padre // Clase padre
@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
@NotNull @NotNull(message = "Debe introducir una fecha de inicio")
@Future @Future(message = "La fecha debe debe ser futura")
private LocalDateTime start; private LocalDateTime start;
@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm") @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
@NotNull @NotNull(message = "Debe introducir una fecha de fin")
@Future @Future(message = "La fecha debe debe ser futura")
private LocalDateTime end; private LocalDateTime end;
private String code; private String code;

View file

@ -6,6 +6,8 @@ import javax.persistence.Table;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Range;
@Entity @Entity
@Table(name = "speed_offers") @Table(name = "speed_offers")
public class SpeedOffer extends Offer { public class SpeedOffer extends Offer {
@ -13,31 +15,31 @@ public class SpeedOffer extends Offer {
// Ofertar por rapidez comiendo // Ofertar por rapidez comiendo
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@NotNull @NotNull(message = "Debe rellenar el tiempo del rango oro")
@Min(0) @Min(1)
private Integer gold; private Integer gold;
@Column(name = "discount_gold") @Column(name = "discount_gold")
@NotNull @NotNull(message = "Debe rellenar el descuento del rango oro")
@Min(0) @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %")
private Integer discountGold; private Integer discountGold;
@NotNull @NotNull(message = "Debe rellenar el tiempo del rango plata")
@Min(0) @Min(1)
private Integer silver; private Integer silver;
@Column(name = "discount_silver") @Column(name = "discount_silver")
@NotNull @NotNull(message = "Debe rellenar el descuento del rango plata")
@Min(0) @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %")
private Integer discountSilver; private Integer discountSilver;
@NotNull @NotNull(message = "Debe rellenar el tiempo del rango bronce")
@Min(0) @Min(1)
private Integer bronze; private Integer bronze;
@Column(name = "discount_bronze") @Column(name = "discount_bronze")
@NotNull @NotNull(message = "Debe rellenar el descuento del rango bronce")
@Min(0) @Range(min = 0, max = 100, message = "El descuento debe estar entre 0 y 100 %")
private Integer discountBronze; private Integer discountBronze;
public Integer getGold() { public Integer getGold() {

View file

@ -6,6 +6,7 @@ import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Range;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
@Entity @Entity
@ -17,14 +18,15 @@ public class TimeOffer extends Offer {
// Oferta por franja horaria // Oferta por franja horaria
@DateTimeFormat(pattern = "HH:mm") @DateTimeFormat(pattern = "HH:mm")
@NotNull @NotNull(message = "Debe introducir una hora de inicio")
private LocalTime init; private LocalTime init;
@DateTimeFormat(pattern = "HH:mm") @DateTimeFormat(pattern = "HH:mm")
@NotNull @NotNull(message = "Debe introducir una hora de fin")
private LocalTime finish; 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; private Integer discount;
public LocalTime getInit() { public LocalTime getInit() {

View file

@ -26,12 +26,6 @@ import org.springframework.cheapy.repository.AuthoritiesRepository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; 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 @Service
public class AuthoritiesService { public class AuthoritiesService {
/* /*

View file

@ -35,6 +35,11 @@ public class NuOfferService {
this.nuOfferRepository.save(nuOffer); this.nuOfferRepository.save(nuOffer);
} }
@Transactional
public void saveUpdateNuOffer(final NuOffer nuOfferNew, final NuOffer nuOfferOld) throws DataAccessException {
this.nuOfferRepository.save(nuOfferNew);
}
public List<NuOffer> findActiveNuOffer() { public List<NuOffer> findActiveNuOffer() {
return this.nuOfferRepository.findActiveNuOffer(StatusOffer.active); return this.nuOfferRepository.findActiveNuOffer(StatusOffer.active);
} }

View file

@ -4,8 +4,10 @@ package org.springframework.cheapy.web;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.Client;
import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
@ -31,6 +33,33 @@ public class FoodOfferController {
this.clientService = clientService; 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") @GetMapping("/offers/food/new")
public String initCreationForm(Map<String, Object> model) { public String initCreationForm(Map<String, Object> model) {
@ -44,6 +73,10 @@ public class FoodOfferController {
if (result.hasErrors()) { if (result.hasErrors()) {
return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
} else { } else {
if(!this.checkDates(foodOffer)) {
//Poner aqui mensaje de error
return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
}
Client client = this.clientService.getCurrentClient(); Client client = this.clientService.getCurrentClient();
foodOffer.setClient(client); foodOffer.setClient(client);
foodOffer.setStatus(StatusOffer.hidden); foodOffer.setStatus(StatusOffer.hidden);
@ -63,7 +96,7 @@ public class FoodOfferController {
} else { } else {
modelMap.addAttribute("message", "You don't have access to this food offer"); modelMap.addAttribute("message", "You don't have access to this food offer");
} }
return "redirect:/offers/food/"+foodOfferId; return "redirect:/offers/food/" + foodOfferId;
} }
@ -76,28 +109,50 @@ public class FoodOfferController {
model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"));
return "offers/food/foodOffersShow"; return "offers/food/foodOffersShow";
} }
@GetMapping(value = "/offers/food/{foodOfferId}/edit") @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); FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
if (foodOffer.getStatus().equals(StatusOffer.inactive)) {
return "error";
}
model.addAttribute("foodOffer", foodOffer); model.addAttribute("foodOffer", foodOffer);
request.getSession().setAttribute("idFood", foodOfferId);
return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
} }
@PostMapping(value = "/offers/food/{foodOfferId}/edit") @PostMapping(value = "/offers/food/{foodOfferId}/edit")
public String updateFoodOffer(@Valid final FoodOffer foodOfferEdit, final BindingResult result, 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()) { if (result.hasErrors()) {
model.addAttribute("foodOffer", foodOfferEdit); model.addAttribute("foodOffer", foodOfferEdit);
return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
} else { } 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); this.foodOfferService.saveFoodOffer(foodOfferEdit);
return "redirect:/offers/food/" + foodOfferEdit.getId(); return "redirect:/offers/food/" + foodOfferEdit.getId();
} }
@ -106,6 +161,9 @@ public class FoodOfferController {
@GetMapping(value = "/offers/food/{foodOfferId}/disable") @GetMapping(value = "/offers/food/{foodOfferId}/disable")
public String disableFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) { public String disableFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) {
if (!this.checkIdentity(foodOfferId)) {
return "error";
}
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
model.put("foodOffer", foodOffer); model.put("foodOffer", foodOffer);
@ -115,6 +173,9 @@ public class FoodOfferController {
@PostMapping(value = "/offers/food/{foodOfferId}/disable") @PostMapping(value = "/offers/food/{foodOfferId}/disable")
public String disableFoodOfferForm(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) { public String disableFoodOfferForm(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) {
if (!this.checkIdentity(foodOfferId)) {
return "error";
}
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
@ -122,7 +183,7 @@ public class FoodOfferController {
this.foodOfferService.saveFoodOffer(foodOffer); this.foodOfferService.saveFoodOffer(foodOffer);
return "redirect:/offers"; return "redirect:/myOffers";
} }
} }

View file

@ -4,15 +4,18 @@ import java.security.Principal;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.NuOffer;
import org.springframework.cheapy.model.SpeedOffer;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
import org.springframework.beans.BeanUtils;
import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.Client;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.ClientService;
import org.springframework.cheapy.service.NuOfferService; import org.springframework.cheapy.service.NuOfferService;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -32,6 +35,50 @@ public class NuOfferController {
this.clientService = clientService; 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") @GetMapping("/offers/nu/new")
public String initCreationForm(Map<String, Object> model) { public String initCreationForm(Map<String, Object> model) {
NuOffer nuOffer = new NuOffer(); NuOffer nuOffer = new NuOffer();
@ -44,6 +91,18 @@ public class NuOfferController {
if (result.hasErrors()) { if (result.hasErrors()) {
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
} else { } 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); nuOffer.setStatus(StatusOffer.hidden);
Client client = this.clientService.getCurrentClient(); Client client = this.clientService.getCurrentClient();
@ -51,11 +110,11 @@ public class NuOfferController {
nuOffer.setClient(client); nuOffer.setClient(client);
this.nuOfferService.saveNuOffer(nuOffer); 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) { public String activateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap modelMap) {
Client client = this.clientService.getCurrentClient(); Client client = this.clientService.getCurrentClient();
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
@ -67,7 +126,7 @@ public class NuOfferController {
} else { } else {
modelMap.addAttribute("message", "You don't have access to this number offer"); 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") @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); NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
if (nuOffer.getStatus().equals(StatusOffer.inactive)) {
return "error";
}
model.addAttribute("nuOffer", nuOffer); model.addAttribute("nuOffer", nuOffer);
request.getSession().setAttribute("idNu", nuOfferId);
return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
} }
@PostMapping(value = "/offers/nu/{nuOfferId}/edit") @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()) { if (result.hasErrors()) {
model.addAttribute("nuOffer", nuOfferEdit); model.addAttribute("nuOffer", nuOfferEdit);
return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
} else { } 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); this.nuOfferService.saveNuOffer(nuOfferEdit);
return "redirect:/offers/nu/" + nuOfferEdit.getId(); return "redirect:/offers/nu/" + nuOfferEdit.getId();
} }
@ -107,6 +197,9 @@ public class NuOfferController {
public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal,
final ModelMap model) { final ModelMap model) {
if (!this.checkIdentity(nuOfferId)) {
return "error";
}
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
model.put("nuOffer", nuOffer); model.put("nuOffer", nuOffer);
@ -117,11 +210,14 @@ public class NuOfferController {
public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal,
final ModelMap model) { final ModelMap model) {
if (!this.checkIdentity(nuOfferId)) {
return "error";
}
NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId);
nuOffer.setStatus(StatusOffer.inactive); nuOffer.setStatus(StatusOffer.inactive);
this.nuOfferService.saveNuOffer(nuOffer); this.nuOfferService.saveNuOffer(nuOffer);
return "redirect:/offers"; return "redirect:/myOffers";
} }

View file

@ -3,11 +3,14 @@ package org.springframework.cheapy.web;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.SpeedOffer;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
import org.springframework.beans.BeanUtils;
import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.Client;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.ClientService;
import org.springframework.cheapy.service.SpeedOfferService; import org.springframework.cheapy.service.SpeedOfferService;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -30,6 +33,49 @@ public class SpeedOfferController {
this.clientService = clientService; 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") @GetMapping("/offers/speed/new")
public String initCreationForm(Map<String, Object> model) { public String initCreationForm(Map<String, Object> model) {
@ -43,6 +89,18 @@ public class SpeedOfferController {
if (result.hasErrors()) { if (result.hasErrors()) {
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
} else { } 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(); Client client = this.clientService.getCurrentClient();
speedOffer.setClient(client); speedOffer.setClient(client);
speedOffer.setStatus(StatusOffer.hidden); speedOffer.setStatus(StatusOffer.hidden);
@ -51,7 +109,6 @@ public class SpeedOfferController {
} }
} }
@GetMapping(value = "/offers/speed/{speedOfferId}/activate") @GetMapping(value = "/offers/speed/{speedOfferId}/activate")
public String activateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, ModelMap modelMap) { public String activateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, ModelMap modelMap) {
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
@ -77,21 +134,53 @@ public class SpeedOfferController {
} }
@GetMapping(value = "/offers/speed/{speedOfferId}/edit") @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); SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
if (speedOffer.getStatus().equals(StatusOffer.inactive)) {
return "error";
}
model.addAttribute("speedOffer", speedOffer); model.addAttribute("speedOffer", speedOffer);
request.getSession().setAttribute("idSpeed", speedOfferId);
return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
} }
@PostMapping(value = "/offers/speed/{speedOfferId}/edit") @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()) { if (result.hasErrors()) {
model.addAttribute("speedOffer", speedOfferEdit); model.addAttribute("speedOffer", speedOfferEdit);
return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
} else { } 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); this.speedOfferService.saveSpeedOffer(speedOfferEdit);
return "redirect:/offers/speed/" + speedOfferEdit.getId(); return "redirect:/offers/speed/" + speedOfferEdit.getId();
} }
@ -101,6 +190,9 @@ public class SpeedOfferController {
@GetMapping(value = "/offers/speed/{speedOfferId}/disable") @GetMapping(value = "/offers/speed/{speedOfferId}/disable")
public String disableSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) { public String disableSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) {
if (!this.checkIdentity(speedOfferId)) {
return "error";
}
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
model.put("speedOffer", speedOffer); model.put("speedOffer", speedOffer);
@ -110,6 +202,9 @@ public class SpeedOfferController {
@PostMapping(value = "/offers/speed/{speedOfferId}/disable") @PostMapping(value = "/offers/speed/{speedOfferId}/disable")
public String disableSpeedOfferForm(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) { public String disableSpeedOfferForm(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) {
if (!this.checkIdentity(speedOfferId)) {
return "error";
}
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
@ -117,7 +212,7 @@ public class SpeedOfferController {
this.speedOfferService.saveSpeedOffer(speedOffer); this.speedOfferService.saveSpeedOffer(speedOffer);
return "redirect:/offers"; return "redirect:/myOffers";
} }
} }

View file

@ -1,12 +1,14 @@
package org.springframework.cheapy.web; package org.springframework.cheapy.web;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.Client;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.StatusOffer;
import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.model.TimeOffer;
import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.ClientService;
@ -21,7 +23,6 @@ import org.springframework.web.bind.annotation.PostMapping;
@Controller @Controller
public class TimeOfferController { public class TimeOfferController {
private static final String VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM = "offers/time/createOrUpdateTimeOfferForm"; private static final String VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM = "offers/time/createOrUpdateTimeOfferForm";
private final TimeOfferService timeOfferService; private final TimeOfferService timeOfferService;
private final ClientService clientService; private final ClientService clientService;
@ -31,6 +32,42 @@ public class TimeOfferController {
this.clientService = clientService; 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") @GetMapping("/offers/time/new")
public String initCreationForm(Map<String, Object> model) { public String initCreationForm(Map<String, Object> model) {
TimeOffer timeOffer = new TimeOffer(); TimeOffer timeOffer = new TimeOffer();
@ -43,6 +80,16 @@ public class TimeOfferController {
if (result.hasErrors()) { if (result.hasErrors()) {
return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
} else { } 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); timeOffer.setStatus(StatusOffer.hidden);
Client client = this.clientService.getCurrentClient(); 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) { public String activateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap modelMap) {
Client client = this.clientService.getCurrentClient(); Client client = this.clientService.getCurrentClient();
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
@ -63,13 +110,11 @@ public class TimeOfferController {
timeOffer.setCode("TI-" + timeOfferId); timeOffer.setCode("TI-" + timeOfferId);
this.timeOfferService.saveTimeOffer(timeOffer); this.timeOfferService.saveTimeOffer(timeOffer);
} else { } else {
modelMap.addAttribute("message", "You don't have access to this time offer"); modelMap.addAttribute("message", "You don't have access to this time offer");
} }
return "redirect:/offers/time/" + timeOffer.getId(); return "redirect:/offers/time/" + timeOffer.getId();
} }
@GetMapping("/offers/time/{timeOfferId}") @GetMapping("/offers/time/{timeOfferId}")
@ -86,23 +131,50 @@ public class TimeOfferController {
} }
@GetMapping(value = "/offers/time/{timeOfferId}/edit") @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); TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
if (timeOffer.getStatus().equals(StatusOffer.inactive)) {
return "error";
}
model.addAttribute("timeOffer", timeOffer); model.addAttribute("timeOffer", timeOffer);
request.getSession().setAttribute("idTime", timeOfferId);
return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
} }
@PostMapping(value = "/offers/time/{timeOfferId}/edit") @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()) { if (result.hasErrors()) {
model.addAttribute("timeOffer", timeOfferEdit); model.addAttribute("timeOffer", timeOfferEdit);
return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
} else { } 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); this.timeOfferService.saveTimeOffer(timeOfferEdit);
return "redirect:/offers/time/" + timeOfferEdit.getId(); return "redirect:/offers/time/" + timeOfferEdit.getId();
} }
@ -112,6 +184,9 @@ public class TimeOfferController {
@GetMapping(value = "/offers/time/{timeOfferId}/disable") @GetMapping(value = "/offers/time/{timeOfferId}/disable")
public String disableTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) { public String disableTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) {
if (!this.checkIdentity(timeOfferId)) {
return "error";
}
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
model.put("timeOffer", timeOffer); model.put("timeOffer", timeOffer);
@ -121,6 +196,9 @@ public class TimeOfferController {
@PostMapping(value = "/offers/time/{timeOfferId}/disable") @PostMapping(value = "/offers/time/{timeOfferId}/disable")
public String disableTimeOfferForm(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) { public String disableTimeOfferForm(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) {
if (!this.checkIdentity(timeOfferId)) {
return "error";
}
TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId);
@ -128,8 +206,7 @@ public class TimeOfferController {
this.timeOfferService.saveTimeOffer(timeOffer); this.timeOfferService.saveTimeOffer(timeOffer);
return "redirect:/offers"; return "redirect:/myOffers";
} }

View file

@ -1,3 +1,5 @@
__^__ __^__ __^__ __^__
( ___ )------------------------------------( ___ ) ( ___ )------------------------------------( ___ )
| / | | \ | | / | | \ |
@ -5,5 +7,4 @@
|___| |___| |___| |___|
(_____)------------------------------------(_____) (_____)------------------------------------(_____)
:: Built with Spring Boot :: ${spring-boot.version} -- Built with Spring Boot -- (${spring-boot.version})

View file

@ -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 users (dtype,username,password,enabled) VALUES ('User','admin','admin', TRUE );
INSERT INTO authorities VALUES ('admin','admin'); 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 authorities VALUES ('manoli','client');
INSERT INTO users (dtype,username,password,enabled) VALUES ('User','david','david', TRUE ); INSERT INTO users (dtype,username,password,enabled) VALUES ('User','david','david', TRUE );
INSERT INTO authorities VALUES ('david','client'); 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 (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 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 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 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 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 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 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 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 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);

View file

@ -5,12 +5,12 @@ cancel=Cancelar
deleteOfferMessage=Confirme que quiere eliminar su oferta deleteOfferMessage=Confirme que quiere eliminar su oferta
listOffers=Ver Ofertas listOffers=Ver Ofertas
createOffers=Crear Ofertas createOffers=Crear Ofertas
foodOffers=Ofertas por plato espec<EFBFBD>fico foodOffers=Ofertas por plato específico
foodOffer=Oferta por plato espec<EFBFBD>fico foodOffer=Oferta por plato específico
nuOffers=Ofertas por n<EFBFBD>mero de comensales nuOffers=Ofertas por número de comensales
nuOffer=Oferta por n<EFBFBD>mero de comensales nuOffer=Oferta por número de comensales
speedOffers=Ofertas rapidez comiendo speedOffers=Ofertas por tiempo empleado en comer
speedOffer=Oferta por comer veloz speedOffer=Oferta por tiempo empleado en comer
timeOffers=Ofertas por franja horaria timeOffers=Ofertas por franja horaria
timeOffer=Oferta por franja horaria timeOffer=Oferta por franja horaria
food=Plato food=Plato
@ -23,20 +23,20 @@ silverGoal=Meta plata
silverDiscount=Descuento plata silverDiscount=Descuento plata
bronzeGoal=Meta bronce bronzeGoal=Meta bronce
bronzeDiscount=Descuento bronce bronzeDiscount=Descuento bronce
startDate=Fecha inicio startDate=Fecha de inicio
offerBeginning=Inicio de la oferta offerBeginning=Inicio de la oferta
endDate=Fecha fin endDate=Fecha de fin
offerEnding=Fin de la oferta offerEnding=Fin de la oferta
details=Detalles details=Detalles
offerCode=C<EFBFBD>digo de la oferta offerCode=Código de la oferta
return=Volver return=Volver
required=Es requerido Ofertas por franja horaria required=Es requerido
notFound=No ha sido encontrado notFound=No ha sido encontrado
duplicate=Ya se encuentra en uso duplicate=Ya se encuentra en uso
nonNumeric=S<EFBFBD>lo debe contener n<>meros nonNumeric=Solo debe contener números
duplicateFormSubmission=No se permite el env<EFBFBD>o de formularios duplicados duplicateFormSubmission=No se permite el envío de formularios duplicados
typeMismatch.date=Fecha inv<EFBFBD>lida typeMismatch.date=Fecha inválida
typeMismatch.birthDate=Fecha inv<EFBFBD>lida typeMismatch.birthDate=Fecha inválida
createFoodOffers= Crear ofertas por plato espec<65>fico createFoodOffers= Crear ofertas por plato espec<65>fico
createNuOffers= Crear ofertas por n<>mero de comensales createNuOffers= Crear ofertas por n<>mero de comensales
createSpeedOffers= Crear ofertas por rapidez comiendo createSpeedOffers= Crear ofertas por rapidez comiendo

View file

@ -282,24 +282,25 @@
<div class="fadeIn first"> <div class="fadeIn first">
<img src="/resources/images/Logo Cheapy.png" id="icon" /> <img src="/resources/images/Logo Cheapy.png" id="icon" />
<c:if test= "${not empty param}" > <c:if test= "${not empty param}" >
<p class="text-danger"> El usuario y/o la contraseña son incorrectos </p> <p class="text-danger"> El usuario y/o la contraseña son incorrectos </p>
</c:if> </c:if>
</div> </div>
<div th:if="${param.error}">
<p class="text-danger">Nombre de usuario o contraseña inválido</p>
</div>
<!-- Login Form --> <!-- Login Form -->
<form class='form-signin' action="/login" method='POST'> <form class='form-signin' action="/login" method='POST'>
<input type="text" id="username" class="fadeIn second" name="username" placeholder="Usuario" required autofocus> <input type="text" id="username" class="fadeIn second" name="username" placeholder="nombre de usuario" required autofocus>
<input type="password" id="password" class="fadeIn third" name="password" placeholder="Contraseña" required> <input type="password" id="password" class="fadeIn third" name="password" placeholder="contraseña" required>
<sec:csrfInput /> <sec:csrfInput />
<input type="submit" class="fadeIn fourth" value="Iniciar sesión"> <input type="submit" class="fadeIn fourth" value="Acceder">
</form> </form>
<!-- Remind Passowrd <!-- Remind Passowrd
<div id="formFooter"> <div id="formFooter">
<a class="underlineHover" href="#">Forgot Password?</a> <a class="underlineHover" href="#">¿Olvidó su contraseña?</a>
</div> --> </div>
</div> </div>
</div> </div>

View file

@ -11,6 +11,7 @@
<h2 style="text-align:center;padding:5px"> <h2 style="text-align:center;padding:5px">
<c:if test="${foodOffer['new']}"><fmt:message key="new"/> </c:if> <fmt:message key="foodOffer"/> <c:if test="${foodOffer['new']}"><fmt:message key="new"/> </c:if> <fmt:message key="foodOffer"/>
</h2> </h2>
<form:form modelAttribute="foodOffer" class="form-horizontal" id="add-foodOffer-form"> <form:form modelAttribute="foodOffer" class="form-horizontal" id="add-foodOffer-form">
<div class="form-group has-feedback"> <div class="form-group has-feedback">
<form:hidden path="id"/> <form:hidden path="id"/>

View file

@ -2,15 +2,16 @@
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <%@ 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"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<petclinic:layout pageName="foodOffer"> <cheapy:layout pageName="foodOffer">
<jsp:body> <jsp:body>
<h2> ¿Está seguro de que quiere eliminar su oferta? </h2> <h2> ¿Está seguro de que quiere eliminar su oferta? </h2>
<form:form modelAttribute="foodOffer" class="form-horizontal"> <form:form modelAttribute="foodOffer" class="form-horizontal">
<input type="hidden" name="food" value="${foodOffer.food}" /> <input type="hidden" name="food" value="${foodOffer.food}" />
<input type="hidden" name="discount" value="${foodOffer.discount}" /> <input type="hidden" name="discount" value="${foodOffer.discount}" />
@ -20,4 +21,4 @@
<a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a> <a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a>
</jsp:body> </jsp:body>
</petclinic:layout> </cheapy:layout>

View file

@ -9,7 +9,6 @@
<cheapy:layout pageName="foodOffer"> <cheapy:layout pageName="foodOffer">
<h2 style="text-align:center;padding:5px"><fmt:message key="foodOffer"/></h2> <h2 style="text-align:center;padding:5px"><fmt:message key="foodOffer"/></h2>

View file

@ -19,11 +19,11 @@
<cheapy:inputField label="Fecha de Inicio" placeholder="dd/MM/yyyy HH:mm" name="start"/> <cheapy:inputField label="Fecha de Inicio" placeholder="dd/MM/yyyy HH:mm" name="start"/>
<cheapy:inputField label="Fecha de Fin" placeholder="dd/MM/yyyy HH:mm" name="end"/> <cheapy:inputField label="Fecha de Fin" placeholder="dd/MM/yyyy HH:mm" name="end"/>
<cheapy:inputField label="Número de comensales (nivel Oro)" placeholder="XX (Ej. 6)" name="gold"/> <cheapy:inputField label="Número de comensales (nivel Oro)" placeholder="XX (Ej. 6)" name="gold"/>
<cheapy:inputField label="Descuento de nivel oro" placeholder="XX% (Ej. 30)" name="discountGold"/> <cheapy:inputField label="Descuento de nivel oro" placeholder="XX% (Ej. 30)" name="discountGold"/>
<cheapy:inputField label="Número de comensales (nivel Plata)" placeholder="XX (Ej. 4)" name="silver"/> <cheapy:inputField label="Número de comensales (nivel Plata)" placeholder="XX (Ej. 4)" name="silver"/>
<cheapy:inputField label="Descuento de plata" placeholder="XX% (Ej. 15)" name="discountSilver"/> <cheapy:inputField label="Descuento de plata" placeholder="XX% (Ej. 15)" name="discountSilver"/>
<cheapy:inputField label="Número de comensales (nivel Bronce)" placeholder="XX (Ej. 2)" name="bronze"/> <cheapy:inputField label="Número de comensales (nivel Bronce)" placeholder="XX (Ej. 2)" name="bronze"/>
<cheapy:inputField label="Descuento de bronce" placeholder="XX% (Ej. 5)" name="discountBronze"/> <cheapy:inputField label="Descuento de bronce" placeholder="XX% (Ej. 5)" name="discountBronze"/>
</div> </div>

View file

@ -2,13 +2,13 @@
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <%@ 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"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<petclinic:layout pageName="nuOfferDisable"> <petclinic:layout pageName="nuOfferDisable">
<jsp:body> <jsp:body>
<h2> ¿Está seguro de que quiere dar de baja su offer? </h2> <h2> ¿Está seguro de que quiere dar de baja su offer? </h2>
<form:form modelAttribute="nuOffer" class="form-horizontal"> <form:form modelAttribute="nuOffer" class="form-horizontal">
<input type="hidden" name="gold" value="${nuOffer.gold}" /> <input type="hidden" name="gold" value="${nuOffer.gold}" />
@ -24,4 +24,4 @@
<a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a> <a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a>
</jsp:body> </jsp:body>
</petclinic:layout> </cheapy:layout>

View file

@ -9,8 +9,9 @@
<cheapy:layout pageName="nuOffer"> <cheapy:layout pageName="nuOffer">
<h2 style="text-align:center;padding:5px"><fmt:message key="nuOffer"/></h2> <h2 style="text-align: center; padding: 5px">
<fmt:message key="nuOffer" />
</h2>
<table class="table table-striped" id="nuOffer-table"> <table class="table table-striped" id="nuOffer-table">
<tr> <tr>

View file

@ -2,15 +2,16 @@
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <%@ 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"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<petclinic:layout pageName="speedOffer"> <cheapy:layout pageName="speedOffer">
<jsp:body> <jsp:body>
<h2> ¿Esta seguro de que quiere dar de baja su offer? </h2> <h2> <EFBFBD>Est<EFBFBD> seguro de que quiere dar de baja su oferta? </h2>
<form:form modelAttribute="speedOffer" class="form-horizontal"> <form:form modelAttribute="speedOffer" class="form-horizontal">
<input type="hidden" name="gold" value="${speedOffer.gold}" /> <input type="hidden" name="gold" value="${speedOffer.gold}" />
<input type="hidden" name="discountGold" value="${speedOffer.discountGold}" /> <input type="hidden" name="discountGold" value="${speedOffer.discountGold}" />
<input type="hidden" name="silver" value="${speedOffer.silver}" /> <input type="hidden" name="silver" value="${speedOffer.silver}" />
@ -24,4 +25,4 @@
<a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a> <a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a>
</jsp:body> </jsp:body>
</petclinic:layout> </cheapy:layout>

View file

@ -9,8 +9,9 @@
<cheapy:layout pageName="speedOffer"> <cheapy:layout pageName="speedOffer">
<h2 style="text-align:center;padding:5px"><fmt:message key="speedOffer"/></h2> <h2 style="text-align: center; padding: 5px">
<fmt:message key="speedOffer" />
</h2>
<table class="table table-striped" id="speedOffer-table"> <table class="table table-striped" id="speedOffer-table">
<tr> <tr>

View file

@ -2,13 +2,13 @@
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <%@ 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"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<petclinic:layout pageName="timeOffer"> <petclinic:layout pageName="timeOffer">
<jsp:body> <jsp:body>
<h2> ¿Esta seguro de que quiere eliminar su oferta? </h2> <h2> <EFBFBD>Est<EFBFBD> seguro de que quiere eliminar su oferta? </h2>
<form:form modelAttribute="timeOffer" class="form-horizontal"> <form:form modelAttribute="timeOffer" class="form-horizontal">
<input type="hidden" name="init" value="${timeOffer.init}" /> <input type="hidden" name="init" value="${timeOffer.init}" />
@ -21,4 +21,4 @@
<a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a> <a class="btn btn-default" href='<spring:url value="/offers" htmlEscape="true"/>'>Volver</a>
</jsp:body> </jsp:body>
</petclinic:layout> </cheapy:layout>

View file

@ -83,5 +83,4 @@
} }
</script> </script>
</cheapy:layout> </cheapy:layout>

View file

@ -14,7 +14,7 @@ Cheapy :: a Spring Framework demonstration
<spring:url value="/resources/images/faviconChikito.png" var="favicon"/> <spring:url value="/resources/images/faviconChikito.png" var="favicon"/>
<link rel="shortcut icon" type="image/x-icon" href="${favicon}"> <link rel="shortcut icon" type="image/x-icon" href="${favicon}">
<title>Cheapy : eat fast, eat cheapy</title> <title>Cheapy: Eat fast, eat cheapy</title>
<%-- CSS generated from LESS --%> <%-- CSS generated from LESS --%>
<spring:url value="/resources/css/cheapy.css" var="cheapyCss"/> <spring:url value="/resources/css/cheapy.css" var="cheapyCss"/>

View file

@ -28,17 +28,23 @@
<span>Inicio</span> <span>Inicio</span>
</cheapy:menuItem> </cheapy:menuItem>
<cheapy:menuItem active="${name eq 'ofertas'}" url="/offers" <cheapy:menuItem active="${name eq 'ofertas'}" url="/offers" title="ofertas">
title="ofertas">
<span class="glyphicon glyphicon-cutlery" aria-hidden="true"></span> <span class="glyphicon glyphicon-cutlery" aria-hidden="true"></span>
<span>Ver ofertas</span> <span>Ver ofertas</span>
</cheapy:menuItem> </cheapy:menuItem>
<sec:authorize access="hasAnyAuthority('client')"> <sec:authorize access="hasAnyAuthority('client')">
<cheapy:menuItem active="${name eq 'ofertas'}" url="/myOffers" title="misOfertas"> <cheapy:menuItem active="${name eq 'ofertass'}" url="/myOffers" title="misOfertas">
<span class="glyphicon glyphicon-cutlery" aria-hidden="true"></span> <span class="glyphicon glyphicon-cutlery" aria-hidden="true"></span>
<span>Mis ofertas</span> <span>Mis ofertas</span>
</cheapy:menuItem> </cheapy:menuItem>
</sec:authorize>
<sec:authorize access="hasAnyAuthority('usuario')">
<cheapy:menuItem active="${name eq 'ofertas'}" url="/myOffers" title="valoranos">
<span class="glyphicon glyphicon-star" aria-hidden="true"></span>
<span>Valóranos</span>
</cheapy:menuItem>
</sec:authorize> </sec:authorize>
<!-- <!--
<cheapy:menuItem active="${name eq 'contactanos'}" url="/contactanos" <cheapy:menuItem active="${name eq 'contactanos'}" url="/contactanos"
@ -54,7 +60,7 @@
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<sec:authorize access="!isAuthenticated()"> <sec:authorize access="!isAuthenticated()">
<li><a href="<c:url value="/login" />">Login</a></li> <li><a href="<c:url value="/login" />">Iniciar sesión</a></li>
<!--<li><a href="<c:url value="/users/new" />">Register</a></li>--> <!--<li><a href="<c:url value="/users/new" />">Register</a></li>-->
</sec:authorize> </sec:authorize>
<sec:authorize access="isAuthenticated()"> <sec:authorize access="isAuthenticated()">