Fix errors issue#105
This commit is contained in:
abemorcardc 2021-04-12 21:19:40 +02:00 committed by GitHub
commit 40828b3007
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 42 additions and 44 deletions

View file

@ -3,7 +3,6 @@ package org.springframework.cheapy.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
@Entity
@Table(name = "authorities")

View file

@ -1,7 +1,6 @@
package org.springframework.cheapy.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

View file

@ -5,10 +5,6 @@ import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import org.springframework.boot.context.properties.bind.DefaultValue;
import net.bytebuddy.implementation.bind.annotation.Default;
@Entity
@Table(name = "users")
public class User {

View file

@ -9,7 +9,6 @@ import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Entity
@Table(name = "usuarios")

View file

@ -1,6 +1,5 @@
package org.springframework.cheapy.system;
import java.util.Collection;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@ -18,15 +17,12 @@ import org.springframework.cheapy.service.ClientService;
import org.springframework.cheapy.service.UserService;
import org.springframework.cheapy.service.UsuarioService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class SingUpController {

View file

@ -12,6 +12,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cheapy.model.Client;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.Municipio;
import org.springframework.cheapy.model.NuOffer;
import org.springframework.cheapy.model.SpeedOffer;
import org.springframework.cheapy.model.StatusOffer;
@ -84,7 +85,8 @@ public class ClientController {
public String updateClient( final ModelMap model, HttpServletRequest request) {
Client client = this.clientService.getCurrentClient();
model.put("municipio", Municipio.values());
model.addAttribute("client", client);
return ClientController.VIEWS_CREATE_OR_UPDATE_CLIENT;
@ -96,7 +98,6 @@ 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");
@ -105,6 +106,7 @@ public class ClientController {
if (result.hasErrors()) {
model.addAttribute("client", clientEdit);
model.put("municipio", Municipio.values());
return ClientController.VIEWS_CREATE_OR_UPDATE_CLIENT;
}
@ -161,7 +163,6 @@ public class ClientController {
public String showRestaurant(final ModelMap model, @PathVariable("clientId") Integer id) {
Client client = this.clientRepo.findById(id).get();
System.out.println(client.getDescription());
model.put("client", client);
return "clients/restaurantShow";
}

View file

@ -7,6 +7,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.cheapy.model.Municipio;
import org.springframework.cheapy.model.Usuario;
import org.springframework.cheapy.service.UsuarioService;
import org.springframework.stereotype.Controller;
@ -37,15 +38,21 @@ public class UsuarioController {
public String updateUsuario(final ModelMap model, HttpServletRequest request) {
Usuario usuario = this.usuarioService.getCurrentUsuario();
model.addAttribute("usuario", usuario);
model.put("municipio", Municipio.values());
return UsuarioController.VIEWS_USUARIO_CREATE_OR_UPDATE_FORM;
}
@PostMapping(value = "/usuarios/edit")
public String updateUsuario(@Valid final Usuario usuarioEdit, final BindingResult result,
final ModelMap model, HttpServletRequest request) {
if (result.hasErrors()) {
model.addAttribute("usuario", usuarioEdit);
model.put("municipio", Municipio.values());
return UsuarioController.VIEWS_USUARIO_CREATE_OR_UPDATE_FORM;
}
Usuario usuario = this.usuarioService.getCurrentUsuario();
BeanUtils.copyProperties(usuario, usuarioEdit, "nombre", "apellidos", "dni", "direccion", "telefono", "usuar");
BeanUtils.copyProperties(usuario, usuarioEdit, "nombre", "apellidos", "municipio", "direccion","email", "usuar");
usuarioEdit.getUsuar().setUsername(usuario.getNombre());
usuarioEdit.getUsuar().setEnabled(true);
this.usuarioService.saveUsuario(usuarioEdit);

View file

@ -25,7 +25,7 @@ INSERT INTO codes (id,code,activo) VALUES (3,'code3',TRUE);
INSERT INTO codes (id,code,activo) VALUES (4,'code4',TRUE);
INSERT INTO clients (id, name, email, address, municipio, init, finish, telephone, description, food, username, code) VALUES (1,'bar manoli','manoli@gmail.com','C/Betis', 'sevilla','10:00','22:00','608726190', 'description 1', 'ESPAÑOLA','manoli', 'code1');
INSERT INTO clients (id, name, email, address, municipio, init, finish, telephone, description, food, username, code) VALUES (2,'bar david','david@gmail.com','C/Sevilla', 'dosHermanas','09:30','22:00','608726190', 'description 2', 'americana','david', 'code2');
INSERT INTO clients (id, name, email, address, municipio, init, finish, telephone, description, food, username, code) VALUES (2,'bar david','david@gmail.com','C/Sevilla', 'dos_hermanas','09:30','22:00','608726190', 'description 2', 'americana','david', 'code2');
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);

View file

@ -35,6 +35,10 @@
<tr>
<th><fmt:message key="addressClient"/></th>
<td><c:out value="${client.address}"/> </td>
</tr><tr>
<tr>
<th><fmt:message key="municipioClient"/></th>
<td><c:out value="${client.municipio}"/> </td>
</tr><tr>
<th><fmt:message key="telephone"/></th>
<td><c:out value="${client.telephone}"/> </td>

View file

@ -15,7 +15,6 @@
<form:form modelAttribute="client" class="form-horizontal" id="add-client-form">
<div class="form-group has-feedback">
<form:hidden path="code"/>
<cheapy:inputField label="Contraseña" placeholder="Restaurante pepito" name="usuar.password"/>
@ -24,6 +23,14 @@
<cheapy:inputField label="Name" placeholder="Restaurante pepito" name="name"/>
<cheapy:inputField label="Email" placeholder="" name="email"/>
<cheapy:inputField label="Dirección" placeholder="" name="address"/>
<div class="form-group">
<label>Municipio: </label>
<select name="municipio">
<c:forEach items="${municipio}" var="entry">
<option value="${entry}">${entry}</option>
</c:forEach>
</select>
</div>
<cheapy:inputField label="telephone" placeholder="" name="telephone"/>
<cheapy:inputField label="description" placeholder="" name="description"/>
<cheapy:inputField label="food" placeholder="food" name="food"/>
@ -31,18 +38,10 @@
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="btn-mod">
<c:choose>
<c:when test="${client['new']}">
<button class="btn btn-default" type="submit" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true" style="padding: 5px"> </span>
Crear cliente</button>
</c:when>
<c:otherwise>
<button class="btn btn-default" type="submit" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true" style="padding: 5px"> </span>
Modificar</button>
</c:otherwise>
</c:choose>
</div>
</div>
</div>

View file

@ -16,27 +16,24 @@
<div class="form-group has-feedback">
<cheapy:inputField label="Nombre" name="nombre"/>
<cheapy:inputField label="Apellidos" name="apellidos"/>
<cheapy:inputField label="DNI" name="dni"/>
<div class="form-group">
<label>Municipio: </label>
<select name="municipio">
<c:forEach items="${municipio}" var="entry">
<option value="${entry}">${entry}</option>
</c:forEach>
</select>
</div>
<cheapy:inputField label="Direccion" name="direccion"/>
<cheapy:inputField label="Telefono" name="telefono"/>
<cheapy:inputField label="Email" name="email"/>
<cheapy:inputField label="Password" name="usuar.password"/>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="btn-mod">
<c:choose>
<c:when test="${usuario['new']}">
<button class="btn btn-default" type="submit" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true" style="padding: 5px"> </span>
Crear usuario</button>
</c:when>
<c:otherwise>
<button class="btn btn-default" type="submit" style="font-family: 'Lobster'; font-size: 20px;">
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true" style="padding: 5px"> </span>
Modificar</button>
</c:otherwise>
</c:choose>
</div>
</div>
</div>

View file

@ -22,17 +22,14 @@
<td><c:out value="${usuario.apellidos}"/></td>
</tr>
<tr>
<th><fmt:message key="dni"/></th>
<td><c:out value="${usuario.dni}"/></td>
<th><fmt:message key="municipio"/></th>
<td><c:out value="${usuario.municipio}"/></td>
</tr>
<tr>
<th><fmt:message key="addressUser"/></th>
<td><c:out value="${usuario.direccion}"/> </td>
</tr>
<tr>
<th><fmt:message key="telephone"/></th>
<td><c:out value="${usuario.telefono}"/></td>
</tr>
<tr>
<th><fmt:message key="email"/></th>
<td><c:out value="${usuario.email}"/></td>

View file

@ -18,6 +18,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.cheapy.configuration.SecurityConfiguration;
import org.springframework.cheapy.model.Client;
import org.springframework.cheapy.model.Code;
import org.springframework.cheapy.model.FoodOffer;
import org.springframework.cheapy.model.User;
import org.springframework.cheapy.service.ClientService;

View file

@ -18,6 +18,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.cheapy.configuration.SecurityConfiguration;
import org.springframework.cheapy.model.Client;
import org.springframework.cheapy.model.Code;
import org.springframework.cheapy.model.NuOffer;
import org.springframework.cheapy.model.User;
import org.springframework.cheapy.service.ClientService;

View file

@ -18,6 +18,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.cheapy.configuration.SecurityConfiguration;
import org.springframework.cheapy.model.Client;
import org.springframework.cheapy.model.Code;
import org.springframework.cheapy.model.SpeedOffer;
import org.springframework.cheapy.model.User;
import org.springframework.cheapy.service.ClientService;

View file

@ -18,6 +18,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.cheapy.configuration.SecurityConfiguration;
import org.springframework.cheapy.model.Client;
import org.springframework.cheapy.model.Code;
import org.springframework.cheapy.model.TimeOffer;
import org.springframework.cheapy.model.User;
import org.springframework.cheapy.service.ClientService;