Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuevas clases para testear. #14

Merged
merged 1 commit into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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