From d504fecc1853459ab29e4017d161375ec8063020 Mon Sep 17 00:00:00 2001 From: Abraham Date: Mon, 12 Apr 2021 19:08:43 +0200 Subject: [PATCH] Todo funcional --- .../springframework/cheapy/model/Client.java | 1 + .../cheapy/model/Municipio.java | 2 +- .../springframework/cheapy/model/Usuario.java | 8 -- .../cheapy/service/AuthoritiesService.java | 5 ++ .../cheapy/service/ClientService.java | 3 - .../cheapy/service/UsuarioService.java | 9 -- .../cheapy/system/SingUpController.java | 87 +++++-------------- src/main/resources/db/mysql/data.sql | 28 ++---- .../WEB-INF/jsp/singup/singUpClient.jsp | 8 +- 9 files changed, 39 insertions(+), 112 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/model/Client.java b/src/main/java/org/springframework/cheapy/model/Client.java index ab52eb6f0..f55f91214 100644 --- a/src/main/java/org/springframework/cheapy/model/Client.java +++ b/src/main/java/org/springframework/cheapy/model/Client.java @@ -36,6 +36,7 @@ public class Client extends BaseEntity { private String address; @Enumerated(value = EnumType.STRING) + @NotNull private Municipio municipio; // Hora de apertura del local diff --git a/src/main/java/org/springframework/cheapy/model/Municipio.java b/src/main/java/org/springframework/cheapy/model/Municipio.java index f89afca92..95d1230d1 100644 --- a/src/main/java/org/springframework/cheapy/model/Municipio.java +++ b/src/main/java/org/springframework/cheapy/model/Municipio.java @@ -1,5 +1,5 @@ package org.springframework.cheapy.model; public enum Municipio { -sevilla,dosHermanas,carmona,bollullos,pilas,montellano,mairenaAljarafe,mairenaAlcor +sevilla,dos_hermanas,carmona,bollullos,pilas,montellano,mairena_aljarafe,mairena_alcor } diff --git a/src/main/java/org/springframework/cheapy/model/Usuario.java b/src/main/java/org/springframework/cheapy/model/Usuario.java index 83b7ab8d5..660faa88a 100644 --- a/src/main/java/org/springframework/cheapy/model/Usuario.java +++ b/src/main/java/org/springframework/cheapy/model/Usuario.java @@ -90,14 +90,6 @@ public class Usuario extends BaseEntity{ } - public User getUsuar() { - return usuar; - } - - public void setUsuar(User username) { - this.usuar = username; - } - } diff --git a/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java b/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java index 4c28f40ce..5ec186de2 100644 --- a/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java +++ b/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java @@ -15,7 +15,12 @@ */ package org.springframework.cheapy.service; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cheapy.model.Authorities; +import org.springframework.cheapy.repository.AuthoritiesRepository; +import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service public class AuthoritiesService { diff --git a/src/main/java/org/springframework/cheapy/service/ClientService.java b/src/main/java/org/springframework/cheapy/service/ClientService.java index 1b322720d..e65eec3a7 100644 --- a/src/main/java/org/springframework/cheapy/service/ClientService.java +++ b/src/main/java/org/springframework/cheapy/service/ClientService.java @@ -53,9 +53,6 @@ public class ClientService { return this.clientRepository.findByUsername(username); } - public void saveClient(final Client client) throws DataAccessException { - this.clientRepository.save(client); - } @Transactional public List findAllClient() throws DataAccessException { return this.clientRepository.findAllClient(); diff --git a/src/main/java/org/springframework/cheapy/service/UsuarioService.java b/src/main/java/org/springframework/cheapy/service/UsuarioService.java index d08e5cff6..efd60a87e 100644 --- a/src/main/java/org/springframework/cheapy/service/UsuarioService.java +++ b/src/main/java/org/springframework/cheapy/service/UsuarioService.java @@ -5,15 +5,6 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.Usuario; - -package org.springframework.cheapy.service; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cheapy.model.FoodOffer; -import org.springframework.cheapy.model.User; -import org.springframework.cheapy.model.Usuario; -import org.springframework.cheapy.repository.UserRepository; - import org.springframework.cheapy.repository.UsuarioRepository; import org.springframework.dao.DataAccessException; import org.springframework.security.core.Authentication; diff --git a/src/main/java/org/springframework/cheapy/system/SingUpController.java b/src/main/java/org/springframework/cheapy/system/SingUpController.java index 6ddc319ca..d07f727f6 100644 --- a/src/main/java/org/springframework/cheapy/system/SingUpController.java +++ b/src/main/java/org/springframework/cheapy/system/SingUpController.java @@ -3,6 +3,7 @@ package org.springframework.cheapy.system; import java.util.Collection; import java.util.Map; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; @@ -10,16 +11,15 @@ import org.springframework.cheapy.model.Authorities; import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.Code; import org.springframework.cheapy.model.Municipio; -import org.springframework.cheapy.model.Owner; import org.springframework.cheapy.model.User; import org.springframework.cheapy.model.Usuario; import org.springframework.cheapy.service.AuthoritiesService; import org.springframework.cheapy.service.ClientService; -import org.springframework.cheapy.service.OwnerService; 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; @@ -51,11 +51,21 @@ public class SingUpController { this.usuarioService = usuarioService; } + + @InitBinder public void setAllowedFields(WebDataBinder dataBinder) { dataBinder.setDisallowedFields("id"); } + + 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("/users/new") public String singUpUserForm(Map model) { @@ -106,9 +116,9 @@ public class SingUpController { } @PostMapping("/clients/new") - public String singUpClientForm(/*@Valid User user,*/ @Valid Client cliente, BindingResult result) { + public String singUpClientForm(/*@Valid User user,*/ @Valid Client cliente, final BindingResult result, final ModelMap model, + HttpServletRequest request) { Authorities auth=new Authorities(); - System.out.println(cliente.getCode().getCode()); String cod=cliente.getCode().getCode(); Code code=this.clientService.findCodeByCode(cod); User user= cliente.getUsuar(); @@ -116,13 +126,17 @@ public class SingUpController { cliente.setUsuar(user); auth.setUsername(user.getUsername()); auth.setAuthority("client"); + if(!this.checkTimes(cliente)) { + result.rejectValue("finish","" ,"La hora de cierre debe ser posterior a la hora de apertura"); + + } if (result.hasErrors()) { + model.put("municipio", Municipio.values()); + model.put("cliente", cliente); return "singup/singUpClient"; }else if(code.getActivo().equals(false)) { return "error"; }else { - //auth.setId(1); - //this.authoritiesService.saveAuthorities(auth); code.setActivo(false); this.clientService.saveCode(code); cliente.setCode(code); @@ -134,65 +148,4 @@ public class SingUpController { return "redirect:/"; } } -// @GetMapping("/owners/find") -// public String initFindForm(Map model) { -// model.put("owner", new Owner()); -// return "owners/findOwners"; -// } -// -// @GetMapping("/owners") -// public String processFindForm(Owner owner, BindingResult result, Map model) { -// -// // allow parameterless GET request for /owners to return all records -// if (owner.getLastName() == null) { -// owner.setLastName(""); // empty string signifies broadest possible search -// } -// -// // find owners by last name -// Collection results = this.ownerService.findByLastName(owner.getLastName()); -// if (results.isEmpty()) { -// // no owners found -// result.rejectValue("lastName", "notFound", "not found"); -// return "owners/findOwners"; -// } -// else if (results.size() == 1) { -// // 1 owner found -// owner = results.iterator().next(); -// return "redirect:/owners/" + owner.getId(); -// } -// else { -// // multiple owners found -// model.put("selections", results); -// return "owners/ownersList"; -// } -// } -// -// @GetMapping("/owners/{ownerId}/edit") -// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { -// Owner owner = this.ownerService.findOwnerById(ownerId); -// model.addAttribute(owner); -// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; -// } -// -// @PostMapping("/owners/{ownerId}/edit") -// public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, -// @PathVariable("ownerId") int ownerId) { -// if (result.hasErrors()) { -// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; -// } -// else { -// owner.setId(ownerId); -// this.ownerService.saveOwner(owner); -// return "redirect:/owners/{ownerId}"; -// } -// } -// @GetMapping("/owners/{ownerId}") -// public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { -// ModelAndView mav = new ModelAndView("owners/ownerDetails"); -// Owner owner = this.ownerService.findOwnerById(ownerId); -// -// mav.addObject(owner); -// return mav; -// } -// } diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index 1149edb98..97230b156 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -1,34 +1,22 @@ -INSERT INTO owners VALUES (1, 'Javi', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023'); -INSERT INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749'); -INSERT INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763'); -INSERT INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198'); -INSERT INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765'); -INSERT INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654'); -INSERT INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387'); -INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683'); -INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435'); -INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487'); - - -INSERT INTO users (dtype,username,password,enabled) VALUES ('User','admin','admin', TRUE ); +INSERT INTO users (username,password,enabled) VALUES ('admin','admin', TRUE ); INSERT INTO authorities (username,authority) VALUES ('admin','admin'); -INSERT INTO users (dtype,username,password,enabled) VALUES ('User','manoli','manoli', TRUE ); +INSERT INTO users (username,password,enabled) VALUES ('manoli','manoli', TRUE ); INSERT INTO authorities (username,authority) VALUES ('manoli','client'); -INSERT INTO users (dtype,username,password,enabled) VALUES ('User','david','david', TRUE ); +INSERT INTO users (username,password,enabled) VALUES ('david','david', TRUE ); INSERT INTO authorities (username,authority) VALUES ('david','client'); -INSERT INTO users (dtype,username,password,enabled) VALUES ('User','paco','paco', TRUE ); +INSERT INTO users (username,password,enabled) VALUES ('paco','paco', TRUE ); INSERT INTO authorities (username,authority) VALUES ('paco','usuario'); -INSERT INTO users (dtype,username,password,enabled) VALUES ('User','lolo','lolo', TRUE ); +INSERT INTO users (username,password,enabled) VALUES ('lolo','lolo', TRUE ); INSERT INTO authorities (username,authority) VALUES ('lolo','usuario'); -INSERT INTO users (dtype,username,password,enabled) VALUES ('User','pepe','pepe', TRUE ); +INSERT INTO users (username,password,enabled) VALUES ('pepe','pepe', TRUE ); INSERT INTO authorities (username,authority) VALUES ('pepe','usuario'); INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (1, 'admin', 'admin', 'C/admin', 'carmona', 'admin@gmail.com','admin'); INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (2, 'Paco', 'Naranjo', 'C/Esperanza', 'sevilla', 'Paco@gmail.com','paco'); -INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (3, 'Lolo', 'Lopez', 'C/Macarena', 'dosHermanas', 'Lolo@gmail.com','lolo'); +INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (3, 'Lolo', 'Lopez', 'C/Macarena', 'dos_hermanas', 'Lolo@gmail.com','lolo'); INSERT INTO usuarios (id, nombre, apellidos, direccion, municipio, email, username) VALUES (4, 'Pepe', 'Lopez', 'C/Macarena', 'carmona', 'Pepe@gmail.com','pepe'); INSERT INTO codes (id,code,activo) VALUES (1,'code1',FALSE); @@ -37,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, init, municipio, 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', 'dosHermanas','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); diff --git a/src/main/webapp/WEB-INF/jsp/singup/singUpClient.jsp b/src/main/webapp/WEB-INF/jsp/singup/singUpClient.jsp index 2582bf34f..124ed5701 100644 --- a/src/main/webapp/WEB-INF/jsp/singup/singUpClient.jsp +++ b/src/main/webapp/WEB-INF/jsp/singup/singUpClient.jsp @@ -274,10 +274,10 @@

- +

+ id="add-client-form">
@@ -291,9 +291,9 @@
- -