Skip to content

Commit

Permalink
arreglada validación de time
Browse files Browse the repository at this point in the history
  • Loading branch information
antmarcab4 committed Mar 28, 2020
1 parent 2762a56 commit fbf2f34
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,15 @@ public String processNewHairdressingForm(@PathVariable("petId") int petId, @Path
return "pets/createOrUpdateHairdressingForm";
}
else {
this.petService.saveHairdressing(hairdressing);
System.out.println("\n\n\n\n Estos son los hairdressings que hay: \n\n\n\n"+this.petService.findPetById(petId).getHairdressings()+"\n\n\n\n");
return "redirect:/owners/"+ ownerId;
if (hairdressingService.countHairdressingsByDateAndTime(hairdressing.getDate(), hairdressing.getTime()) != 0){
result.rejectValue("time", "", "This time isn't available, please select another");
return "pets/createOrUpdateHairdressingForm";

}else {
this.petService.saveHairdressing(hairdressing);
System.out.println("\n\n\n\n Estos son los hairdressings que hay: \n\n\n\n"+this.petService.findPetById(petId).getHairdressings()+"\n\n\n\n");
return "redirect:/owners/"+ ownerId;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
*/
package org.springframework.samples.petclinic.web;

import java.time.LocalDate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Hairdressing;
import org.springframework.samples.petclinic.model.Pet;
import org.springframework.samples.petclinic.model.TipoCuidado;
import org.springframework.samples.petclinic.repository.HairdressingRepository;
import org.springframework.samples.petclinic.service.HairdressingService;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
Expand All @@ -36,20 +40,41 @@ public class HairdressingValidator implements Validator {

private static final String REQUIRED = "required";

// @Autowired
// HairdressingService hairdressingService;

@Autowired
HairdressingService hairdressingService;
@Autowired
HairdressingRepository hairdressingRepo;
@Override
public void validate(Object obj, Errors errors) {
Hairdressing h = (Hairdressing) obj;




if (hairdressingService.countHairdressingsByDateAndTime(h.getDate(), h.getTime()) != 0){
errors.rejectValue("time", REQUIRED + "This time isn't available, please select another", REQUIRED + "This time isn't available, please select another");
//date
if (h.getDate() == null){
errors.rejectValue("date", REQUIRED, REQUIRED);
}else if(h.getDate().isBefore(LocalDate.now().plusDays(1))) {
errors.rejectValue("date", "The appointment has to be at least for tomorrow", "The appointment has to be at least for tomorrow");
}
//description
if (h.getDescription().isEmpty()){
errors.rejectValue("description", REQUIRED, REQUIRED);
}if (h.getDescription().length()>20){
errors.rejectValue("description", "Must not be longer than 20 characters", "Must not be longer than 20 characters");
}
//care type
if (h.getCuidado() == null){
errors.rejectValue("cuidado", REQUIRED, REQUIRED);
}else if(h.getCuidado() != TipoCuidado.ESTETICA && h.getCuidado() != TipoCuidado.PELUQUERIA) {
errors.rejectValue("cuidado", "Select a valid care type", "Select a valid care type");
}
System.out.println("\n\n\n\n··········Hora: " + h.getTime());
System.out.println("\n\n\n\n··········Fecha: " + h.getDate());
//time
if (h.getTime() == null){
errors.rejectValue("time", REQUIRED, REQUIRED);
}
// else if (hairdressingService.countHairdressingsByDateAndTime(h.getDate(), h.getTime()) != 0){
// errors.rejectValue("time", REQUIRED + "This time isn't available, please select another", REQUIRED + "This time isn't available, please select another");
// }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<th>Description</th>
<th>Tipo de cuidado</th>
</tr>
<c:forEach var="hairdressing" items="${hairdressing.pet.visits}">
<c:forEach var="hairdressing" items="${hairdressing.pet.hairdressings}">
<c:if test="${!hairdressing['new']}">
<tr>
<td><petclinic:localDate date="${hairdressing.date}" pattern="yyyy/MM/dd"/></td>
Expand Down

0 comments on commit fbf2f34

Please sign in to comment.