diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index abf0c8cd3..651272a81 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -46,7 +46,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers("/usuarios/new").permitAll() .antMatchers("/usuarios/**").hasAnyAuthority("usuario") - .antMatchers("/admin/**").hasAnyAuthority("admin") + .antMatchers("/administrators/**").hasAnyAuthority("admin") .antMatchers("/owners/**").hasAnyAuthority("owner", "admin") diff --git a/src/main/java/org/springframework/cheapy/model/Administrator.java b/src/main/java/org/springframework/cheapy/model/Administrator.java index 44a3ffdf6..0eba5746d 100644 --- a/src/main/java/org/springframework/cheapy/model/Administrator.java +++ b/src/main/java/org/springframework/cheapy/model/Administrator.java @@ -1,15 +1,29 @@ package org.springframework.cheapy.model; +import javax.persistence.CascadeType; import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; import javax.persistence.Table; @Entity @Table(name = "administrators") -public class Administrator extends User{ +public class Administrator extends BaseEntity{ /** * */ private static final long serialVersionUID = 1L; + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "username", referencedColumnName = "username") + private User usuar; + + public User getUsuar() { + return usuar; + } + + public void setUsuar(User usuar) { + this.usuar = usuar; + } } diff --git a/src/main/java/org/springframework/cheapy/repository/ClientRepository.java b/src/main/java/org/springframework/cheapy/repository/ClientRepository.java index 128db69ac..a796b3e0a 100644 --- a/src/main/java/org/springframework/cheapy/repository/ClientRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/ClientRepository.java @@ -1,6 +1,9 @@ package org.springframework.cheapy.repository; + import java.util.Optional; +import java.util.List; + import org.springframework.cheapy.model.Client; import org.springframework.data.jpa.repository.Query; @@ -16,6 +19,12 @@ public interface ClientRepository extends CrudRepository { Optional findById(Integer id); + // void save(Client client); + + @Query("SELECT client FROM Client client") + @Transactional(readOnly = true) + List findAllClient(); + } \ No newline at end of file diff --git a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java index 6f833665c..87b11c04d 100644 --- a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java @@ -1,5 +1,7 @@ package org.springframework.cheapy.repository; +import java.util.List; + import org.springframework.cheapy.model.Usuario; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; @@ -11,6 +13,10 @@ public interface UsuarioRepository extends Repository { @Transactional(readOnly = true) Usuario findByUsername(String username); + @Query("SELECT usuario FROM Usuario usuario") + @Transactional(readOnly = true) + List findAllUsuario(); + void save(Usuario usuario); } diff --git a/src/main/java/org/springframework/cheapy/service/ClientService.java b/src/main/java/org/springframework/cheapy/service/ClientService.java index c8404afb9..a92d25a75 100644 --- a/src/main/java/org/springframework/cheapy/service/ClientService.java +++ b/src/main/java/org/springframework/cheapy/service/ClientService.java @@ -1,5 +1,7 @@ package org.springframework.cheapy.service; +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.Client; import org.springframework.cheapy.repository.ClientRepository; @@ -26,8 +28,16 @@ public class ClientService { return this.clientRepository.findByUsername(username); } + @Transactional + public Client findByUsername(String username) throws DataAccessException { + 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 9fb6002a8..5c994342d 100644 --- a/src/main/java/org/springframework/cheapy/service/UsuarioService.java +++ b/src/main/java/org/springframework/cheapy/service/UsuarioService.java @@ -1,6 +1,8 @@ package org.springframework.cheapy.service; +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.Usuario; import org.springframework.cheapy.repository.UsuarioRepository; @@ -27,6 +29,16 @@ public class UsuarioService { String username = authentication.getName(); return this.usuarioRepository.findByUsername(username); } + + @Transactional + public Usuario findByUsername(String username) throws DataAccessException { + return this.usuarioRepository.findByUsername(username); + } + + @Transactional + public List findAllUsuario() throws DataAccessException { + return this.usuarioRepository.findAllUsuario(); + } @Transactional public void saveUsuario(final Usuario usuario) throws DataAccessException { diff --git a/src/main/java/org/springframework/cheapy/web/AdministratorController.java b/src/main/java/org/springframework/cheapy/web/AdministratorController.java new file mode 100644 index 000000000..d5e001f77 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/web/AdministratorController.java @@ -0,0 +1,92 @@ +package org.springframework.cheapy.web; + +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.cheapy.model.Client; +import org.springframework.cheapy.model.Usuario; +import org.springframework.cheapy.service.ClientService; +import org.springframework.cheapy.service.UsuarioService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; + +@Controller +public class AdministratorController { + + private static final String VIEWS_USUARIO_CREATE_OR_UPDATE_FORM = "usuarios/createOrUpdateUsuarioForm"; + + private final UsuarioService usuarioService; + private final ClientService clientService; + + public AdministratorController(final UsuarioService usuarioService, ClientService clientService) { + this.usuarioService = usuarioService; + this.clientService=clientService; + } + + @GetMapping("/administrators/usuarios") + public String processFindUsuariosForm(Map model) { + List usuarioLs = this.usuarioService.findAllUsuario(); + model.put("usuarioLs", usuarioLs); + return "usuarios/usuariosList"; + } + + @GetMapping("/administrators/clients") + public String processFindClientesForm(Map model) { + List clientLs = this.clientService.findAllClient(); + model.put("clientLs", clientLs); + return "clients/clientsList"; + } + @GetMapping("/administrators/usuarios/{username}") + public String processUsuarioShowForm(@PathVariable("username") String username, Map model) { + Usuario usuario = this.usuarioService.findByUsername(username); + model.put("usuario", usuario); + return "usuarios/usuariosShow"; + } + + @GetMapping("/administrators/clients/{username}") + public String processClientShowForm(@PathVariable("username") String username, Map model) { + Client client = this.clientService.findByUsername(username); + model.put("client", client); + return "clients/clientShow"; + } + + @GetMapping(value = "/administrators/usuarios/{username}/disable") + public String disableUsuario(@PathVariable("username") final String username, final ModelMap model) { + + Usuario usuario = this.usuarioService.findByUsername(username); + model.put("usuario", usuario); + return "usuarios/usuariosDisable"; + } + + + @PostMapping(value = "/administrators/usuarios/{username}/disable") + public String disableUsuarioForm(@PathVariable("username") final String username, final ModelMap model, final HttpServletRequest request) { + + Usuario usuario = this.usuarioService.findByUsername(username); + usuario.getUsuar().setEnabled(false); + this.usuarioService.saveUsuario(usuario); + return "redirect:/administrators/usuarios"; + } + + + @GetMapping(value = "/administrators/clients/{username}/disable") + public String disableClient(@PathVariable("username") final String username, final ModelMap model) { + + Client client = this.clientService.findByUsername(username); + model.put("client", client); + return "clients/clientDisable"; + } + @PostMapping(value = "/administrators/clients/{username}/disable") + public String disableClientForm(@PathVariable("username") final String username, final ModelMap model, final HttpServletRequest request) { + + Client client = this.clientService.findByUsername(username); + client.getUsuar().setEnabled(false); + this.clientService.saveClient(client); + return "redirect:/administrators/clients"; + } +} diff --git a/src/main/java/org/springframework/cheapy/web/UsuarioController.java b/src/main/java/org/springframework/cheapy/web/UsuarioController.java index 26991e812..8e6d965cc 100644 --- a/src/main/java/org/springframework/cheapy/web/UsuarioController.java +++ b/src/main/java/org/springframework/cheapy/web/UsuarioController.java @@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.PostMapping; @Controller public class UsuarioController { - private static final String VIEWS_USUARIO_CREATE_OR_UPDATE_FORM = "usuarios/createOrUpdateUsuariosForm"; + private static final String VIEWS_USUARIO_CREATE_OR_UPDATE_FORM = "usuarios/createOrUpdateUsuarioForm"; private final UsuarioService usuarioService; diff --git a/src/main/less/cheapy.less b/src/main/less/cheapy.less index 44e9d7e26..cbda84c10 100644 --- a/src/main/less/cheapy.less +++ b/src/main/less/cheapy.less @@ -216,9 +216,15 @@ img.img-responsive{ padding: 20px; } -.btn-home{ - display: table; - margin: 0 auto; +.btn-block { + display: block; + width: 25%; +} + +.btn-home { + display: flex; + justify-content: center; + align-items: center; } .btn-home button { @@ -227,7 +233,6 @@ img.img-responsive{ color: white; padding: 10px 24px; cursor: pointer; - width: 100%; display: block; } @@ -240,9 +245,12 @@ img.img-responsive{ background-color: rgb(40, 140, 215); } -.btn-home{ - display: table; - margin: 0 auto; + +.btn-home-max button { + padding: 20px; + margin-left:auto; + margin-right: auto; + margin-bottom: 20px; } .btn-create button { @@ -342,6 +350,13 @@ text-align: center; float:left; } +.btn-menu button { + margin-left:auto; + margin-right: auto; + margin-bottom: 20px; + margin-right: 20px; +} + .btns-edit{ display: table; margin: 0 auto; @@ -356,10 +371,6 @@ text-align: center; cursor: pointer; } -.btns-edit button:not(:last-child) { - border-bottom: none; -} - .btns-edit button:hover { background-color: rgb(40, 140, 215); @@ -518,6 +529,14 @@ text-align: center; color: rgb(29, 142, 226); } + .row-full{ + width: 100vw; + position: relative; + margin-left: -50vw; + height: 100px; + left: 50%; +} + .alert-success { .alert-variant(fade(@alert-success-bg, 70%); @alert-success-border; @alert-success-text); } diff --git a/src/main/less/responsive.less b/src/main/less/responsive.less index a8874e253..2f7a2c6bb 100644 --- a/src/main/less/responsive.less +++ b/src/main/less/responsive.less @@ -38,4 +38,13 @@ margin-bottom: 30px; } + .btn-home button { + background-color: rgb(0, 64, 128); + border: 1px solid rgb(0, 0, 160); + color: white; + padding: 10px 24px; + cursor: pointer; + width: 70%; + display: block; + } } diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index cfdb7d6aa..1074dcd4a 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -1,19 +1,20 @@ -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 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 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 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 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 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 VALUES ('pepe','usuario'); -INSERT INTO usuarios (id, nombre, apellidos, dni, direccion, telefono, email, username) VALUES (1, 'admin', 'admin', 'admin', 'C/admin', '000000000', 'admin@gmail.com','admin'); +INSERT INTO administrators (id, username) VALUES (1, 'admin'); + INSERT INTO usuarios (id, nombre, apellidos, dni, direccion, telefono, email, username) VALUES (2, 'Paco', 'Naranjo', '21154416G', 'C/Esperanza', '666973647', 'Paco@gmail.com','paco'); 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'); diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp index 398ba4d07..66ff86179 100644 --- a/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp @@ -67,11 +67,20 @@ - - - + + +
+ + + + + +
+
diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientsList.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientsList.jsp new file mode 100644 index 000000000..464b7a0ec --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/clients/clientsList.jsp @@ -0,0 +1,55 @@ +<%@ page session="false" trimDirectiveWhitespaces="true" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> +<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> + + + +

+ + +

No hay ningun Cliente.

+
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ +
+
+
+
diff --git a/src/main/webapp/WEB-INF/jsp/login.jsp b/src/main/webapp/WEB-INF/jsp/login.jsp index 5c2ecff60..81bd7c811 100644 --- a/src/main/webapp/WEB-INF/jsp/login.jsp +++ b/src/main/webapp/WEB-INF/jsp/login.jsp @@ -94,7 +94,7 @@ background-color: #56baed; border: none; color: white; - padding: 15px 80px; + padding: 15px; text-align: center; text-decoration: none; display: inline-block; @@ -110,6 +110,7 @@ -ms-transition: all 0.3s ease-in-out; -o-transition: all 0.3s ease-in-out; transition: all 0.3s ease-in-out; + width: 60%; } input[type=button]:hover, input[type=submit]:hover, input[type=reset]:hover { @@ -143,6 +144,7 @@ transition: all 0.5s ease-in-out; -webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px; + margin: 0 auto; } input[type=text]:focus { @@ -292,7 +294,9 @@ - +
+ +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - -
- - +
+ + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + +
+ +
+
+

No hay ninguna oferta por número de comensales creada.

- - - - - - - - - - - - - - - - - - - - -
- - - -
- - - - - - - - - -
- -
-
+
+ + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + +
+ +
+
+

@@ -108,47 +112,49 @@

No hay ninguna oferta por tiempo empleado en comer creada.

- - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - - - - - - - -
- -
-
+
+ + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + +
+ +
+
+

@@ -156,44 +162,46 @@

No hay ninguna oferta por franja horaria creada.

- - - - - - - - - - - - - - - - - - - - -
- - -
- - - - - - - - - -
- -
-
+
+ + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + +
+ +
+
+
diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp index 0b8f7da47..5373e4e7f 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -11,9 +11,11 @@

-

No hay ninguna oferta por plato específico activa.

+

No hay ninguna oferta por plato específico activa.

+ +
@@ -61,12 +63,16 @@
+
+

-

No hay ninguna oferta por número de comensales activa.

+

No hay ninguna oferta por número de comensales activa.

+ +
@@ -112,6 +118,8 @@
+
+

@@ -119,52 +127,56 @@

No hay ninguna oferta por tiempo empleado en comer activa.

- - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - -
- -
-
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+
+
+

@@ -172,51 +184,54 @@

No hay ninguna oferta por franja horaria activa.

- - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - -
- -
-
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+
+
diff --git a/src/main/webapp/WEB-INF/jsp/usuarios/createOrUpdateUsuariosForm.jsp b/src/main/webapp/WEB-INF/jsp/usuarios/createOrUpdateUsuarioForm.jsp similarity index 100% rename from src/main/webapp/WEB-INF/jsp/usuarios/createOrUpdateUsuariosForm.jsp rename to src/main/webapp/WEB-INF/jsp/usuarios/createOrUpdateUsuarioForm.jsp diff --git a/src/main/webapp/WEB-INF/jsp/usuarios/usuariosList.jsp b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosList.jsp new file mode 100644 index 000000000..297978c7e --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosList.jsp @@ -0,0 +1,57 @@ +<%@ page session="false" trimDirectiveWhitespaces="true" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> +<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> + + + +

+ + +

No hay ningun usuario.

+
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+ +
+
+
+
diff --git a/src/main/webapp/WEB-INF/jsp/usuarios/usuariosShow.jsp b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosShow.jsp index 4e5e6b962..2feff3623 100644 --- a/src/main/webapp/WEB-INF/jsp/usuarios/usuariosShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosShow.jsp @@ -56,6 +56,18 @@ Desactivar usuario + + +
+ + + + + +
+
diff --git a/src/main/webapp/WEB-INF/jsp/welcome.jsp b/src/main/webapp/WEB-INF/jsp/welcome.jsp index 43be3e422..e5a956229 100644 --- a/src/main/webapp/WEB-INF/jsp/welcome.jsp +++ b/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -9,38 +9,39 @@ <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> -

+

-
- +
+
+ +
+ + +
+ +
+
+ +
+
+ +
+ +
- - -
- -
-
- -
-
- -
- -
-
- +
- + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index 40f426e7e..97f1d6ced 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -39,6 +39,20 @@ Mis ofertas + + + + + Clientes + + + + + + + Usuarios + +