mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 15:55:49 +00:00
Merge pull request #86 from cheapy-ispp/026-Modificar-atributos-de-horas-de-cliente#84
Campos init y finish de client han pasado de String a LocalTime y algunas correcciones
This commit is contained in:
commit
09d721333c
8 changed files with 40 additions and 23 deletions
|
@ -1,5 +1,6 @@
|
|||
package org.springframework.cheapy.model;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
|
@ -9,8 +10,10 @@ import javax.persistence.OneToMany;
|
|||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Digits;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
@Entity
|
||||
@Table(name = "clients")
|
||||
|
@ -31,12 +34,14 @@ public class Client extends BaseEntity {
|
|||
private String address;
|
||||
|
||||
// Hora de apertura del local
|
||||
@NotBlank
|
||||
private String init;
|
||||
@DateTimeFormat(pattern = "HH:mm")
|
||||
@NotNull(message = "Debe introducir una hora de apertura")
|
||||
private LocalTime init;
|
||||
|
||||
// Hora de cierre del local
|
||||
@NotBlank
|
||||
private String finish;
|
||||
@DateTimeFormat(pattern = "HH:mm")
|
||||
@NotNull(message = "Debe introducir una hora de cierre")
|
||||
private LocalTime finish;
|
||||
|
||||
@NotEmpty
|
||||
@Digits(fraction = 0, integer = 10)
|
||||
|
@ -92,19 +97,19 @@ public class Client extends BaseEntity {
|
|||
this.address = address;
|
||||
}
|
||||
|
||||
public String getInit() {
|
||||
public LocalTime getInit() {
|
||||
return init;
|
||||
}
|
||||
|
||||
public void setInit(String init) {
|
||||
public void setInit(LocalTime init) {
|
||||
this.init = init;
|
||||
}
|
||||
|
||||
public String getFinish() {
|
||||
public LocalTime getFinish() {
|
||||
return finish;
|
||||
}
|
||||
|
||||
public void setFinish(String finish) {
|
||||
public void setFinish(LocalTime finish) {
|
||||
this.finish = finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.util.Map;
|
|||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import javax.websocket.server.PathParam;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -59,7 +58,13 @@ public class ClientController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
private boolean checkTimes(final Client client) {
|
||||
boolean res = false;
|
||||
if(client.getFinish()==null || client.getInit()==null || client.getFinish().isAfter(client.getInit())) {
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/clients/show")
|
||||
|
@ -91,7 +96,11 @@ public class ClientController {
|
|||
|
||||
|
||||
Client clienteSesion = this.clientService.getCurrentClient();
|
||||
|
||||
|
||||
if(!this.checkTimes(clientEdit)) {
|
||||
result.rejectValue("finish","" ,"La hora de cierre debe ser posterior a la hora de apertura");
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (result.hasErrors()) {
|
||||
|
|
|
@ -19,8 +19,8 @@ INSERT INTO usuarios (id, nombre, apellidos, dni, direccion, telefono, email, us
|
|||
INSERT INTO usuarios (id, nombre, apellidos, dni, direccion, telefono, email, username) VALUES (3, 'Lolo', 'Lopez', '25486596L', 'C/Macarena', '690670547' ,'Lolo@gmail.com','lolo');
|
||||
INSERT INTO usuarios (id, nombre, apellidos, dni, direccion, telefono, email, username) VALUES (4, 'Pepe', 'Lopez', '12456776V', 'C/Macarena', '690670547', 'Pepe@gmail.com','pepe');
|
||||
|
||||
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 (1,'bar manoli','manoli@gmail.com','C/Betis','10:00:00','22:00: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:00','22:00:00','608726190', 'description 2', 'code2', 'americana','david');
|
||||
|
||||
INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'FO-1', 'inactive', 1, 'macarrones', 15);
|
||||
INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'FO-2', 'active', 1, 'macarrones con tomate', 10);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<cheapy:layout pageName="clients">
|
||||
<h2 style="text-align:center;padding:5px">
|
||||
<c:if test="${client['new']}"><fmt:message key="new"/> </c:if> <fmt:message key="client"/>
|
||||
<fmt:message key="client"/>
|
||||
</h2>
|
||||
|
||||
<form:form modelAttribute="client" class="form-horizontal" id="add-client-form">
|
||||
|
|
|
@ -8,6 +8,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -58,8 +59,8 @@ class FoodOfferControllerTest {
|
|||
client1.setName("client1");
|
||||
client1.setEmail("client1");
|
||||
client1.setAddress("client1");
|
||||
client1.setInit("01:00");
|
||||
client1.setFinish("01:01");
|
||||
client1.setInit(LocalTime.of(01, 00));
|
||||
client1.setFinish(LocalTime.of(01, 01));
|
||||
client1.setTelephone("123456789");
|
||||
client1.setDescription("client1");
|
||||
client1.setCode("client1");
|
||||
|
|
|
@ -8,6 +8,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -57,8 +58,8 @@ class NuOfferControllerTest {
|
|||
client1.setName("client1");
|
||||
client1.setEmail("client1");
|
||||
client1.setAddress("client1");
|
||||
client1.setInit("01:00");
|
||||
client1.setFinish("01:01");
|
||||
client1.setInit(LocalTime.of(01, 00));
|
||||
client1.setFinish(LocalTime.of(01, 01));
|
||||
client1.setTelephone("123456789");
|
||||
client1.setDescription("client1");
|
||||
client1.setCode("client1");
|
||||
|
|
|
@ -8,6 +8,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -58,8 +59,8 @@ class SpeedOfferControllerTest {
|
|||
client1.setName("client1");
|
||||
client1.setEmail("client1");
|
||||
client1.setAddress("client1");
|
||||
client1.setInit("01:00");
|
||||
client1.setFinish("01:01");
|
||||
client1.setInit(LocalTime.of(01, 00));
|
||||
client1.setFinish(LocalTime.of(01, 01));
|
||||
client1.setTelephone("123456789");
|
||||
client1.setDescription("client1");
|
||||
client1.setCode("client1");
|
||||
|
|
|
@ -58,8 +58,8 @@ class TimeOfferControllerTest {
|
|||
client1.setName("client1");
|
||||
client1.setEmail("client1");
|
||||
client1.setAddress("client1");
|
||||
client1.setInit("01:00");
|
||||
client1.setFinish("01:01");
|
||||
client1.setInit(LocalTime.of(12, 00));
|
||||
client1.setFinish(LocalTime.of(01, 01));
|
||||
client1.setTelephone("123456789");
|
||||
client1.setDescription("client1");
|
||||
client1.setCode("client1");
|
||||
|
|
Loading…
Reference in a new issue