mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 15:55:49 +00:00
Merge pull request #59 from cheapy-ispp/011-pruebas-unitarias-publicar-ofertas-abel
This commit is contained in:
commit
3cddfa2d51
7 changed files with 115 additions and 98 deletions
|
@ -55,7 +55,7 @@ public class FoodOfferController {
|
|||
|
||||
private boolean checkDates(final FoodOffer foodOffer) {
|
||||
boolean res = false;
|
||||
if(foodOffer.getEnd().isAfter(foodOffer.getStart())) {
|
||||
if(foodOffer.getEnd()==null || foodOffer.getStart()==null || foodOffer.getEnd().isAfter(foodOffer.getStart())) {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
|
@ -70,19 +70,20 @@ public class FoodOfferController {
|
|||
|
||||
@PostMapping("/offers/food/new")
|
||||
public String processCreationForm(@Valid FoodOffer foodOffer, BindingResult result) {
|
||||
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;
|
||||
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio");
|
||||
|
||||
}
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
foodOffer.setClient(client);
|
||||
foodOffer.setStatus(StatusOffer.hidden);
|
||||
this.foodOfferService.saveFoodOffer(foodOffer);
|
||||
return "redirect:/offers/food/" + foodOffer.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/food/{foodOfferId}/activate")
|
||||
|
@ -143,21 +144,22 @@ public class FoodOfferController {
|
|||
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
|
||||
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio");
|
||||
|
||||
}
|
||||
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("foodOffer", foodOfferEdit);
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/food/{foodOfferId}/disable")
|
||||
|
|
|
@ -7,12 +7,10 @@ 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.model.NuOffer;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.NuOfferService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -57,15 +55,17 @@ public class NuOfferController {
|
|||
|
||||
private boolean checkDates(final NuOffer nuOffer) {
|
||||
boolean res = false;
|
||||
if(nuOffer.getEnd().isAfter(nuOffer.getStart())) {
|
||||
if(nuOffer.getEnd()==null || nuOffer.getStart()==null || nuOffer.getEnd().isAfter(nuOffer.getStart())) {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private boolean checkConditions(final NuOffer NuOffer) {
|
||||
private boolean checkConditions(final NuOffer nuOffer) {
|
||||
boolean res = false;
|
||||
if(NuOffer.getGold() > NuOffer.getSilver() && NuOffer.getSilver() > NuOffer.getBronze()) {
|
||||
if(nuOffer.getGold()==null || nuOffer.getSilver()==null || nuOffer.getBronze()==null) {
|
||||
|
||||
}else if(nuOffer.getGold() >= nuOffer.getSilver() && nuOffer.getSilver() >= nuOffer.getBronze()) {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
|
@ -73,7 +73,8 @@ public class NuOfferController {
|
|||
|
||||
private boolean checkDiscounts(final NuOffer NuOffer) {
|
||||
boolean res = false;
|
||||
if(NuOffer.getDiscountGold() > NuOffer.getDiscountSilver() && NuOffer.getDiscountSilver() > NuOffer.getDiscountBronze()) {
|
||||
if(NuOffer.getDiscountGold()==null || NuOffer.getDiscountSilver()==null || NuOffer.getDiscountBronze()==null) {
|
||||
}else if(NuOffer.getDiscountGold() >= NuOffer.getDiscountSilver() && NuOffer.getDiscountSilver() >= NuOffer.getDiscountBronze()) {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
|
@ -88,21 +89,23 @@ public class NuOfferController {
|
|||
|
||||
@PostMapping("/offers/nu/new")
|
||||
public String processCreationForm(@Valid NuOffer nuOffer, BindingResult result) {
|
||||
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;
|
||||
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio");
|
||||
|
||||
}
|
||||
if(!this.checkConditions(nuOffer)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("gold","" ,"Oro debe ser mayor o igual que plata, y plata mayor o igual que bronce");
|
||||
|
||||
}
|
||||
if(!this.checkDiscounts(nuOffer)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("discountGold","" ,"El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce");
|
||||
|
||||
}
|
||||
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
nuOffer.setStatus(StatusOffer.hidden);
|
||||
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
|
@ -111,7 +114,7 @@ public class NuOfferController {
|
|||
|
||||
this.nuOfferService.saveNuOffer(nuOffer);
|
||||
return "redirect:/offers/nu/" + nuOffer.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/nu/{nuOfferId}/activate")
|
||||
|
@ -173,28 +176,30 @@ public class NuOfferController {
|
|||
return "error";
|
||||
}
|
||||
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("nuOffer", nuOfferEdit);
|
||||
return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
|
||||
} else {
|
||||
if(!this.checkDates(nuOfferEdit)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio");
|
||||
|
||||
}
|
||||
if(!this.checkConditions(nuOfferEdit)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("gold","" ,"Oro debe ser mayor o igual que plata, y plata mayor o igual que bronce");
|
||||
|
||||
}
|
||||
if(!this.checkDiscounts(nuOfferEdit)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("discountGold","" ,"El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce");
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("nuOffer", nuOfferEdit);
|
||||
return NuOfferController.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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/nu/{nuOfferId}/disable")
|
||||
|
|
|
@ -6,11 +6,10 @@ 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.model.SpeedOffer;
|
||||
import org.springframework.cheapy.model.StatusOffer;
|
||||
import org.springframework.cheapy.service.ClientService;
|
||||
import org.springframework.cheapy.service.SpeedOfferService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -55,7 +54,7 @@ public class SpeedOfferController {
|
|||
|
||||
private boolean checkDates(final SpeedOffer speedOffer) {
|
||||
boolean res = false;
|
||||
if(speedOffer.getEnd().isAfter(speedOffer.getStart())) {
|
||||
if(speedOffer.getEnd()==null || speedOffer.getStart()==null || speedOffer.getEnd().isAfter(speedOffer.getStart())) {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
|
@ -63,7 +62,9 @@ public class SpeedOfferController {
|
|||
|
||||
private boolean checkConditions(final SpeedOffer speedOffer) {
|
||||
boolean res = false;
|
||||
if(speedOffer.getGold() < speedOffer.getSilver() && speedOffer.getSilver() < speedOffer.getBronze()) {
|
||||
if(speedOffer.getGold()==null || speedOffer.getSilver()==null || speedOffer.getBronze()==null) {
|
||||
|
||||
}else if(speedOffer.getGold() <= speedOffer.getSilver() && speedOffer.getSilver() <= speedOffer.getBronze()) {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
|
@ -71,7 +72,8 @@ public class SpeedOfferController {
|
|||
|
||||
private boolean checkDiscounts(final SpeedOffer speedOffer) {
|
||||
boolean res = false;
|
||||
if(speedOffer.getDiscountGold() > speedOffer.getDiscountSilver() && speedOffer.getDiscountSilver() > speedOffer.getDiscountBronze()) {
|
||||
if(speedOffer.getDiscountGold()==null || speedOffer.getDiscountSilver()==null || speedOffer.getDiscountBronze()==null) {
|
||||
}else if(speedOffer.getDiscountGold() >= speedOffer.getDiscountSilver() && speedOffer.getDiscountSilver() >= speedOffer.getDiscountBronze()) {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
|
@ -86,27 +88,30 @@ public class SpeedOfferController {
|
|||
|
||||
@PostMapping("/offers/speed/new")
|
||||
public String processCreationForm(@Valid SpeedOffer speedOffer, BindingResult result) {
|
||||
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;
|
||||
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio");
|
||||
|
||||
}
|
||||
if(!this.checkConditions(speedOffer)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("gold","" ,"Oro debe ser menor o igual que plata, y plata menor o igual que bronce");
|
||||
|
||||
}
|
||||
if(!this.checkDiscounts(speedOffer)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("discountGold","" ,"El descuento de Oro debe ser menor o igual que el de plata, y el de plata menor o igual que el de bronce");
|
||||
|
||||
}
|
||||
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
speedOffer.setClient(client);
|
||||
speedOffer.setStatus(StatusOffer.hidden);
|
||||
this.speedOfferService.saveSpeedOffer(speedOffer);
|
||||
return "redirect:/offers/speed/" + speedOffer.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/speed/{speedOfferId}/activate")
|
||||
|
@ -165,28 +170,29 @@ public class SpeedOfferController {
|
|||
return "error";
|
||||
}
|
||||
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("speedOffer", speedOfferEdit);
|
||||
return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
|
||||
} else {
|
||||
if(!this.checkDates(speedOfferEdit)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio");
|
||||
|
||||
}
|
||||
if(!this.checkConditions(speedOfferEdit)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("gold","" ,"Oro debe ser menor o igual que plata, y plata menor o igual que bronce");
|
||||
|
||||
}
|
||||
if(!this.checkDiscounts(speedOfferEdit)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("discountGold","" ,"El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce");
|
||||
|
||||
}
|
||||
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("speedOffer", speedOfferEdit);
|
||||
return SpeedOfferController.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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ 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;
|
||||
|
@ -54,7 +53,7 @@ public class TimeOfferController {
|
|||
|
||||
private boolean checkDates(final TimeOffer timeOffer) {
|
||||
boolean res = false;
|
||||
if(timeOffer.getEnd().isAfter(timeOffer.getStart())) {
|
||||
if(timeOffer.getEnd()==null || timeOffer.getStart()==null || timeOffer.getEnd().isAfter(timeOffer.getStart())) {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
|
@ -62,7 +61,7 @@ public class TimeOfferController {
|
|||
|
||||
private boolean checkTimes(final TimeOffer timeOffer) {
|
||||
boolean res = false;
|
||||
if(timeOffer.getFinish().isAfter(timeOffer.getInit())) {
|
||||
if(timeOffer.getFinish()==null || timeOffer.getInit()==null || timeOffer.getFinish().isAfter(timeOffer.getInit())) {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
|
@ -77,19 +76,21 @@ public class TimeOfferController {
|
|||
|
||||
@PostMapping("/offers/time/new")
|
||||
public String processCreationForm(@Valid TimeOffer timeOffer, BindingResult result) {
|
||||
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;
|
||||
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio");
|
||||
|
||||
}
|
||||
|
||||
if(!this.checkTimes(timeOffer)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("finish","" ,"La hora de fin debe ser posterior a la de inicio");
|
||||
|
||||
}
|
||||
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
timeOffer.setStatus(StatusOffer.hidden);
|
||||
|
||||
Client client = this.clientService.getCurrentClient();
|
||||
|
@ -98,7 +99,7 @@ public class TimeOfferController {
|
|||
|
||||
this.timeOfferService.saveTimeOffer(timeOffer);
|
||||
return "redirect:/offers/time/" + timeOffer.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value = "/offers/time/{timeOfferId}/activate")
|
||||
|
@ -163,24 +164,26 @@ public class TimeOfferController {
|
|||
return "error";
|
||||
}
|
||||
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("timeOffer", timeOfferEdit);
|
||||
return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
|
||||
} else {
|
||||
|
||||
if(!this.checkDates(timeOfferEdit)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio");
|
||||
|
||||
}
|
||||
if(!this.checkTimes(timeOfferEdit)) {
|
||||
//Poner aqui mensaje de error
|
||||
return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM;
|
||||
result.rejectValue("finish","" ,"La hora de fin debe ser posterior a la de inicio");
|
||||
|
||||
}
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("timeOffer", timeOfferEdit);
|
||||
return TimeOfferController.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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,8 @@ 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
|
||||
finishOffer= Fin del intervalo
|
||||
name= Nombre del restaurante
|
||||
status= Estado de oferta
|
||||
myOffers= Ver mis Ofertas
|
||||
myOffers= Ver mis Ofertas
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@
|
|||
<th><fmt:message key="startDate"/></th>
|
||||
<th><fmt:message key="endDate"/></th>
|
||||
<th><fmt:message key="init"/></th>
|
||||
<th><fmt:message key="finish"/></th>
|
||||
<th><fmt:message key="finishOffer"/></th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<td><c:out value="${timeOffer.init}h"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><fmt:message key="finish"/></th>
|
||||
<th><fmt:message key="finishOffer"/></th>
|
||||
<td><c:out value="${timeOffer.finish}h"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
Loading…
Reference in a new issue