From f2ebda490441d2f75540c9a7c6dcaeff74d98bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Franco=20S=C3=A1nchez?= <56022165+pabfrasan@users.noreply.github.com> Date: Wed, 7 Apr 2021 18:11:24 +0200 Subject: [PATCH 01/21] =?UTF-8?q?A=C3=B1adido=20info.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- info.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 info.yml diff --git a/info.yml b/info.yml new file mode 100644 index 000000000..da2d533d0 --- /dev/null +++ b/info.yml @@ -0,0 +1,14 @@ +project: + name: 'Cheapy' + owner: 'afternoon' + teamId: '19' + identities: + github: + url: 'https://github.com/cheapy-ispp/cheapy' + travis: + url: 'https://travis-ci.com/github/cheapy-ispp/cheapy' + members: + member: + name: 'Cheapy' + surname: 'Cheapy' + githubUsername: 'cheapy-ispp' \ No newline at end of file From fd402a182cd5a2e3d8a05d0b3f8c6e28d9db2f02 Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 8 Apr 2021 20:20:22 +0200 Subject: [PATCH 02/21] Filtros por tipo de oferta --- .../cheapy/web/FoodOfferController.java | 10 +++ .../cheapy/web/NuOfferController.java | 10 +++ .../cheapy/web/SpeedOfferController.java | 10 +++ .../cheapy/web/TimeOfferController.java | 10 +++ .../jsp/offers/food/foodOffersList.jsp | 85 +++++++++++++++++++ .../WEB-INF/jsp/offers/nu/nuOffersList.jsp | 82 ++++++++++++++++++ .../webapp/WEB-INF/jsp/offers/offersList.jsp | 25 ++++++ .../jsp/offers/speed/speedOffersList.jsp | 82 ++++++++++++++++++ .../jsp/offers/time/timeOffersList.jsp | 82 ++++++++++++++++++ 9 files changed, 396 insertions(+) create mode 100644 src/main/webapp/WEB-INF/jsp/offers/food/foodOffersList.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersList.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersList.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/offers/time/timeOffersList.jsp diff --git a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java index 2fef1c882..ce814e54e 100644 --- a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java @@ -2,6 +2,7 @@ package org.springframework.cheapy.web; import java.time.format.DateTimeFormatter; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -60,6 +61,15 @@ public class FoodOfferController { } return res; } + + @GetMapping("/offers/foodOfferList") + public String processFindForm(Map model) { + List foodOfferLs=this.foodOfferService.findActiveFoodOffer(); + model.put("foodOfferLs", foodOfferLs); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "offers/food/foodOffersList"; + + } @GetMapping("/offers/food/new") public String initCreationForm(Map model) { diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index a6c79db67..01a3f9cb0 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -2,6 +2,7 @@ package org.springframework.cheapy.web; import java.security.Principal; import java.time.format.DateTimeFormatter; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -79,6 +80,15 @@ public class NuOfferController { } return res; } + + @GetMapping("/offers/nuOfferList") + public String processFindForm(Map model) { + List foodOfferLs=this.nuOfferService.findActiveNuOffer(); + model.put("nuOfferLs", foodOfferLs); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "offers/nu/nuOffersList"; + + } @GetMapping("/offers/nu/new") public String initCreationForm(Map model) { diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java index ab42eacb6..bbf1372b6 100644 --- a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -1,6 +1,7 @@ package org.springframework.cheapy.web; import java.time.format.DateTimeFormatter; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -78,6 +79,15 @@ public class SpeedOfferController { } return res; } + + @GetMapping("/offers/speedOfferList") + public String processFindForm(Map model) { + List speedOfferLs=this.speedOfferService.findActiveSpeedOffer(); + model.put("speedOfferLs", speedOfferLs); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "offers/speed/speedOffersList"; + + } @GetMapping("/offers/speed/new") public String initCreationForm(Map model) { diff --git a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java index 2e584cdea..23480e3b7 100644 --- a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java @@ -1,6 +1,7 @@ package org.springframework.cheapy.web; import java.time.format.DateTimeFormatter; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -66,6 +67,15 @@ public class TimeOfferController { } return res; } + + @GetMapping("/offers/timeOfferList") + public String processFindForm(Map model) { + List timeOfferLs=this.timeOfferService.findActiveTimeOffer(); + model.put("timeOfferLs", timeOfferLs); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "offers/time/timeOffersList"; + + } @GetMapping("/offers/time/new") public String initCreationForm(Map model) { diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersList.jsp new file mode 100644 index 000000000..2ca621bf4 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersList.jsp @@ -0,0 +1,85 @@ +<%@ 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 ninguna oferta por plato específico activa.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+
+
+ +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersList.jsp new file mode 100644 index 000000000..d3a0725ce --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersList.jsp @@ -0,0 +1,82 @@ +<%@ 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 ninguna oferta por número de comensales activa.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+
+
+ +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp index c9fd5dbba..3f25a182b 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -8,6 +8,31 @@ + + + + + + + + + + + + + + + + +

diff --git a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersList.jsp new file mode 100644 index 000000000..01a638bd0 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersList.jsp @@ -0,0 +1,82 @@ +<%@ 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 ninguna oferta por tiempo empleado en comer activa.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+
+
+
diff --git a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersList.jsp new file mode 100644 index 000000000..f51d2a1f9 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersList.jsp @@ -0,0 +1,82 @@ +<%@ 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 ninguna oferta por franja horaria activa.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+
+
+ +
From ba2b2a4345b62a43d69e452b9346c9f1afa6988d Mon Sep 17 00:00:00 2001 From: Thiloparn <48439369+Thiloparn@users.noreply.github.com> Date: Thu, 8 Apr 2021 21:35:55 +0200 Subject: [PATCH 03/21] Ver, modificar y borrar de Usuario funcional. --- .../configuration/SecurityConfiguration.java | 1 + .../springframework/cheapy/model/User.java | 7 ++ .../springframework/cheapy/model/Usuario.java | 10 +-- .../cheapy/repository/NuOfferRepository.java | 1 - .../cheapy/repository/UsuarioRepository.java | 18 ++++ .../cheapy/service/UsuarioService.java | 35 ++++++++ .../cheapy/web/UsuarioController.java | 86 +++++++++++++++++++ src/main/resources/db/mysql/data.sql | 8 +- .../usuarios/createOrUpdateUsuariosForm.jsp | 45 ++++++++++ .../WEB-INF/jsp/usuarios/usuariosDisable.jsp | 26 ++++++ .../WEB-INF/jsp/usuarios/usuariosShow.jsp | 62 +++++++++++++ src/main/webapp/WEB-INF/jsp/welcome.jsp | 9 ++ 12 files changed, 298 insertions(+), 10 deletions(-) create mode 100644 src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java create mode 100644 src/main/java/org/springframework/cheapy/service/UsuarioService.java create mode 100644 src/main/java/org/springframework/cheapy/web/UsuarioController.java create mode 100644 src/main/webapp/WEB-INF/jsp/usuarios/createOrUpdateUsuariosForm.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/usuarios/usuariosDisable.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/usuarios/usuariosShow.jsp diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index 542e41f26..1155bc49e 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -40,6 +40,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers("/logout").authenticated() .antMatchers("/usuarios/new").permitAll() + .antMatchers("/usuarios/**").hasAnyAuthority("usuario") .antMatchers("/admin/**").hasAnyAuthority("admin") .antMatchers("/owners/**").hasAnyAuthority("owner", "admin") diff --git a/src/main/java/org/springframework/cheapy/model/User.java b/src/main/java/org/springframework/cheapy/model/User.java index e9c232562..81b834002 100644 --- a/src/main/java/org/springframework/cheapy/model/User.java +++ b/src/main/java/org/springframework/cheapy/model/User.java @@ -36,4 +36,11 @@ public class User{ this.password = password; } + public boolean getEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } } diff --git a/src/main/java/org/springframework/cheapy/model/Usuario.java b/src/main/java/org/springframework/cheapy/model/Usuario.java index 9079bc72e..6299ca2b5 100644 --- a/src/main/java/org/springframework/cheapy/model/Usuario.java +++ b/src/main/java/org/springframework/cheapy/model/Usuario.java @@ -12,9 +12,9 @@ import javax.validation.constraints.NotBlank; @Table(name = "usuarios") public class Usuario extends BaseEntity{ - /** nombre, apellidos, dni, direccion, telefono, email, username - * (id,nombre, apellidos, dni, direccion, telefono, email, usuar) - */ + /* nombre, apellidos, dni, direccion, telefono, email, username + (id,nombre, apellidos, dni, direccion, telefono, email, usuar)*/ + private static final long serialVersionUID = 1L; @NotBlank @@ -89,11 +89,11 @@ public class Usuario extends BaseEntity{ this.email = email; } - public User getUser() { + public User getUsuar() { return usuar; } - public void setUser(User username) { + public void setUsuar(User username) { this.usuar = username; } diff --git a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java index d895c5916..1dd0a9296 100644 --- a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java @@ -2,7 +2,6 @@ package org.springframework.cheapy.repository; import java.util.List; -import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.data.repository.Repository; diff --git a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java new file mode 100644 index 000000000..a472b2f17 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java @@ -0,0 +1,18 @@ +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; +import org.springframework.transaction.annotation.Transactional; + +public interface UsuarioRepository extends Repository { + + @Query("SELECT usuario FROM Usuario usuario WHERE username =:username") + @Transactional(readOnly = true) + Usuario findByUsername(String username); + + void save(Usuario usuario); + +} diff --git a/src/main/java/org/springframework/cheapy/service/UsuarioService.java b/src/main/java/org/springframework/cheapy/service/UsuarioService.java new file mode 100644 index 000000000..9fb6002a8 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/service/UsuarioService.java @@ -0,0 +1,35 @@ + +package org.springframework.cheapy.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cheapy.model.Usuario; +import org.springframework.cheapy.repository.UsuarioRepository; +import org.springframework.dao.DataAccessException; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class UsuarioService { + + private UsuarioRepository usuarioRepository; + + + @Autowired + public UsuarioService(final UsuarioRepository usuarioRepository) { + this.usuarioRepository = usuarioRepository; + } + + @Transactional + public Usuario getCurrentUsuario() throws DataAccessException { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + String username = authentication.getName(); + return this.usuarioRepository.findByUsername(username); + } + + @Transactional + public void saveUsuario(final Usuario usuario) throws DataAccessException { + this.usuarioRepository.save(usuario); + } +} diff --git a/src/main/java/org/springframework/cheapy/web/UsuarioController.java b/src/main/java/org/springframework/cheapy/web/UsuarioController.java new file mode 100644 index 000000000..08d6185f8 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/web/UsuarioController.java @@ -0,0 +1,86 @@ +package org.springframework.cheapy.web; + +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +import org.springframework.beans.BeanUtils; +import org.springframework.cheapy.model.SpeedOffer; +import org.springframework.cheapy.model.StatusOffer; +import org.springframework.cheapy.model.Usuario; +import org.springframework.cheapy.service.UsuarioService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; + +@Controller +public class UsuarioController { + + private static final String VIEWS_USUARIO_CREATE_OR_UPDATE_FORM = "usuarios/createOrUpdateUsuariosForm"; + + private final UsuarioService usuarioService; + + public UsuarioController(final UsuarioService usuarioService) { + this.usuarioService = usuarioService; + } + + @GetMapping("/usuarios/show") + public String processShowForm(Map model) { + Usuario usuario = this.usuarioService.getCurrentUsuario(); + model.put("usuario", usuario); + return "usuarios/usuariosShow"; + } + + @GetMapping(value = "/usuarios/edit") + public String updateUsuario(final ModelMap model, HttpServletRequest request) { + Usuario usuario = this.usuarioService.getCurrentUsuario(); + model.addAttribute("usuario", usuario); + 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) { + + Usuario usuario = this.usuarioService.getCurrentUsuario(); + BeanUtils.copyProperties(usuario, usuarioEdit, "nombre", "apellidos", "dni", "direccion", "telefono", "usuar"); + usuarioEdit.getUsuar().setUsername(usuario.getNombre()); + usuarioEdit.getUsuar().setEnabled(true); + this.usuarioService.saveUsuario(usuarioEdit); + return "redirect:/usuarios/show"; + } + + @GetMapping(value = "/usuarios/disable") + public String disableUsuario(final ModelMap model) { + + Usuario usuario = this.usuarioService.getCurrentUsuario(); + model.put("usuario", usuario); + return "usuarios/usuariosDisable"; + } + + @PostMapping(value = "/usuarios/disable") + public String disableUsuarioForm(final ModelMap model, final HttpServletRequest request) { + + Usuario usuario = this.usuarioService.getCurrentUsuario(); + usuario.getUsuar().setEnabled(false); + this.usuarioService.saveUsuario(usuario); + + try { + + request.logout(); + + } catch (ServletException e) { + + e.printStackTrace(); + + } + + return "redirect:/login"; + + } +} diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index c279eadf3..5f2794626 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -24,10 +24,10 @@ INSERT INTO authorities VALUES ('lolo','usuario'); INSERT INTO users (dtype,username,password,enabled) VALUES ('User','pepe','pepe', TRUE ); INSERT INTO authorities VALUES ('pepe','usuario'); -INSERT INTO usuarios VALUES (1, 'admin', 'admin', 'admin', 'C/admin', '000000000', 'admin@gmail.com','admin'); -INSERT INTO usuarios VALUES (2, 'Paco', 'Naranjo', '21154416G', 'C/Esperanza', '666973647', 'Paco@gmail.com','paco'); -INSERT INTO usuarios VALUES (3, 'Lolo', 'Lopez', '25486596L', 'C/Macarena', '690670547' ,'Lolo@gmail.com','lolo'); -INSERT INTO usuarios VALUES (4, 'Pepe', 'Lopez', '12456776V', 'C/Macarena', '690670547', 'Pepe@gmail.com','pepe'); +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 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'); 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'); diff --git a/src/main/webapp/WEB-INF/jsp/usuarios/createOrUpdateUsuariosForm.jsp b/src/main/webapp/WEB-INF/jsp/usuarios/createOrUpdateUsuariosForm.jsp new file mode 100644 index 000000000..e63363513 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/usuarios/createOrUpdateUsuariosForm.jsp @@ -0,0 +1,45 @@ +<%@ 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="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> + + + +

+ +

+ + +
+ + + + + + + +
+
+
+
+ + + + + + + + +
+
+
+
+ +
diff --git a/src/main/webapp/WEB-INF/jsp/usuarios/usuariosDisable.jsp b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosDisable.jsp new file mode 100644 index 000000000..a728c3f55 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosDisable.jsp @@ -0,0 +1,26 @@ +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> + + + + +

¿Está seguro de que quiere eliminar su cuenta?

+ + + +
+ + +
+
+ + +
+
diff --git a/src/main/webapp/WEB-INF/jsp/usuarios/usuariosShow.jsp b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosShow.jsp new file mode 100644 index 000000000..4e5e6b962 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosShow.jsp @@ -0,0 +1,62 @@ +<%@ 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" %> + + + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + + + +
+
+
+ + +
diff --git a/src/main/webapp/WEB-INF/jsp/welcome.jsp b/src/main/webapp/WEB-INF/jsp/welcome.jsp index a2622ed5a..37142a352 100644 --- a/src/main/webapp/WEB-INF/jsp/welcome.jsp +++ b/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -33,6 +33,15 @@ + + + + +
+ +
From 44d03596b26caf8a847f3f2143e26d466655a975 Mon Sep 17 00:00:00 2001 From: abemorcardc Date: Fri, 9 Apr 2021 00:15:15 +0200 Subject: [PATCH 04/21] =?UTF-8?q?A=C3=B1adida=20funcionalidad=20de=20ver,?= =?UTF-8?q?=20modificar=20y=20eliminar=20Cliente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/SecurityConfiguration.java | 5 +- .../springframework/cheapy/model/Client.java | 1 - .../springframework/cheapy/model/User.java | 8 ++ .../cheapy/repository/ClientRepository.java | 6 +- .../cheapy/service/ClientService.java | 4 + .../cheapy/web/ClientController.java | 115 ++++++++++++++++++ .../cheapy/web/OfertaController.java | 3 - .../WEB-INF/jsp/clients/clientDisable.jsp | 25 ++++ .../webapp/WEB-INF/jsp/clients/clientShow.jsp | 78 ++++++++++++ .../jsp/clients/createOrUpdateClientForm.jsp | 51 ++++++++ src/main/webapp/WEB-INF/jsp/welcome.jsp | 5 + 11 files changed, 294 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/springframework/cheapy/web/ClientController.java create mode 100644 src/main/webapp/WEB-INF/jsp/clients/clientDisable.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp create mode 100644 src/main/webapp/WEB-INF/jsp/clients/createOrUpdateClientForm.jsp diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index 542e41f26..25364f7b0 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -35,6 +35,10 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { http.authorizeRequests().antMatchers("/resources/**", "/webjars/**", "/h2-console/**").permitAll() .antMatchers(HttpMethod.GET, "/", "/oups").permitAll() .antMatchers("/users/new").permitAll() + + .antMatchers("/clients/new").permitAll() + .antMatchers("/clients/edit").hasAnyAuthority("client") + .antMatchers("/clients/disable").hasAnyAuthority("client") .antMatchers("/login/**").anonymous() .antMatchers("/logout").authenticated() @@ -48,7 +52,6 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers("/offers/**/new").hasAnyAuthority("admin", "client") .antMatchers("/offers/**/activate").hasAnyAuthority("admin","client") - .antMatchers("/clients/new").permitAll() .antMatchers("/offers").permitAll() .antMatchers("/offersCreate").hasAuthority("client") diff --git a/src/main/java/org/springframework/cheapy/model/Client.java b/src/main/java/org/springframework/cheapy/model/Client.java index e3f939728..2981c9d98 100644 --- a/src/main/java/org/springframework/cheapy/model/Client.java +++ b/src/main/java/org/springframework/cheapy/model/Client.java @@ -1,7 +1,6 @@ package org.springframework.cheapy.model; import java.util.List; -import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Entity; diff --git a/src/main/java/org/springframework/cheapy/model/User.java b/src/main/java/org/springframework/cheapy/model/User.java index e9c232562..4ef2dec13 100644 --- a/src/main/java/org/springframework/cheapy/model/User.java +++ b/src/main/java/org/springframework/cheapy/model/User.java @@ -36,4 +36,12 @@ public class User{ this.password = password; } + public boolean getEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + } diff --git a/src/main/java/org/springframework/cheapy/repository/ClientRepository.java b/src/main/java/org/springframework/cheapy/repository/ClientRepository.java index 1e04f6f3a..54c696f00 100644 --- a/src/main/java/org/springframework/cheapy/repository/ClientRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/ClientRepository.java @@ -2,13 +2,15 @@ package org.springframework.cheapy.repository; import org.springframework.cheapy.model.Client; import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.Repository; import org.springframework.transaction.annotation.Transactional; -public interface ClientRepository extends CrudRepository { +public interface ClientRepository extends Repository { @Query("SELECT client FROM Client client WHERE username =:username") @Transactional(readOnly = true) Client findByUsername(String username); + void save(Client client); + } diff --git a/src/main/java/org/springframework/cheapy/service/ClientService.java b/src/main/java/org/springframework/cheapy/service/ClientService.java index d65649680..c8404afb9 100644 --- a/src/main/java/org/springframework/cheapy/service/ClientService.java +++ b/src/main/java/org/springframework/cheapy/service/ClientService.java @@ -26,4 +26,8 @@ public class ClientService { return this.clientRepository.findByUsername(username); } + public void saveClient(final Client client) throws DataAccessException { + this.clientRepository.save(client); + } + } diff --git a/src/main/java/org/springframework/cheapy/web/ClientController.java b/src/main/java/org/springframework/cheapy/web/ClientController.java new file mode 100644 index 000000000..47ba8a918 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/web/ClientController.java @@ -0,0 +1,115 @@ + +package org.springframework.cheapy.web; + +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +import org.springframework.beans.BeanUtils; +import org.springframework.cheapy.model.Client; +import org.springframework.cheapy.model.FoodOffer; +import org.springframework.cheapy.service.ClientService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; + +@Controller +public class ClientController { + + private static final String VIEWS_CREATE_OR_UPDATE_CLIENT = "clients/createOrUpdateClientForm"; + + private final ClientService clientService; + + public ClientController(final ClientService clientService) { + this.clientService = clientService; + } + + + + private boolean checkDates(final FoodOffer foodOffer) { + boolean res = false; + if(foodOffer.getEnd()==null || foodOffer.getStart()==null || foodOffer.getEnd().isAfter(foodOffer.getStart())) { + res = true; + } + return res; + } + + + + + @GetMapping("/clients/show") + public String processShowForm(Map model) { + + Client client = this.clientService.getCurrentClient(); + + + model.put("client", client); + return "clients/clientShow"; + + + + } + + @GetMapping(value = "/clients/edit") + public String updateClient( final ModelMap model, HttpServletRequest request) { + + Client client = this.clientService.getCurrentClient(); + + model.addAttribute("client", client); + + return ClientController.VIEWS_CREATE_OR_UPDATE_CLIENT; + } + + @PostMapping(value = "/clients/edit") + public String updateClient(@Valid final Client clientEdit, final BindingResult result, + final ModelMap model, HttpServletRequest request) { + + + Client clienteSesion = this.clientService.getCurrentClient(); + + + + if (result.hasErrors()) { + model.addAttribute("client", clientEdit); + return ClientController.VIEWS_CREATE_OR_UPDATE_CLIENT; + } + + BeanUtils.copyProperties(clienteSesion, clientEdit, "name", "email", "address","init", "finish","telephone", "description","food","usuar"); + clientEdit.getUsuar().setUsername(clienteSesion.getUsuar().getUsername()); + clientEdit.getUsuar().setEnabled(true); + this.clientService.saveClient(clientEdit); + return "redirect:/clients/show"; + + } + + @GetMapping(value = "/clients/disable") + public String disableClient(final ModelMap model) { + + Client client = this.clientService.getCurrentClient(); + model.put("client", client); + return "/clients/clientDisable"; + } + + @PostMapping(value = "/clients/disable") + public String disableClientForm(final ModelMap model, HttpServletRequest request) { + + + Client client = this.clientService.getCurrentClient(); + + client.getUsuar().setEnabled(false); + + this.clientService.saveClient(client); + + try { + request.logout(); + } catch (ServletException e) { + + } + return "redirect:/login"; + + } +} diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index 60567c491..996773042 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -13,9 +13,6 @@ import org.springframework.cheapy.service.FoodOfferService; import org.springframework.cheapy.service.NuOfferService; import org.springframework.cheapy.service.SpeedOfferService; import org.springframework.cheapy.service.TimeOfferService; -import org.springframework.security.authentication.AnonymousAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientDisable.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientDisable.jsp new file mode 100644 index 000000000..5961d075c --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/clients/clientDisable.jsp @@ -0,0 +1,25 @@ +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> + + + + +

¿Está seguro de que quiere eliminar su cuenta?

+ + + +
+ +
+
+ +
+ +
diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp new file mode 100644 index 000000000..398ba4d07 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp @@ -0,0 +1,78 @@ +<%@ 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" %> + + + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + + + + + + + + +
+
+
+ + +
diff --git a/src/main/webapp/WEB-INF/jsp/clients/createOrUpdateClientForm.jsp b/src/main/webapp/WEB-INF/jsp/clients/createOrUpdateClientForm.jsp new file mode 100644 index 000000000..bd21204d0 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/clients/createOrUpdateClientForm.jsp @@ -0,0 +1,51 @@ +<%@ 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="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> + + + +

+ +

+ + +
+ + + + + + + + + + + + + +
+
+
+
+ + + + + + + + +
+
+
+
+ +
diff --git a/src/main/webapp/WEB-INF/jsp/welcome.jsp b/src/main/webapp/WEB-INF/jsp/welcome.jsp index a2622ed5a..c5bc812e3 100644 --- a/src/main/webapp/WEB-INF/jsp/welcome.jsp +++ b/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -33,6 +33,11 @@ +
+ +
From bc181eafca7067ce3fa15a1fb47ad922b6f9ecfc Mon Sep 17 00:00:00 2001 From: abemorcardc Date: Fri, 9 Apr 2021 17:28:39 +0200 Subject: [PATCH 05/21] =?UTF-8?q?A=C3=B1adida=20la=20eliminaci=C3=B3n=20de?= =?UTF-8?q?=20las=20ofertas=20del=20cliente=20que=20se=20borre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cheapy/web/ClientController.java | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/web/ClientController.java b/src/main/java/org/springframework/cheapy/web/ClientController.java index 47ba8a918..3cc9138b3 100644 --- a/src/main/java/org/springframework/cheapy/web/ClientController.java +++ b/src/main/java/org/springframework/cheapy/web/ClientController.java @@ -1,6 +1,7 @@ package org.springframework.cheapy.web; +import java.util.List; import java.util.Map; import javax.servlet.ServletException; @@ -10,7 +11,15 @@ import javax.validation.Valid; import org.springframework.beans.BeanUtils; import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.FoodOffer; +import org.springframework.cheapy.model.NuOffer; +import org.springframework.cheapy.model.SpeedOffer; +import org.springframework.cheapy.model.StatusOffer; +import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.service.ClientService; +import org.springframework.cheapy.service.FoodOfferService; +import org.springframework.cheapy.service.NuOfferService; +import org.springframework.cheapy.service.SpeedOfferService; +import org.springframework.cheapy.service.TimeOfferService; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; @@ -23,22 +32,27 @@ public class ClientController { private static final String VIEWS_CREATE_OR_UPDATE_CLIENT = "clients/createOrUpdateClientForm"; private final ClientService clientService; + + private final FoodOfferService foodOfferService; + + private final SpeedOfferService speedOfferService; + + private final NuOfferService nuOfferService; + + private final TimeOfferService timeOfferService; + - public ClientController(final ClientService clientService) { + public ClientController(final ClientService clientService, FoodOfferService foodOfferService, + SpeedOfferService speedOfferService, NuOfferService nuOfferService, TimeOfferService timeOfferService) { this.clientService = clientService; + this.foodOfferService=foodOfferService; + this.speedOfferService=speedOfferService; + this.nuOfferService=nuOfferService; + this.timeOfferService=timeOfferService; } - private boolean checkDates(final FoodOffer foodOffer) { - boolean res = false; - if(foodOffer.getEnd()==null || foodOffer.getStart()==null || foodOffer.getEnd().isAfter(foodOffer.getStart())) { - res = true; - } - return res; - } - - @GetMapping("/clients/show") @@ -100,8 +114,23 @@ public class ClientController { Client client = this.clientService.getCurrentClient(); + + + List foodOffers=this.foodOfferService.findFoodOfferByUserId(client.getId()); + List speedOffers=this.speedOfferService.findSpeedOfferByUserId(client.getId()); + List nuOffers=this.nuOfferService.findNuOfferByUserId(client.getId()); + List timeOffers=this.timeOfferService.findTimeOfferByUserId(client.getId()); + + foodOffers.stream().forEach(f->f.setStatus(StatusOffer.inactive)); + + speedOffers.stream().forEach(s->s.setStatus(StatusOffer.inactive)); + + nuOffers.stream().forEach(n->n.setStatus(StatusOffer.inactive)); + + timeOffers.stream().forEach(t->t.setStatus(StatusOffer.inactive)); + + client.getUsuar().setEnabled(false); - this.clientService.saveClient(client); try { From 4571c4717845b6094e71f82393022349f0b62e75 Mon Sep 17 00:00:00 2001 From: Antonio Vidal Date: Fri, 9 Apr 2021 17:40:45 +0200 Subject: [PATCH 06/21] Retirados los imports innecesarios y algunas clases que se han ido arrastrando. --- .../ExceptionHandlerConfiguration.java | 5 - .../configuration/SecurityConfiguration.java | 1 + .../springframework/cheapy/model/Client.java | 1 - .../springframework/cheapy/model/Owner.java | 69 -------- .../cheapy/model/package-info.java | 1 - .../cheapy/repository/OwnerRepository.java | 65 ------- .../repository/SpeedOfferRepository.java | 1 - .../cheapy/repository/UsuarioRepository.java | 2 - .../cheapy/service/AuthoritiesService.java | 9 - .../cheapy/service/OwnerService.java | 34 ---- .../cheapy/service/ReviewService.java | 3 - .../cheapy/service/SpeedOfferService.java | 1 - .../cheapy/web/OfertaController.java | 3 - .../cheapy/web/OwnerController.java | 118 ------------- .../cheapy/web/UsuarioController.java | 3 - src/main/resources/db/mysql/data.sql | 11 -- src/main/resources/db/mysql/schema.sql | 9 - .../integration/CheapyIntegrationTests.java | 2 - .../cheapy/web/OwnerControllerTests.java | 162 ------------------ 19 files changed, 1 insertion(+), 499 deletions(-) delete mode 100644 src/main/java/org/springframework/cheapy/model/Owner.java delete mode 100644 src/main/java/org/springframework/cheapy/model/package-info.java delete mode 100644 src/main/java/org/springframework/cheapy/repository/OwnerRepository.java delete mode 100644 src/main/java/org/springframework/cheapy/service/OwnerService.java delete mode 100644 src/main/java/org/springframework/cheapy/web/OwnerController.java delete mode 100644 src/test/java/org/springframework/cheapy/web/OwnerControllerTests.java diff --git a/src/main/java/org/springframework/cheapy/configuration/ExceptionHandlerConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/ExceptionHandlerConfiguration.java index e578e2a7e..fd8a8cf8c 100644 --- a/src/main/java/org/springframework/cheapy/configuration/ExceptionHandlerConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/ExceptionHandlerConfiguration.java @@ -1,7 +1,5 @@ package org.springframework.cheapy.configuration; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import javax.servlet.http.HttpServletRequest; @@ -14,9 +12,6 @@ import javax.servlet.http.HttpServletRequest; @ControllerAdvice public class ExceptionHandlerConfiguration { - @Autowired - private BasicErrorController errorController; - // add any exceptions/validations/binding problems @ExceptionHandler(Exception.class) public String defaultErrorHandler(HttpServletRequest request, Exception ex) { diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index 1155bc49e..8b7fff0aa 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -21,6 +21,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; */ +@SuppressWarnings("deprecation") @Configuration @EnableWebSecurity public class SecurityConfiguration extends WebSecurityConfigurerAdapter { diff --git a/src/main/java/org/springframework/cheapy/model/Client.java b/src/main/java/org/springframework/cheapy/model/Client.java index e3f939728..2981c9d98 100644 --- a/src/main/java/org/springframework/cheapy/model/Client.java +++ b/src/main/java/org/springframework/cheapy/model/Client.java @@ -1,7 +1,6 @@ package org.springframework.cheapy.model; import java.util.List; -import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Entity; diff --git a/src/main/java/org/springframework/cheapy/model/Owner.java b/src/main/java/org/springframework/cheapy/model/Owner.java deleted file mode 100644 index 7a04f3434..000000000 --- a/src/main/java/org/springframework/cheapy/model/Owner.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.springframework.cheapy.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; -import javax.validation.constraints.Digits; -import javax.validation.constraints.NotEmpty; - -import org.springframework.core.style.ToStringCreator; - -@Entity -@Table(name = "owners") -public class Owner extends Person { - - /** - * - */ - private static final long serialVersionUID = 1L; - - @Column(name = "address") - @NotEmpty - private String address; - - @Column(name = "city") - @NotEmpty - private String city; - - @Column(name = "telephone") - @NotEmpty - @Digits(fraction = 0, integer = 10) - private String telephone; - - - public String getAddress() { - return this.address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getCity() { - return this.city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getTelephone() { - return this.telephone; - } - - public void setTelephone(String telephone) { - this.telephone = telephone; - } - - - - @Override - public String toString() { - return new ToStringCreator(this) - - .append("id", this.getId()).append("new", this.isNew()).append("lastName", this.getLastName()) - .append("firstName", this.getFirstName()).append("address", this.address).append("city", this.city) - .append("telephone", this.telephone).toString(); - } - -} diff --git a/src/main/java/org/springframework/cheapy/model/package-info.java b/src/main/java/org/springframework/cheapy/model/package-info.java deleted file mode 100644 index 1bc54373f..000000000 --- a/src/main/java/org/springframework/cheapy/model/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package org.springframework.cheapy.model; diff --git a/src/main/java/org/springframework/cheapy/repository/OwnerRepository.java b/src/main/java/org/springframework/cheapy/repository/OwnerRepository.java deleted file mode 100644 index 67c4d6a9a..000000000 --- a/src/main/java/org/springframework/cheapy/repository/OwnerRepository.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.cheapy.repository; - -import java.util.Collection; - -import org.springframework.cheapy.model.Owner; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.Repository; -import org.springframework.data.repository.query.Param; -import org.springframework.transaction.annotation.Transactional; - -/** - * Repository class for Owner domain objects All method names are compliant - * with Spring Data naming conventions so this interface can easily be extended for Spring - * Data. See: - * https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation - * - * @author Ken Krebs - * @author Juergen Hoeller - * @author Sam Brannen - * @author Michael Isvy - */ -public interface OwnerRepository extends Repository { - - /** - * Retrieve {@link Owner}s from the data store by last name, returning all owners - * whose last name starts with the given name. - * @param lastName Value to search for - * @return a Collection of matching {@link Owner}s (or an empty Collection if none - * found) - */ - @Query("SELECT DISTINCT owner FROM Owner owner WHERE owner.lastName LIKE :lastName%") - @Transactional(readOnly = true) - Collection findByLastName(@Param("lastName") String lastName); - - /** - * Retrieve an {@link Owner} from the data store by id. - * @param id the id to search for - * @return the {@link Owner} if found - */ - @Query("SELECT owner FROM Owner owner WHERE id =:id") - @Transactional(readOnly = true) - Owner findById(@Param("id") Integer id); - - /** - * Save an {@link Owner} to the data store, either inserting or updating it. - * @param owner the {@link Owner} to save - */ - void save(Owner owner); - -} diff --git a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java index 4c7465368..79eedf517 100644 --- a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java @@ -2,7 +2,6 @@ package org.springframework.cheapy.repository; import java.util.List; -import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.data.jpa.repository.Query; diff --git a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java index a472b2f17..6f833665c 100644 --- a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java @@ -1,7 +1,5 @@ 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; diff --git a/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java b/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java index 7d0f8d7a8..9e91ce3b2 100644 --- a/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java +++ b/src/main/java/org/springframework/cheapy/service/AuthoritiesService.java @@ -15,16 +15,7 @@ */ package org.springframework.cheapy.service; - -import java.util.Optional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataAccessException; -import org.springframework.cheapy.model.Authorities; -import org.springframework.cheapy.model.User; -import org.springframework.cheapy.repository.AuthoritiesRepository; 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/OwnerService.java b/src/main/java/org/springframework/cheapy/service/OwnerService.java deleted file mode 100644 index da5559f37..000000000 --- a/src/main/java/org/springframework/cheapy/service/OwnerService.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.springframework.cheapy.service; - -import java.util.Collection; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cheapy.model.Owner; -import org.springframework.cheapy.repository.OwnerRepository; -import org.springframework.dao.DataAccessException; -import org.springframework.stereotype.Service; - -@Service -public class OwnerService { - private OwnerRepository ownerRepository; - - - @Autowired - public OwnerService(final OwnerRepository ownerRepository) { - this.ownerRepository = ownerRepository; - } - - public Owner findOwnerById(final int id) { - return this.ownerRepository.findById(id); - } - - public Collection findByLastName(final String lastname) { // - return this.ownerRepository.findByLastName(lastname); - - } - - public void saveOwner(final Owner owner) throws DataAccessException { // - this.ownerRepository.save(owner); - - } -} diff --git a/src/main/java/org/springframework/cheapy/service/ReviewService.java b/src/main/java/org/springframework/cheapy/service/ReviewService.java index 2b7bc9301..d07bf7e33 100644 --- a/src/main/java/org/springframework/cheapy/service/ReviewService.java +++ b/src/main/java/org/springframework/cheapy/service/ReviewService.java @@ -4,10 +4,7 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.Review; -import org.springframework.cheapy.model.StatusOffer; -import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.repository.ReviewRepository; -import org.springframework.cheapy.repository.TimeOfferRepository; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java index 384ec046c..2784446b9 100644 --- a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java @@ -3,7 +3,6 @@ package org.springframework.cheapy.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.repository.SpeedOfferRepository; diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index 60567c491..996773042 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -13,9 +13,6 @@ import org.springframework.cheapy.service.FoodOfferService; import org.springframework.cheapy.service.NuOfferService; import org.springframework.cheapy.service.SpeedOfferService; import org.springframework.cheapy.service.TimeOfferService; -import org.springframework.security.authentication.AnonymousAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; diff --git a/src/main/java/org/springframework/cheapy/web/OwnerController.java b/src/main/java/org/springframework/cheapy/web/OwnerController.java deleted file mode 100644 index 229693415..000000000 --- a/src/main/java/org/springframework/cheapy/web/OwnerController.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.springframework.cheapy.web; - -import java.util.Collection; -import java.util.Map; - -import javax.validation.Valid; - -import org.springframework.cheapy.model.Owner; -import org.springframework.cheapy.service.OwnerService; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -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 OwnerController { - - private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; - - private final OwnerService ownerService; - - - - public OwnerController(final OwnerService ownerService) { - this.ownerService = ownerService; - - } - - @InitBinder - public void setAllowedFields(WebDataBinder dataBinder) { - dataBinder.setDisallowedFields("id"); - } - - @GetMapping("/owners/new") - public String initCreationForm(Map model) { - Owner owner = new Owner(); - model.put("owner", owner); - return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; - } - - @PostMapping("/owners/new") - public String processCreationForm(@Valid Owner owner, BindingResult result) { - if (result.hasErrors()) { - return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; - } - else { - this.ownerService.saveOwner(owner); - return "redirect:/owners/" + owner.getId(); - } - } - - @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/java/org/springframework/cheapy/web/UsuarioController.java b/src/main/java/org/springframework/cheapy/web/UsuarioController.java index 08d6185f8..26991e812 100644 --- a/src/main/java/org/springframework/cheapy/web/UsuarioController.java +++ b/src/main/java/org/springframework/cheapy/web/UsuarioController.java @@ -7,15 +7,12 @@ import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import org.springframework.beans.BeanUtils; -import org.springframework.cheapy.model.SpeedOffer; -import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.Usuario; import org.springframework.cheapy.service.UsuarioService; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @Controller diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index 5f2794626..cfdb7d6aa 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -1,14 +1,3 @@ -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 authorities VALUES ('admin','admin'); diff --git a/src/main/resources/db/mysql/schema.sql b/src/main/resources/db/mysql/schema.sql index 01f224382..e69de29bb 100644 --- a/src/main/resources/db/mysql/schema.sql +++ b/src/main/resources/db/mysql/schema.sql @@ -1,9 +0,0 @@ -CREATE TABLE IF NOT EXISTS owners ( - id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - first_name VARCHAR(30), - last_name VARCHAR(30), - address VARCHAR(255), - city VARCHAR(80), - telephone VARCHAR(20), - INDEX(last_name) -) engine=InnoDB; diff --git a/src/test/java/org/springframework/cheapy/integration/CheapyIntegrationTests.java b/src/test/java/org/springframework/cheapy/integration/CheapyIntegrationTests.java index 0c7fb3377..cadb75073 100644 --- a/src/test/java/org/springframework/cheapy/integration/CheapyIntegrationTests.java +++ b/src/test/java/org/springframework/cheapy/integration/CheapyIntegrationTests.java @@ -16,8 +16,6 @@ package org.springframework.cheapy.integration; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; diff --git a/src/test/java/org/springframework/cheapy/web/OwnerControllerTests.java b/src/test/java/org/springframework/cheapy/web/OwnerControllerTests.java deleted file mode 100644 index c684187ca..000000000 --- a/src/test/java/org/springframework/cheapy/web/OwnerControllerTests.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* -package org.springframework.cheapy.web; - -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.is; -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -import org.assertj.core.util.Lists; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.cheapy.model.Owner; -import org.springframework.cheapy.service.OwnerService; -import org.springframework.test.web.servlet.MockMvc; - -/** - * Test class for {@link OwnerController} - * - * @author Colin But - */ -/* -@WebMvcTest(OwnerController.class) -class OwnerControllerTests { - - /*private static final int TEST_OWNER_ID = 1; - - @Autowired - private MockMvc mockMvc; - - @MockBean - private OwnerService ownerService; - - - private Owner george; - - @BeforeEach - void setup() { - george = new Owner(); - george.setId(TEST_OWNER_ID); - george.setFirstName("George"); - george.setLastName("Franklin"); - george.setAddress("110 W. Liberty St."); - george.setCity("Madison"); - george.setTelephone("6085551023"); - - given(this.ownerService.findOwnerById(TEST_OWNER_ID)).willReturn(george); - - - } - - @Test - void testInitCreationForm() throws Exception { - mockMvc.perform(get("/owners/new")).andExpect(status().isOk()).andExpect(model().attributeExists("owner")) - .andExpect(view().name("owners/createOrUpdateOwnerForm")); - } - - @Test - void testProcessCreationFormSuccess() throws Exception { - mockMvc.perform(post("/owners/new").param("firstName", "Joe").param("lastName", "Bloggs") - .param("address", "123 Caramel Street").param("city", "London").param("telephone", "01316761638")) - .andExpect(status().is3xxRedirection()); - } - - @Test - void testProcessCreationFormHasErrors() throws Exception { - mockMvc.perform( - post("/owners/new").param("firstName", "Joe").param("lastName", "Bloggs").param("city", "London")) - .andExpect(status().isOk()).andExpect(model().attributeHasErrors("owner")) - .andExpect(model().attributeHasFieldErrors("owner", "address")) - .andExpect(model().attributeHasFieldErrors("owner", "telephone")) - .andExpect(view().name("owners/createOrUpdateOwnerForm")); - } - - @Test - void testInitFindForm() throws Exception { - mockMvc.perform(get("/owners/find")).andExpect(status().isOk()).andExpect(model().attributeExists("owner")) - .andExpect(view().name("owners/findOwners")); - } - - @Test - void testProcessFindFormSuccess() throws Exception { - given(this.ownerService.findByLastName("")).willReturn(Lists.newArrayList(george, new Owner())); - mockMvc.perform(get("/owners")).andExpect(status().isOk()).andExpect(view().name("owners/ownersList")); - } - - @Test - void testProcessFindFormByLastName() throws Exception { - given(this.ownerService.findByLastName(george.getLastName())).willReturn(Lists.newArrayList(george)); - mockMvc.perform(get("/owners").param("lastName", "Franklin")).andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/" + TEST_OWNER_ID)); - } - - @Test - void testProcessFindFormNoOwnersFound() throws Exception { - mockMvc.perform(get("/owners").param("lastName", "Unknown Surname")).andExpect(status().isOk()) - .andExpect(model().attributeHasFieldErrors("owner", "lastName")) - .andExpect(model().attributeHasFieldErrorCode("owner", "lastName", "notFound")) - .andExpect(view().name("owners/findOwners")); - } - - @Test - void testInitUpdateOwnerForm() throws Exception { - mockMvc.perform(get("/owners/{ownerId}/edit", TEST_OWNER_ID)).andExpect(status().isOk()) - .andExpect(model().attributeExists("owner")) - .andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin")))) - .andExpect(model().attribute("owner", hasProperty("firstName", is("George")))) - .andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St.")))) - .andExpect(model().attribute("owner", hasProperty("city", is("Madison")))) - .andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023")))) - .andExpect(view().name("owners/createOrUpdateOwnerForm")); - } - - @Test - void testProcessUpdateOwnerFormSuccess() throws Exception { - mockMvc.perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID).param("firstName", "Joe") - .param("lastName", "Bloggs").param("address", "123 Caramel Street").param("city", "London") - .param("telephone", "01616291589")).andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/{ownerId}")); - } - - @Test - void testProcessUpdateOwnerFormHasErrors() throws Exception { - mockMvc.perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID).param("firstName", "Joe") - .param("lastName", "Bloggs").param("city", "London")).andExpect(status().isOk()) - .andExpect(model().attributeHasErrors("owner")) - .andExpect(model().attributeHasFieldErrors("owner", "address")) - .andExpect(model().attributeHasFieldErrors("owner", "telephone")) - .andExpect(view().name("owners/createOrUpdateOwnerForm")); - } - - @Test - void testShowOwner() throws Exception { - mockMvc.perform(get("/owners/{ownerId}", TEST_OWNER_ID)).andExpect(status().isOk()) - .andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin")))) - .andExpect(model().attribute("owner", hasProperty("firstName", is("George")))) - .andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St.")))) - .andExpect(model().attribute("owner", hasProperty("city", is("Madison")))) - .andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023")))) - .andExpect(view().name("owners/ownerDetails")); - }*/ From 47232540b9ac4fb296e9db37b24aba1998f1008e Mon Sep 17 00:00:00 2001 From: Thiloparn <48439369+Thiloparn@users.noreply.github.com> Date: Fri, 9 Apr 2021 18:22:14 +0200 Subject: [PATCH 07/21] Ver, modificar y borrar de admin sobre usuarios funcional --- .../cheapy/model/Administrator.java | 16 ++++- .../cheapy/repository/UsuarioRepository.java | 4 ++ .../cheapy/service/UsuarioService.java | 12 ++++ .../cheapy/web/AdministratorController.java | 68 +++++++++++++++++++ .../cheapy/web/UsuarioController.java | 2 +- src/main/resources/db/mysql/data.sql | 15 ++-- ...Form.jsp => createOrUpdateUsuarioForm.jsp} | 0 .../WEB-INF/jsp/usuarios/usuariosList.jsp | 57 ++++++++++++++++ .../WEB-INF/jsp/usuarios/usuariosShow.jsp | 12 ++++ src/main/webapp/WEB-INF/jsp/welcome.jsp | 8 +++ 10 files changed, 185 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/springframework/cheapy/web/AdministratorController.java rename src/main/webapp/WEB-INF/jsp/usuarios/{createOrUpdateUsuariosForm.jsp => createOrUpdateUsuarioForm.jsp} (100%) create mode 100644 src/main/webapp/WEB-INF/jsp/usuarios/usuariosList.jsp 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/UsuarioRepository.java b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java index a472b2f17..87b11c04d 100644 --- a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java @@ -13,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/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..f1c9b77dc --- /dev/null +++ b/src/main/java/org/springframework/cheapy/web/AdministratorController.java @@ -0,0 +1,68 @@ +package org.springframework.cheapy.web; + +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +import org.springframework.beans.BeanUtils; +import org.springframework.cheapy.model.FoodOffer; +import org.springframework.cheapy.model.NuOffer; +import org.springframework.cheapy.model.SpeedOffer; +import org.springframework.cheapy.model.StatusOffer; +import org.springframework.cheapy.model.TimeOffer; +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.validation.BindingResult; +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; + + public AdministratorController(final UsuarioService usuarioService, ClientService clientService) { + this.usuarioService = usuarioService; + } + + @GetMapping("/administrators/usuarios") + public String processFindUsuariosForm(Map model) { + List usuarioLs = this.usuarioService.findAllUsuario(); + model.put("usuarioLs", usuarioLs); + return "usuarios/usuariosList"; + } + + @GetMapping("/administrators/usuarios/{username}") + public String processShowForm(@PathVariable("username") String username, Map model) { + Usuario usuario = this.usuarioService.findByUsername(username); + model.put("usuario", usuario); + return "usuarios/usuariosShow"; + } + + @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"; + } +} diff --git a/src/main/java/org/springframework/cheapy/web/UsuarioController.java b/src/main/java/org/springframework/cheapy/web/UsuarioController.java index 08d6185f8..4fffd6ff6 100644 --- a/src/main/java/org/springframework/cheapy/web/UsuarioController.java +++ b/src/main/java/org/springframework/cheapy/web/UsuarioController.java @@ -21,7 +21,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/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index 5f2794626..dae325921 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -9,22 +9,23 @@ INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', ' 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 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/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 37142a352..39548df42 100644 --- a/src/main/webapp/WEB-INF/jsp/welcome.jsp +++ b/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -43,6 +43,14 @@ + + +
+ +
+
From b6ac934baeec978ef5ddec654641dbcaff734c2c Mon Sep 17 00:00:00 2001 From: Thiloparn <48439369+Thiloparn@users.noreply.github.com> Date: Fri, 9 Apr 2021 18:47:37 +0200 Subject: [PATCH 08/21] Arreglo de fallo en travis --- .../springframework/cheapy/repository/UsuarioRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java index aac72ae94..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; From c51cd0acf78a9f47922a12a5cf7d6bf2e67c3a06 Mon Sep 17 00:00:00 2001 From: abemorcardc Date: Fri, 9 Apr 2021 20:52:22 +0200 Subject: [PATCH 09/21] Administrador lista, muestra y borra clientes funcional --- .../configuration/SecurityConfiguration.java | 2 +- .../cheapy/repository/ClientRepository.java | 7 +++ .../cheapy/service/ClientService.java | 12 +++- .../cheapy/web/AdministratorController.java | 46 ++++++++++++---- .../webapp/WEB-INF/jsp/clients/clientShow.jsp | 15 ++++- .../WEB-INF/jsp/clients/clientsList.jsp | 55 +++++++++++++++++++ src/main/webapp/WEB-INF/jsp/welcome.jsp | 8 --- src/main/webapp/WEB-INF/tags/menu.tag | 14 +++++ 8 files changed, 135 insertions(+), 24 deletions(-) create mode 100644 src/main/webapp/WEB-INF/jsp/clients/clientsList.jsp 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/repository/ClientRepository.java b/src/main/java/org/springframework/cheapy/repository/ClientRepository.java index 54c696f00..ac016a82c 100644 --- a/src/main/java/org/springframework/cheapy/repository/ClientRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/ClientRepository.java @@ -1,5 +1,7 @@ package org.springframework.cheapy.repository; +import java.util.List; + import org.springframework.cheapy.model.Client; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; @@ -11,6 +13,11 @@ public interface ClientRepository extends Repository { @Transactional(readOnly = true) Client findByUsername(String username); + @Query("SELECT client FROM Client client") + @Transactional(readOnly = true) + List findAllClient(); + + void save(Client client); } 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/web/AdministratorController.java b/src/main/java/org/springframework/cheapy/web/AdministratorController.java index f1c9b77dc..d5e001f77 100644 --- a/src/main/java/org/springframework/cheapy/web/AdministratorController.java +++ b/src/main/java/org/springframework/cheapy/web/AdministratorController.java @@ -1,25 +1,16 @@ package org.springframework.cheapy.web; -import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Map; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; -import org.springframework.beans.BeanUtils; -import org.springframework.cheapy.model.FoodOffer; -import org.springframework.cheapy.model.NuOffer; -import org.springframework.cheapy.model.SpeedOffer; -import org.springframework.cheapy.model.StatusOffer; -import org.springframework.cheapy.model.TimeOffer; +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.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -30,9 +21,11 @@ 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") @@ -42,13 +35,26 @@ public class AdministratorController { 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 processShowForm(@PathVariable("username") String username, Map model) { + 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) { @@ -56,6 +62,7 @@ public class AdministratorController { 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) { @@ -65,4 +72,21 @@ public class AdministratorController { 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/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/welcome.jsp b/src/main/webapp/WEB-INF/jsp/welcome.jsp index 580f03987..43be3e422 100644 --- a/src/main/webapp/WEB-INF/jsp/welcome.jsp +++ b/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -48,14 +48,6 @@ - - -
- -
-
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 + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - -
- - +
+ + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + +
+ +
+
+

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 c9fd5dbba..9be34211d 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -14,104 +14,108 @@

No hay ninguna oferta por plato específico activa.

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

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

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

@@ -119,52 +123,54 @@

No hay ninguna oferta por tiempo empleado en comer activa.

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

@@ -172,51 +178,53 @@

No hay ninguna oferta por franja horaria activa.

- - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - -
- -
-
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+
+
diff --git a/src/main/webapp/WEB-INF/jsp/welcome.jsp b/src/main/webapp/WEB-INF/jsp/welcome.jsp index a2622ed5a..8b3d1f5ca 100644 --- a/src/main/webapp/WEB-INF/jsp/welcome.jsp +++ b/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -9,32 +9,33 @@ <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> -

+

-
- -
- - -
- -
-
- -
-
- +
+
+ +
+ + +
+ +
+
+ +
+
+
diff --git a/src/main/webapp/WEB-INF/tags/pivotal.tag b/src/main/webapp/WEB-INF/tags/pivotal.tag index 3824905bf..8ab29192a 100644 --- a/src/main/webapp/WEB-INF/tags/pivotal.tag +++ b/src/main/webapp/WEB-INF/tags/pivotal.tag @@ -2,7 +2,7 @@

-
+
" alt="Eat fast, eat cheapy"/>
From 765190b8111810d484ef254be92d34128745a7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Franco=20S=C3=A1nchez?= <56022165+pabfrasan@users.noreply.github.com> Date: Sat, 10 Apr 2021 11:30:49 +0200 Subject: [PATCH 11/21] Vista de restaurante MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se ha añadido todo lo necesario para que cualquiera pueda ver información general de los restaurantes/bares --- .../cheapy/repository/ClientRepository.java | 11 +++- .../cheapy/web/ClientController.java | 15 +++++ .../WEB-INF/jsp/clients/restaurantShow.jsp | 58 +++++++++++++++++++ .../webapp/WEB-INF/jsp/offers/offersList.jsp | 8 +-- 4 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 src/main/webapp/WEB-INF/jsp/clients/restaurantShow.jsp diff --git a/src/main/java/org/springframework/cheapy/repository/ClientRepository.java b/src/main/java/org/springframework/cheapy/repository/ClientRepository.java index 54c696f00..128db69ac 100644 --- a/src/main/java/org/springframework/cheapy/repository/ClientRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/ClientRepository.java @@ -1,16 +1,21 @@ package org.springframework.cheapy.repository; +import java.util.Optional; + import org.springframework.cheapy.model.Client; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.Repository; import org.springframework.transaction.annotation.Transactional; -public interface ClientRepository extends Repository { +public interface ClientRepository extends CrudRepository { @Query("SELECT client FROM Client client WHERE username =:username") @Transactional(readOnly = true) Client findByUsername(String username); + + Optional findById(Integer id); - void save(Client client); +// void save(Client client); -} +} \ No newline at end of file diff --git a/src/main/java/org/springframework/cheapy/web/ClientController.java b/src/main/java/org/springframework/cheapy/web/ClientController.java index 3cc9138b3..fef9d999e 100644 --- a/src/main/java/org/springframework/cheapy/web/ClientController.java +++ b/src/main/java/org/springframework/cheapy/web/ClientController.java @@ -7,14 +7,17 @@ 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; import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; +import org.springframework.cheapy.repository.ClientRepository; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.FoodOfferService; import org.springframework.cheapy.service.NuOfferService; @@ -24,6 +27,7 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @Controller @@ -41,6 +45,9 @@ public class ClientController { private final TimeOfferService timeOfferService; + @Autowired + private ClientRepository clientRepo; + public ClientController(final ClientService clientService, FoodOfferService foodOfferService, SpeedOfferService speedOfferService, NuOfferService nuOfferService, TimeOfferService timeOfferService) { @@ -141,4 +148,12 @@ public class ClientController { return "redirect:/login"; } + @GetMapping(value = "/restaurant/{clientId}") + 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"; + } } diff --git a/src/main/webapp/WEB-INF/jsp/clients/restaurantShow.jsp b/src/main/webapp/WEB-INF/jsp/clients/restaurantShow.jsp new file mode 100644 index 000000000..150a738bc --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/clients/restaurantShow.jsp @@ -0,0 +1,58 @@ +<%@ 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" %> + + + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp index c9fd5dbba..0b8f7da47 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -31,7 +31,7 @@ - + @@ -84,7 +84,7 @@ - + @@ -136,7 +136,7 @@ - + @@ -188,7 +188,7 @@ - + From d1909ec7e12d00ba29f8598a6b018c5bc11b3946 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 10 Apr 2021 15:40:27 +0200 Subject: [PATCH 12/21] Cambios en las nuevas vistas y arreglo de algunos errores --- src/main/less/cheapy.less | 32 +++++++++++++++++++ .../resources/messages/messages_es.properties | 17 +++++++++- .../WEB-INF/jsp/clients/clientDisable.jsp | 2 +- .../webapp/WEB-INF/jsp/clients/clientShow.jsp | 24 +++++++------- .../WEB-INF/jsp/clients/clientsList.jsp | 4 +-- .../WEB-INF/jsp/usuarios/usuariosDisable.jsp | 2 +- .../WEB-INF/jsp/usuarios/usuariosList.jsp | 10 +++--- .../WEB-INF/jsp/usuarios/usuariosShow.jsp | 8 ++--- src/main/webapp/WEB-INF/jsp/welcome.jsp | 14 ++++---- 9 files changed, 81 insertions(+), 32 deletions(-) diff --git a/src/main/less/cheapy.less b/src/main/less/cheapy.less index cbda84c10..b62ff8533 100644 --- a/src/main/less/cheapy.less +++ b/src/main/less/cheapy.less @@ -522,6 +522,38 @@ text-align: center; background-color: rgb(204, 128, 51); } +#clientTable th{ + width: 30%; + text-align: center; +} + +#clientTable td{ + vertical-align:middle; +text-align: center; +} + +#reviewTable th{ + width: 30%; + text-align: center; +} + +#reviewTable td{ + vertical-align:middle; +text-align: center; +} + +#usuarioTable th{ + width: 20%; + text-align: center; + vertical-align:middle; +} + +#usuarioTable td{ + width:20%; + vertical-align:middle; +text-align: center; +} + #vacio { text-align:center; font-size: 120%; diff --git a/src/main/resources/messages/messages_es.properties b/src/main/resources/messages/messages_es.properties index 4f1fa0a1d..d1e5854d1 100644 --- a/src/main/resources/messages/messages_es.properties +++ b/src/main/resources/messages/messages_es.properties @@ -48,10 +48,25 @@ createSpeedOffers= Crear ofertas por rapidez comiendo createTimeOffers= Crear ofertas por franja horaria init= Inicio del intervalo finishOffer= Fin del intervalo -name= Nombre del restaurante +name= Nombre del bar/restaurante status= Estado de oferta myOffers= Ver mis Ofertas typeMismatch=Debe ser del formato correcto typeMismatch.java.lang.Integer=Debe ser un número typeMismatch.java.time.LocalDateTime=Debe ser una fecha válida typeMismatch.java.time.LocalTime=Debe ser una hora válida +clientShow= Información del bar/restaurante +client= Cliente +clients= Clientes +email=Dirección de correo electrónico +addressClient= Dirección del bar/restaurante +addressUser= Dirección del usuario +telephone= Número de teléfono +descriptionClient= Descripción del bar/restaurante +foodClient= Tipo de comida +enabled= ¿Está activo el usuario? +users=Usuarios +nameUser=Nombre +surname= Apellidos +dni= DNI +usuario=Usuario \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientDisable.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientDisable.jsp index 5961d075c..2e824727e 100644 --- a/src/main/webapp/WEB-INF/jsp/clients/clientDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/clients/clientDisable.jsp @@ -9,7 +9,7 @@ -

¿Está seguro de que quiere eliminar su cuenta?

+

¿Está seguro de que quiere eliminar su cuenta?

diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp index 66ff86179..e83809451 100644 --- a/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp @@ -16,34 +16,34 @@ - - + + - - + + - + - - + + - + - - + + - + - + diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientsList.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientsList.jsp index 464b7a0ec..abb1bc295 100644 --- a/src/main/webapp/WEB-INF/jsp/clients/clientsList.jsp +++ b/src/main/webapp/WEB-INF/jsp/clients/clientsList.jsp @@ -18,8 +18,8 @@ - - + + diff --git a/src/main/webapp/WEB-INF/jsp/usuarios/usuariosDisable.jsp b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosDisable.jsp index a728c3f55..6c04207c7 100644 --- a/src/main/webapp/WEB-INF/jsp/usuarios/usuariosDisable.jsp +++ b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosDisable.jsp @@ -9,7 +9,7 @@ -

¿Está seguro de que quiere eliminar su cuenta?

+

¿Está seguro de que quiere eliminar su cuenta?

diff --git a/src/main/webapp/WEB-INF/jsp/usuarios/usuariosList.jsp b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosList.jsp index 297978c7e..e1c56b62e 100644 --- a/src/main/webapp/WEB-INF/jsp/usuarios/usuariosList.jsp +++ b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosList.jsp @@ -8,18 +8,18 @@ -

+

-

No hay ningun usuario.

+

No hay ningún usuario.

- - - + + + diff --git a/src/main/webapp/WEB-INF/jsp/usuarios/usuariosShow.jsp b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosShow.jsp index 2feff3623..c9201d00c 100644 --- a/src/main/webapp/WEB-INF/jsp/usuarios/usuariosShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/usuarios/usuariosShow.jsp @@ -14,11 +14,11 @@
- + - + @@ -26,11 +26,11 @@ - + - + diff --git a/src/main/webapp/WEB-INF/jsp/welcome.jsp b/src/main/webapp/WEB-INF/jsp/welcome.jsp index e5a956229..0ebaa7377 100644 --- a/src/main/webapp/WEB-INF/jsp/welcome.jsp +++ b/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -35,7 +35,7 @@
-
@@ -43,11 +43,13 @@ -
- -
+
+
+ +
+
From 0415e6b8b662327cbe8d57c8c7528f45e6b9a271 Mon Sep 17 00:00:00 2001 From: abemorcardc Date: Sat, 10 Apr 2021 17:05:39 +0200 Subject: [PATCH 13/21] Campos init y finish de client han pasado de String a LocalTime --- .../springframework/cheapy/model/Client.java | 23 +++++++++++-------- .../cheapy/web/ClientController.java | 15 +++++++++--- src/main/resources/db/mysql/data.sql | 4 ++-- .../jsp/clients/createOrUpdateClientForm.jsp | 2 +- .../cheapy/web/FoodOfferControllerTests.java | 5 ++-- .../cheapy/web/NuOfferControllerTests.java | 5 ++-- .../cheapy/web/SpeedOfferControllerTests.java | 5 ++-- .../cheapy/web/TimeOfferControllerTests.java | 4 ++-- 8 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/model/Client.java b/src/main/java/org/springframework/cheapy/model/Client.java index 2981c9d98..41d81ca19 100644 --- a/src/main/java/org/springframework/cheapy/model/Client.java +++ b/src/main/java/org/springframework/cheapy/model/Client.java @@ -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; } diff --git a/src/main/java/org/springframework/cheapy/web/ClientController.java b/src/main/java/org/springframework/cheapy/web/ClientController.java index fef9d999e..f17923b36 100644 --- a/src/main/java/org/springframework/cheapy/web/ClientController.java +++ b/src/main/java/org/springframework/cheapy/web/ClientController.java @@ -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()) { diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index 1074dcd4a..3e308ec2d 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -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); diff --git a/src/main/webapp/WEB-INF/jsp/clients/createOrUpdateClientForm.jsp b/src/main/webapp/WEB-INF/jsp/clients/createOrUpdateClientForm.jsp index bd21204d0..163807396 100644 --- a/src/main/webapp/WEB-INF/jsp/clients/createOrUpdateClientForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/clients/createOrUpdateClientForm.jsp @@ -9,7 +9,7 @@

- +

diff --git a/src/test/java/org/springframework/cheapy/web/FoodOfferControllerTests.java b/src/test/java/org/springframework/cheapy/web/FoodOfferControllerTests.java index a0ef27af7..a6ca4f81c 100644 --- a/src/test/java/org/springframework/cheapy/web/FoodOfferControllerTests.java +++ b/src/test/java/org/springframework/cheapy/web/FoodOfferControllerTests.java @@ -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"); diff --git a/src/test/java/org/springframework/cheapy/web/NuOfferControllerTests.java b/src/test/java/org/springframework/cheapy/web/NuOfferControllerTests.java index 31ec0d75b..13815ff9a 100644 --- a/src/test/java/org/springframework/cheapy/web/NuOfferControllerTests.java +++ b/src/test/java/org/springframework/cheapy/web/NuOfferControllerTests.java @@ -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"); diff --git a/src/test/java/org/springframework/cheapy/web/SpeedOfferControllerTests.java b/src/test/java/org/springframework/cheapy/web/SpeedOfferControllerTests.java index d2bc2c1aa..d05027011 100644 --- a/src/test/java/org/springframework/cheapy/web/SpeedOfferControllerTests.java +++ b/src/test/java/org/springframework/cheapy/web/SpeedOfferControllerTests.java @@ -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"); diff --git a/src/test/java/org/springframework/cheapy/web/TimeOfferControllerTests.java b/src/test/java/org/springframework/cheapy/web/TimeOfferControllerTests.java index 64ff4c362..8ff0a094e 100644 --- a/src/test/java/org/springframework/cheapy/web/TimeOfferControllerTests.java +++ b/src/test/java/org/springframework/cheapy/web/TimeOfferControllerTests.java @@ -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"); From 7aaf151b0ab16e984b90e164ab406f820e6e1aba Mon Sep 17 00:00:00 2001 From: "gabgutpri@alum.us.es" Date: Sat, 10 Apr 2021 17:56:35 +0200 Subject: [PATCH 14/21] Pag FoodOffer --- .../repository/FoodOfferRepository.java | 22 ++-- .../cheapy/service/FoodOfferService.java | 24 +++-- .../cheapy/web/OfertaController.java | 101 +++++++++--------- src/main/resources/db/mysql/data.sql | 22 +++- 4 files changed, 96 insertions(+), 73 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java index 099f6788c..5ee262df4 100644 --- a/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java @@ -1,15 +1,17 @@ + package org.springframework.cheapy.repository; +import java.util.List; + import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.StatusOffer; - -import java.util.List; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.Repository; +import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; -public interface FoodOfferRepository extends Repository { +public interface FoodOfferRepository extends PagingAndSortingRepository { @Query("SELECT foodOffer FROM FoodOffer foodOffer") @Transactional(readOnly = true) @@ -17,18 +19,18 @@ public interface FoodOfferRepository extends Repository { @Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE id =:id") @Transactional(readOnly = true) - FoodOffer findById(@Param("id") Integer id); + FoodOffer findByIdFO(@Param("id") Integer id); + + //void save(FoodOffer foodOffer); - void save(FoodOffer foodOffer); - @Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.status =:status") @Transactional(readOnly = true) - List findActiveFoodOffer(StatusOffer status); - + List findActiveFoodOffer(StatusOffer status, Pageable p); + @Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.id =:id") @Transactional(readOnly = true) List findByUserId(@Param("id") Integer id); - + @Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.id =:id AND foodOffer.status!= 'inactive'") @Transactional(readOnly = true) List findFoodOfferActOclByUserId(@Param("id") Integer id); diff --git a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java index a555e5c6c..79b98b494 100644 --- a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java @@ -1,43 +1,47 @@ + package org.springframework.cheapy.service; +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.repository.FoodOfferRepository; -import java.util.List; import org.springframework.dao.DataAccessException; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @Service public class FoodOfferService { - + private FoodOfferRepository foodOfferRepository; + @Autowired public FoodOfferService(final FoodOfferRepository foodOfferRepository) { this.foodOfferRepository = foodOfferRepository; } public FoodOffer findFoodOfferById(final int id) { - return this.foodOfferRepository.findById(id); + return this.foodOfferRepository.findByIdFO(id); } - - public List findAllFoodOffer() { // + + public List findAllFoodOffer(final Pageable p) { // return this.foodOfferRepository.findAllFoodOffer(); } public void saveFoodOffer(final FoodOffer foodOffer) throws DataAccessException { this.foodOfferRepository.save(foodOffer); } - - public List findActiveFoodOffer() { - return this.foodOfferRepository.findActiveFoodOffer(StatusOffer.active); + + public List findActiveFoodOffer(final Pageable p) { + return this.foodOfferRepository.findActiveFoodOffer(StatusOffer.active, p); } - + public List findFoodOfferByUserId(final int id) { return this.foodOfferRepository.findByUserId(id); } - + public List findFoodOfferActOclByUserId(final int id) { return this.foodOfferRepository.findFoodOfferActOclByUserId(id); } diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index 60567c491..2c30db007 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -1,3 +1,4 @@ + package org.springframework.cheapy.web; import java.time.format.DateTimeFormatter; @@ -13,24 +14,23 @@ import org.springframework.cheapy.service.FoodOfferService; import org.springframework.cheapy.service.NuOfferService; import org.springframework.cheapy.service.SpeedOfferService; import org.springframework.cheapy.service.TimeOfferService; -import org.springframework.security.authentication.AnonymousAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class OfertaController { - private final ClientService clientService; + private final ClientService clientService; - private final FoodOfferService foodOfferService; - private final NuOfferService nuOfferService; - private final SpeedOfferService speedOfferService; - private final TimeOfferService timeOfferService; + private final FoodOfferService foodOfferService; + private final NuOfferService nuOfferService; + private final SpeedOfferService speedOfferService; + private final TimeOfferService timeOfferService; - public OfertaController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, - final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService, ClientService clientService) { + + public OfertaController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService, final ClientService clientService) { this.clientService = clientService; this.foodOfferService = foodOfferService; this.nuOfferService = nuOfferService; @@ -39,12 +39,13 @@ public class OfertaController { } @GetMapping("/offers") - public String processFindForm( Map model) { + public String processFindForm(final Map model) { + Pageable elements = PageRequest.of(0, 3); - List foodOfferLs=this.foodOfferService.findActiveFoodOffer(); - List nuOfferLs=this.nuOfferService.findActiveNuOffer(); - List speedOfferLs=this.speedOfferService.findActiveSpeedOffer(); - List timeOfferLs=this.timeOfferService.findActiveTimeOffer(); + List foodOfferLs = this.foodOfferService.findActiveFoodOffer(elements); + List nuOfferLs = this.nuOfferService.findActiveNuOffer(); + List speedOfferLs = this.speedOfferService.findActiveSpeedOffer(); + List timeOfferLs = this.timeOfferService.findActiveTimeOffer(); model.put("foodOfferLs", foodOfferLs); model.put("nuOfferLs", nuOfferLs); @@ -58,9 +59,8 @@ public class OfertaController { } - @GetMapping("/myOffers") - public String processMyOffersForm( Map model) { + public String processMyOffersForm(final Map model) { int actual = this.clientService.getCurrentClient().getId(); @@ -78,43 +78,40 @@ public class OfertaController { model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); return "offers/myOffersList"; - } + } - @GetMapping("/offersCreate") - public String createOffers() { + @GetMapping("/offersCreate") + public String createOffers() { - return "offers/offersCreate"; - } - - - -// @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; -// } + return "offers/offersCreate"; + } + // @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 c279eadf3..95227b11f 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -34,16 +34,36 @@ INSERT INTO clients (id, name, email, address, init, finish, telephone, descript 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); +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-3', 'active', 1, 'Estofado', 10); +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-4', 'active', 1, 'Puchero', 10); +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-5', 'active', 2, 'Tumbalobos', 10); +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-6', 'active', 2, 'Tortilla', 10); +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-7', 'active', 2, 'Arroz con leche', 10); INSERT INTO food_offers(start, end, code, status, client_id, food, discount) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden', 1, 'macarrones con queso', 5); INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'T-1', 'inactive', 1, '12:00:00', '13:00:00', 5); INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-2', 'active', 1, '12:00:00', '13:00:00', 10); +INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-3', 'active', 1, '12:30:00', '14:30:00', 10); +INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-4', 'active', 1, '12:00:00', '13:00:00', 5); +INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-5', 'active', 2, '13:00:00', '16:00:00', 15); +INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-6', 'active', 2, '14:00:00', '17:00:00', 15); +INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'T-7', 'active', 2, '11:00:00', '20:00:00', 20); INSERT INTO time_offers(start, end, code, status, client_id, init, finish, discount) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden', 1, '12:00:00', '13:00:00', 15); INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'SP-1', 'inactive',1,5,25,10,15,15,10); -INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-2', 'active',1,5,25,10,15,15,10); +INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-2', 'active',1,35,25,40,15,55,10); +INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-3', 'active',1,25,25,30,15,35,10); +INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-4', 'active',1,15,25,20,15,35,10); +INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-5', 'active',2,15,30,20,15,50,5); +INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-6', 'active',2,15,30,21,15,50,5); +INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'SP-7', 'active',2,15,30,22,15,50,5); INSERT INTO speed_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden',1,5,25,10,15,15,10); INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-14 12:00:00', '2021-08-15 12:00:00', 'NU-1', 'inactive',1,15,25,10,15,5,10); INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-2', 'active',1,15,25,10,15,5,10); +INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-3', 'active',1,15,25,12,15,3,5); +INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-4', 'active',1,15,25,13,15,2,5); +INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-5', 'active',2,20,35,15,15,5,5); +INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-6', 'active',2,20,30,15,10,10,5); +INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-15 12:00:00', '2021-08-16 12:00:00', 'NU-7', 'active',2,20,35,15,15,10,5); INSERT INTO nu_offers(start, end, code, status, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-08-16 12:00:00', '2021-08-17 12:00:00', null, 'hidden',1,15,25,10,15,5,10); From 1cc7a9daa5242f8faffeb8747866655d37d1d66a Mon Sep 17 00:00:00 2001 From: "gabgutpri@alum.us.es" Date: Sat, 10 Apr 2021 21:32:36 +0200 Subject: [PATCH 15/21] =?UTF-8?q?Paginacion=20en=20todos=20las=20ofertas?= =?UTF-8?q?=20y=20rese=C3=B1as?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cheapy/repository/NuOfferRepository.java | 22 +-- .../cheapy/repository/ReviewRepository.java | 14 +- .../repository/SpeedOfferRepository.java | 24 +-- .../repository/TimeOfferRepository.java | 21 ++- .../cheapy/service/NuOfferService.java | 21 ++- .../cheapy/service/ReviewService.java | 9 +- .../cheapy/service/SpeedOfferService.java | 20 ++- .../cheapy/service/TimeOfferService.java | 23 +-- .../cheapy/web/FoodOfferController.java | 113 ++++++------ .../cheapy/web/NuOfferController.java | 165 +++++++++--------- .../cheapy/web/OfertaController.java | 6 +- .../cheapy/web/ReviewController.java | 37 ++-- .../cheapy/web/SpeedOfferController.java | 160 ++++++++--------- .../cheapy/web/TimeOfferController.java | 140 +++++++-------- .../jsp/offers/food/foodOffersList.jsp | 40 ++++- .../WEB-INF/jsp/offers/nu/nuOffersList.jsp | 40 ++++- .../webapp/WEB-INF/jsp/offers/offersList.jsp | 39 +++-- .../jsp/offers/speed/speedOffersList.jsp | 40 ++++- .../jsp/offers/time/timeOffersList.jsp | 40 ++++- .../WEB-INF/jsp/reviews/reviewsList.jsp | 19 +- src/main/webapp/WEB-INF/tags/menu.tag | 2 +- 21 files changed, 581 insertions(+), 414 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java index 1dd0a9296..7cc4b8335 100644 --- a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java @@ -1,32 +1,34 @@ + package org.springframework.cheapy.repository; import java.util.List; import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.StatusOffer; -import org.springframework.data.repository.Repository; -import org.springframework.data.repository.query.Param; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; -public interface NuOfferRepository extends Repository { +public interface NuOfferRepository extends PagingAndSortingRepository { NuOffer findNuOfferById(int nuOfferId); - + @Query("SELECT nuOffer FROM NuOffer nuOffer") @Transactional(readOnly = true) - List findAllNuOffer(); + List findAllNuOffer(Pageable p); + + //void save(NuOffer nuOffer); - void save(NuOffer nuOffer); - @Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.status =:status") @Transactional(readOnly = true) - List findActiveNuOffer(StatusOffer status); - + List findActiveNuOffer(StatusOffer status, Pageable p); + @Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.id =:id") @Transactional(readOnly = true) List findByUserId(@Param("id") Integer id); - + @Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.id =:id AND nuOffer.status!= 'inactive'") @Transactional(readOnly = true) List findNuOfferActOclByUserId(@Param("id") Integer id); diff --git a/src/main/java/org/springframework/cheapy/repository/ReviewRepository.java b/src/main/java/org/springframework/cheapy/repository/ReviewRepository.java index 754e2650f..5a50414dd 100644 --- a/src/main/java/org/springframework/cheapy/repository/ReviewRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/ReviewRepository.java @@ -1,21 +1,23 @@ + package org.springframework.cheapy.repository; import java.util.List; import org.springframework.cheapy.model.Review; -import org.springframework.data.repository.Repository; -import org.springframework.data.repository.query.Param; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; -public interface ReviewRepository extends Repository { +public interface ReviewRepository extends PagingAndSortingRepository { @Query("SELECT r FROM Review r") @Transactional(readOnly = true) - List findAllReviews(); + List findAllReviews(Pageable p); + + //void save(Review review); - void save(Review review); - @Query("SELECT r FROM Review r WHERE id =:id") @Transactional(readOnly = true) Review findReviewById(@Param("id") Integer id); diff --git a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java index 79eedf517..cb49d2b0a 100644 --- a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java @@ -1,34 +1,36 @@ + package org.springframework.cheapy.repository; import java.util.List; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.Repository; +import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; -public interface SpeedOfferRepository extends Repository { +public interface SpeedOfferRepository extends PagingAndSortingRepository { @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE id =:id") @Transactional(readOnly = true) - SpeedOffer findById(@Param("id") Integer id); - + SpeedOffer findByIdSO(@Param("id") Integer id); + @Query("SELECT speedOffer FROM SpeedOffer speedOffer") @Transactional(readOnly = true) - List findAllSpeedOffer(); - - void save(SpeedOffer speedOffer); - + List findAllSpeedOffer(Pageable p); + + //void save(SpeedOffer speedOffer); + @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.status =:status") @Transactional(readOnly = true) - List findActiveSpeedOffer(StatusOffer status); - + List findActiveSpeedOffer(StatusOffer status, Pageable p); + @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.id =:id") @Transactional(readOnly = true) List findByUserId(@Param("id") Integer id); - + @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.id =:id AND speedOffer.status!= 'inactive'") @Transactional(readOnly = true) List findSpeedOfferActOclByUserId(@Param("id") Integer id); diff --git a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java index d891e0953..77ada9fcb 100644 --- a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java @@ -1,32 +1,35 @@ + package org.springframework.cheapy.repository; import java.util.List; +import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; -import org.springframework.data.repository.Repository; -import org.springframework.data.repository.query.Param; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; -public interface TimeOfferRepository extends Repository { +public interface TimeOfferRepository extends PagingAndSortingRepository { TimeOffer findTimeOfferById(int timeOfferId); - + @Query("SELECT timeOffer FROM TimeOffer timeOffer") @Transactional(readOnly = true) - List findAllTimeOffer(); + List findAllTimeOffer(Pageable p); void save(TimeOffer timeOffer); - + @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.status =:status") @Transactional(readOnly = true) - List findActiveTimeOffer(StatusOffer status); - + List findActiveTimeOffer(StatusOffer status, Pageable p); + @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.id =:id") @Transactional(readOnly = true) List findByUserId(@Param("id") Integer id); - + @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.id =:id AND timeOffer.status!= 'inactive'") @Transactional(readOnly = true) List findTimeOfferActOclByUserId(@Param("id") Integer id); diff --git a/src/main/java/org/springframework/cheapy/service/NuOfferService.java b/src/main/java/org/springframework/cheapy/service/NuOfferService.java index 7bbb48aaa..2812df07b 100644 --- a/src/main/java/org/springframework/cheapy/service/NuOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/NuOfferService.java @@ -1,12 +1,14 @@ package org.springframework.cheapy.service; +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.repository.NuOfferRepository; -import java.util.List; import org.springframework.dao.DataAccessException; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -15,6 +17,7 @@ public class NuOfferService { private NuOfferRepository nuOfferRepository; + @Autowired public NuOfferService(final NuOfferRepository nuOfferRepository) { this.nuOfferRepository = nuOfferRepository; @@ -26,28 +29,28 @@ public class NuOfferService { } @Transactional - public List findAllNuOffer() { - return this.nuOfferRepository.findAllNuOffer(); + public List findAllNuOffer(final Pageable page) { + return this.nuOfferRepository.findAllNuOffer(page); } @Transactional public void saveNuOffer(final NuOffer nuOffer) throws DataAccessException { this.nuOfferRepository.save(nuOffer); } - + @Transactional public void saveUpdateNuOffer(final NuOffer nuOfferNew, final NuOffer nuOfferOld) throws DataAccessException { this.nuOfferRepository.save(nuOfferNew); } - - public List findActiveNuOffer() { - return this.nuOfferRepository.findActiveNuOffer(StatusOffer.active); + + public List findActiveNuOffer(final Pageable page) { + return this.nuOfferRepository.findActiveNuOffer(StatusOffer.active, page); } - + public List findNuOfferByUserId(final int id) { return this.nuOfferRepository.findByUserId(id); } - + public List findNuOfferActOclByUserId(final int id) { return this.nuOfferRepository.findNuOfferActOclByUserId(id); } diff --git a/src/main/java/org/springframework/cheapy/service/ReviewService.java b/src/main/java/org/springframework/cheapy/service/ReviewService.java index d07bf7e33..c6e6e6616 100644 --- a/src/main/java/org/springframework/cheapy/service/ReviewService.java +++ b/src/main/java/org/springframework/cheapy/service/ReviewService.java @@ -1,3 +1,4 @@ + package org.springframework.cheapy.service; import java.util.List; @@ -5,15 +6,17 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.Review; import org.springframework.cheapy.repository.ReviewRepository; - import org.springframework.dao.DataAccessException; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service public class ReviewService { + private ReviewRepository reviewRepository; + @Autowired public ReviewService(final ReviewRepository reviewRepository) { this.reviewRepository = reviewRepository; @@ -25,8 +28,8 @@ public class ReviewService { } @Transactional - public List findAllReviews() { - return this.reviewRepository.findAllReviews(); + public List findAllReviews(final Pageable page) { + return this.reviewRepository.findAllReviews(page); } @Transactional diff --git a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java index 2784446b9..2827c0b0c 100644 --- a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java @@ -2,11 +2,13 @@ package org.springframework.cheapy.service; import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.repository.SpeedOfferRepository; import org.springframework.dao.DataAccessException; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,27 +25,27 @@ public class SpeedOfferService { @Transactional public SpeedOffer findSpeedOfferById(final int id) { - return this.speedOfferRepository.findById(id); + return this.speedOfferRepository.findByIdSO(id); } - + @Transactional - public List findAllSpeedOffer() { // - return this.speedOfferRepository.findAllSpeedOffer(); + public List findAllSpeedOffer(final Pageable page) { // + return this.speedOfferRepository.findAllSpeedOffer(page); } @Transactional public void saveSpeedOffer(final SpeedOffer speedOffer) throws DataAccessException { // this.speedOfferRepository.save(speedOffer); } - - public List findActiveSpeedOffer() { - return this.speedOfferRepository.findActiveSpeedOffer(StatusOffer.active); + + public List findActiveSpeedOffer(final Pageable page) { + return this.speedOfferRepository.findActiveSpeedOffer(StatusOffer.active, page); } - + public List findSpeedOfferByUserId(final int id) { return this.speedOfferRepository.findByUserId(id); } - + public List findSpeedOfferActOclByUserId(final int id) { return this.speedOfferRepository.findSpeedOfferActOclByUserId(id); } diff --git a/src/main/java/org/springframework/cheapy/service/TimeOfferService.java b/src/main/java/org/springframework/cheapy/service/TimeOfferService.java index 154fb9bc8..8b7b6ebda 100644 --- a/src/main/java/org/springframework/cheapy/service/TimeOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/TimeOfferService.java @@ -1,3 +1,4 @@ + package org.springframework.cheapy.service; import java.util.List; @@ -6,12 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.repository.TimeOfferRepository; - import org.springframework.dao.DataAccessException; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @Service public class TimeOfferService { + private TimeOfferRepository timeOfferRepository; @@ -23,24 +25,23 @@ public class TimeOfferService { public TimeOffer findTimeOfferById(final int id) { return this.timeOfferRepository.findTimeOfferById(id); } - - public List findAllTimeOffer() { - return this.timeOfferRepository.findAllTimeOffer(); + + public List findAllTimeOffer(final Pageable page) { + return this.timeOfferRepository.findAllTimeOffer(page); } - - public void saveTimeOffer(final TimeOffer TimeOffer) throws DataAccessException { + public void saveTimeOffer(final TimeOffer TimeOffer) throws DataAccessException { this.timeOfferRepository.save(TimeOffer); } - - public List findActiveTimeOffer() { - return this.timeOfferRepository.findActiveTimeOffer(StatusOffer.active); + + public List findActiveTimeOffer(final Pageable p) { + return this.timeOfferRepository.findActiveTimeOffer(StatusOffer.active, p); } - + public List findTimeOfferByUserId(final int id) { return this.timeOfferRepository.findByUserId(id); } - + public List findTimeOfferActOclByUserId(final int id) { return this.timeOfferRepository.findTimeOfferActOclByUserId(id); } diff --git a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java index ce814e54e..17575790e 100644 --- a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java @@ -14,6 +14,8 @@ import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.FoodOfferService; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; @@ -24,10 +26,11 @@ import org.springframework.web.bind.annotation.PostMapping; @Controller public class FoodOfferController { - private static final String VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM = "offers/food/createOrUpdateFoodOfferForm"; + private static final String VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM = "offers/food/createOrUpdateFoodOfferForm"; + + private final FoodOfferService foodOfferService; + private final ClientService clientService; - private final FoodOfferService foodOfferService; - private final ClientService clientService; public FoodOfferController(final FoodOfferService foodOfferService, final ClientService clientService) { this.foodOfferService = foodOfferService; @@ -47,24 +50,25 @@ public class FoodOfferController { private boolean checkOffer(final FoodOffer session, final FoodOffer offer) { boolean res = false; - if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() - && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) { + if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !session.getStatus().equals(StatusOffer.inactive)) { res = true; } return res; } - + private boolean checkDates(final FoodOffer foodOffer) { boolean res = false; - if(foodOffer.getEnd()==null || foodOffer.getStart()==null || foodOffer.getEnd().isAfter(foodOffer.getStart())) { + if (foodOffer.getEnd() == null || foodOffer.getStart() == null || foodOffer.getEnd().isAfter(foodOffer.getStart())) { res = true; } return res; } - - @GetMapping("/offers/foodOfferList") - public String processFindForm(Map model) { - List foodOfferLs=this.foodOfferService.findActiveFoodOffer(); + + @GetMapping("/offers/foodOfferList/{page}") + public String processFindForm(@PathVariable("page") final int page, final Map model) { + Pageable elements = PageRequest.of(page, 5); + + List foodOfferLs = this.foodOfferService.findActiveFoodOffer(elements); model.put("foodOfferLs", foodOfferLs); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); return "offers/food/foodOffersList"; @@ -72,32 +76,32 @@ public class FoodOfferController { } @GetMapping("/offers/food/new") - public String initCreationForm(Map model) { + public String initCreationForm(final Map model) { FoodOffer foodOffer = new FoodOffer(); model.put("foodOffer", foodOffer); - return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; + return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping("/offers/food/new") - public String processCreationForm(@Valid FoodOffer foodOffer, BindingResult result) { - - if(!this.checkDates(foodOffer)) { - result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio"); - - } - if (result.hasErrors()) { - return VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; - } - Client client = this.clientService.getCurrentClient(); - foodOffer.setClient(client); - foodOffer.setStatus(StatusOffer.hidden); - this.foodOfferService.saveFoodOffer(foodOffer); - return "redirect:/offers/food/" + foodOffer.getId(); - + public String processCreationForm(@Valid final FoodOffer foodOffer, final BindingResult result) { + + if (!this.checkDates(foodOffer)) { + result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio"); + + } + if (result.hasErrors()) { + return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; + } + Client client = this.clientService.getCurrentClient(); + foodOffer.setClient(client); + foodOffer.setStatus(StatusOffer.hidden); + this.foodOfferService.saveFoodOffer(foodOffer); + return "redirect:/offers/food/" + foodOffer.getId(); + } @GetMapping(value = "/offers/food/{foodOfferId}/activate") - public String activateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, ModelMap modelMap) { + public String activateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap modelMap) { FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); Client client = this.clientService.getCurrentClient(); if (foodOffer.getClient().equals(client)) { @@ -112,26 +116,25 @@ public class FoodOfferController { } @GetMapping("/offers/food/{foodOfferId}") - public String processShowForm(@PathVariable("foodOfferId") int foodOfferId, Map model) { + public String processShowForm(@PathVariable("foodOfferId") final int foodOfferId, final Map model) { FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); - if(foodOffer.getStatus().equals(StatusOffer.active)) { + if (foodOffer.getStatus().equals(StatusOffer.active)) { model.put("foodOffer", foodOffer); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); return "offers/food/foodOffersShow"; - - }else if(foodOffer.getStatus().equals(StatusOffer.hidden)&&(this.checkIdentity(foodOfferId))) { - model.put("foodOffer", foodOffer); - model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); - return "offers/food/foodOffersShow"; - }else { + + } else if (foodOffer.getStatus().equals(StatusOffer.hidden) && this.checkIdentity(foodOfferId)) { + model.put("foodOffer", foodOffer); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "offers/food/foodOffersShow"; + } else { return "error"; } } @GetMapping(value = "/offers/food/{foodOfferId}/edit") - public String updateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model, - HttpServletRequest request) { + public String updateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model, final HttpServletRequest request) { if (!this.checkIdentity(foodOfferId)) { return "error"; @@ -146,8 +149,7 @@ public class FoodOfferController { } @PostMapping(value = "/offers/food/{foodOfferId}/edit") - public String updateFoodOffer(@Valid final FoodOffer foodOfferEdit, final BindingResult result, - final ModelMap model, HttpServletRequest request) { + public String updateFoodOffer(@Valid final FoodOffer foodOfferEdit, final BindingResult result, final ModelMap model, final HttpServletRequest request) { if (!this.checkIdentity(foodOfferEdit.getId())) { return "error"; @@ -157,22 +159,21 @@ public class FoodOfferController { if (!this.checkOffer(foodOffer, foodOfferEdit)) { return "error"; } - - if(!this.checkDates(foodOfferEdit)) { - result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio"); - - } - - if (result.hasErrors()) { - model.addAttribute("foodOffer", foodOfferEdit); - return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; - } - BeanUtils.copyProperties(this.foodOfferService.findFoodOfferById(foodOfferEdit.getId()), foodOfferEdit, - "start", "end", "food", "discount"); - this.foodOfferService.saveFoodOffer(foodOfferEdit); - return "redirect:/offers/food/" + foodOfferEdit.getId(); - + if (!this.checkDates(foodOfferEdit)) { + result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio"); + + } + + if (result.hasErrors()) { + model.addAttribute("foodOffer", foodOfferEdit); + return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; + + } + BeanUtils.copyProperties(this.foodOfferService.findFoodOfferById(foodOfferEdit.getId()), foodOfferEdit, "start", "end", "food", "discount"); + this.foodOfferService.saveFoodOffer(foodOfferEdit); + return "redirect:/offers/food/" + foodOfferEdit.getId(); + } @GetMapping(value = "/offers/food/{foodOfferId}/disable") diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index 01a3f9cb0..87d3eb549 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -1,3 +1,4 @@ + package org.springframework.cheapy.web; import java.security.Principal; @@ -14,6 +15,8 @@ import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.NuOfferService; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; @@ -24,16 +27,17 @@ import org.springframework.web.bind.annotation.PostMapping; @Controller public class NuOfferController { - private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "offers/nu/createOrUpdateNuOfferForm"; + private static final String VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM = "offers/nu/createOrUpdateNuOfferForm"; + + private final NuOfferService nuOfferService; + private final ClientService clientService; - private final NuOfferService nuOfferService; - private final ClientService clientService; public NuOfferController(final NuOfferService nuOfferService, final ClientService clientService) { this.nuOfferService = nuOfferService; this.clientService = clientService; } - + private boolean checkIdentity(final int nuOfferId) { boolean res = false; Client client = this.clientService.getCurrentClient(); @@ -47,43 +51,44 @@ public class NuOfferController { private boolean checkOffer(final NuOffer session, final NuOffer offer) { boolean res = false; - if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() - && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) { + if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !session.getStatus().equals(StatusOffer.inactive)) { res = true; } return res; } - + private boolean checkDates(final NuOffer nuOffer) { boolean res = false; - if(nuOffer.getEnd()==null || nuOffer.getStart()==null || nuOffer.getEnd().isAfter(nuOffer.getStart())) { + if (nuOffer.getEnd() == null || nuOffer.getStart() == null || nuOffer.getEnd().isAfter(nuOffer.getStart())) { res = true; } return res; } - + private boolean checkConditions(final NuOffer nuOffer) { boolean res = false; - if(nuOffer.getGold()==null || nuOffer.getSilver()==null || nuOffer.getBronze()==null) { - - }else if(nuOffer.getGold() >= nuOffer.getSilver() && nuOffer.getSilver() >= nuOffer.getBronze()) { + if (nuOffer.getGold() == null || nuOffer.getSilver() == null || nuOffer.getBronze() == null) { + + } else if (nuOffer.getGold() >= nuOffer.getSilver() && nuOffer.getSilver() >= nuOffer.getBronze()) { res = true; } return res; } - + private boolean checkDiscounts(final NuOffer NuOffer) { boolean res = false; - if(NuOffer.getDiscountGold()==null || NuOffer.getDiscountSilver()==null || NuOffer.getDiscountBronze()==null) { - }else if(NuOffer.getDiscountGold() >= NuOffer.getDiscountSilver() && NuOffer.getDiscountSilver() >= NuOffer.getDiscountBronze()) { + if (NuOffer.getDiscountGold() == null || NuOffer.getDiscountSilver() == null || NuOffer.getDiscountBronze() == null) { + } else if (NuOffer.getDiscountGold() >= NuOffer.getDiscountSilver() && NuOffer.getDiscountSilver() >= NuOffer.getDiscountBronze()) { res = true; } return res; } - - @GetMapping("/offers/nuOfferList") - public String processFindForm(Map model) { - List foodOfferLs=this.nuOfferService.findActiveNuOffer(); + + @GetMapping("/offers/nuOfferList/{page}") + public String processFindForm(@PathVariable("page") final int page, final Map model) { + Pageable elements = PageRequest.of(page, 5); + + List foodOfferLs = this.nuOfferService.findActiveNuOffer(elements); model.put("nuOfferLs", foodOfferLs); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); return "offers/nu/nuOffersList"; @@ -91,40 +96,40 @@ public class NuOfferController { } @GetMapping("/offers/nu/new") - public String initCreationForm(Map model) { + public String initCreationForm(final Map model) { NuOffer nuOffer = new NuOffer(); model.put("nuOffer", nuOffer); - return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping("/offers/nu/new") - public String processCreationForm(@Valid NuOffer nuOffer, BindingResult result) { - - if(!this.checkDates(nuOffer)) { - result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio"); - - } - if(!this.checkConditions(nuOffer)) { - result.rejectValue("gold","" ,"Oro debe ser mayor o igual que plata, y plata mayor o igual que bronce"); - - } - if(!this.checkDiscounts(nuOffer)) { - result.rejectValue("discountGold","" ,"El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce"); - - } - - if (result.hasErrors()) { - return VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; - } - nuOffer.setStatus(StatusOffer.hidden); + public String processCreationForm(@Valid final NuOffer nuOffer, final BindingResult result) { - Client client = this.clientService.getCurrentClient(); + if (!this.checkDates(nuOffer)) { + result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio"); - nuOffer.setClient(client); + } + if (!this.checkConditions(nuOffer)) { + result.rejectValue("gold", "", "Oro debe ser mayor o igual que plata, y plata mayor o igual que bronce"); + + } + if (!this.checkDiscounts(nuOffer)) { + result.rejectValue("discountGold", "", "El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce"); + + } + + if (result.hasErrors()) { + return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + nuOffer.setStatus(StatusOffer.hidden); + + Client client = this.clientService.getCurrentClient(); + + nuOffer.setClient(client); + + this.nuOfferService.saveNuOffer(nuOffer); + return "redirect:/offers/nu/" + nuOffer.getId(); - this.nuOfferService.saveNuOffer(nuOffer); - return "redirect:/offers/nu/" + nuOffer.getId(); - } @GetMapping(value = "/offers/nu/{nuOfferId}/activate") @@ -144,26 +149,25 @@ public class NuOfferController { } @GetMapping("/offers/nu/{nuOfferId}") - public String processShowForm(@PathVariable("nuOfferId") int nuOfferId, Map model) { + public String processShowForm(@PathVariable("nuOfferId") final int nuOfferId, final Map model) { NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); - if(nuOffer.getStatus().equals(StatusOffer.active)) { + if (nuOffer.getStatus().equals(StatusOffer.active)) { model.put("nuOffer", nuOffer); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); return "offers/nu/nuOffersShow"; - }else if(nuOffer.getStatus().equals(StatusOffer.hidden)&&(this.checkIdentity(nuOfferId))) { - model.put("nuOffer", nuOffer); - model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); - return "offers/nu/nuOffersShow"; - - }else { + } else if (nuOffer.getStatus().equals(StatusOffer.hidden) && this.checkIdentity(nuOfferId)) { + model.put("nuOffer", nuOffer); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "offers/nu/nuOffersShow"; + + } else { return "error"; } } @GetMapping(value = "/offers/nu/{nuOfferId}/edit") - public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap model, - HttpServletRequest request) { + public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap model, final HttpServletRequest request) { if (!this.checkIdentity(nuOfferId)) { return "error"; @@ -178,8 +182,7 @@ public class NuOfferController { } @PostMapping(value = "/offers/nu/{nuOfferId}/edit") - public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final ModelMap model, - HttpServletRequest request) { + public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final ModelMap model, final HttpServletRequest request) { if (!this.checkIdentity(nuOfferEdit.getId())) { return "error"; @@ -190,35 +193,32 @@ public class NuOfferController { return "error"; } - if(!this.checkDates(nuOfferEdit)) { - result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio"); - - } - if(!this.checkConditions(nuOfferEdit)) { - result.rejectValue("gold","" ,"Oro debe ser mayor o igual que plata, y plata mayor o igual que bronce"); - - } - if(!this.checkDiscounts(nuOfferEdit)) { - result.rejectValue("discountGold","" ,"El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce"); - - } - + if (!this.checkDates(nuOfferEdit)) { + result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio"); - if (result.hasErrors()) { - model.addAttribute("nuOffer", nuOfferEdit); - return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + } + if (!this.checkConditions(nuOfferEdit)) { + result.rejectValue("gold", "", "Oro debe ser mayor o igual que plata, y plata mayor o igual que bronce"); + + } + if (!this.checkDiscounts(nuOfferEdit)) { + result.rejectValue("discountGold", "", "El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce"); + + } + + if (result.hasErrors()) { + model.addAttribute("nuOffer", nuOfferEdit); + return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; + + } + BeanUtils.copyProperties(this.nuOfferService.findNuOfferById(nuOfferEdit.getId()), nuOfferEdit, "start", "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze"); + this.nuOfferService.saveNuOffer(nuOfferEdit); + return "redirect:/offers/nu/" + nuOfferEdit.getId(); - } - BeanUtils.copyProperties(this.nuOfferService.findNuOfferById(nuOfferEdit.getId()), nuOfferEdit, "start", - "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze"); - this.nuOfferService.saveNuOffer(nuOfferEdit); - return "redirect:/offers/nu/" + nuOfferEdit.getId(); - } @GetMapping(value = "/offers/nu/{nuOfferId}/disable") - public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, - final ModelMap model) { + public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { if (!this.checkIdentity(nuOfferId)) { return "error"; @@ -230,8 +230,7 @@ public class NuOfferController { } @PostMapping(value = "/offers/nu/{nuOfferId}/disable") - public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, - final ModelMap model) { + public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { if (!this.checkIdentity(nuOfferId)) { return "error"; diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index 2c30db007..6d532b9ac 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -43,9 +43,9 @@ public class OfertaController { Pageable elements = PageRequest.of(0, 3); List foodOfferLs = this.foodOfferService.findActiveFoodOffer(elements); - List nuOfferLs = this.nuOfferService.findActiveNuOffer(); - List speedOfferLs = this.speedOfferService.findActiveSpeedOffer(); - List timeOfferLs = this.timeOfferService.findActiveTimeOffer(); + List nuOfferLs = this.nuOfferService.findActiveNuOffer(elements); + List speedOfferLs = this.speedOfferService.findActiveSpeedOffer(elements); + List timeOfferLs = this.timeOfferService.findActiveTimeOffer(elements); model.put("foodOfferLs", foodOfferLs); model.put("nuOfferLs", nuOfferLs); diff --git a/src/main/java/org/springframework/cheapy/web/ReviewController.java b/src/main/java/org/springframework/cheapy/web/ReviewController.java index 0412db3cb..2514da8a7 100644 --- a/src/main/java/org/springframework/cheapy/web/ReviewController.java +++ b/src/main/java/org/springframework/cheapy/web/ReviewController.java @@ -1,3 +1,4 @@ + package org.springframework.cheapy.web; import java.util.List; @@ -9,6 +10,8 @@ import org.springframework.cheapy.model.Review; import org.springframework.cheapy.model.User; import org.springframework.cheapy.service.ReviewService; import org.springframework.cheapy.service.UserService; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; @@ -19,10 +22,10 @@ import org.springframework.web.bind.annotation.PostMapping; @Controller public class ReviewController { + private static final String VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM = "reviews/createOrUpdateReviewForm"; + private final ReviewService reviewService; + private final UserService userService; - private static final String VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM = "reviews/createOrUpdateReviewForm"; - private final ReviewService reviewService; - private final UserService userService; public ReviewController(final ReviewService reviewService, final UserService userService) { this.reviewService = reviewService; @@ -38,46 +41,44 @@ public class ReviewController { } return res; } - @GetMapping("/reviews") - public String processFindForm( Map model) { + @GetMapping("/reviewsList/{page}") + public String processFindForm(@PathVariable("page") final int page, final Map model) { + Pageable elements = PageRequest.of(page, 6); - List reviewsLs=this.reviewService.findAllReviews(); + List reviewsLs = this.reviewService.findAllReviews(elements); model.put("reviewsLs", reviewsLs); - + return "reviews/reviewsList"; } @GetMapping("/reviews/new") - public String initCreationForm(Map model) { + public String initCreationForm(final Map model) { Review review = new Review(); model.put("review", review); - return VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM; + return ReviewController.VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM; } @PostMapping("/reviews/new") - public String processCreationForm(@Valid Review review, BindingResult result) { + public String processCreationForm(@Valid final Review review, final BindingResult result) { if (result.hasErrors()) { - return VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM; + return ReviewController.VIEWS_REVIEWS_CREATE_OR_UPDATE_FORM; } else { User escritor = this.userService.getCurrentUser(); review.setEscritor(escritor); - + this.reviewService.saveReview(review); return "redirect:/reviews/" + review.getId(); } } - - @GetMapping("/reviews/{reviewId}") - public String processShowForm(@PathVariable("reviewId") int reviewId, Map model) { + public String processShowForm(@PathVariable("reviewId") final int reviewId, final Map model) { Review review = this.reviewService.findReviewById(reviewId); model.put("review", review); - - + return "reviews/reviewsShow"; } @@ -105,7 +106,7 @@ public class ReviewController { } else { User escritor = this.userService.getCurrentUser(); reviewEdit.setEscritor(escritor); - + this.reviewService.saveReview(reviewEdit); return "redirect:/reviews/" + reviewEdit.getId(); } diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java index bbf1372b6..4fae3d5ea 100644 --- a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -1,3 +1,4 @@ + package org.springframework.cheapy.web; import java.time.format.DateTimeFormatter; @@ -13,6 +14,8 @@ import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.SpeedOfferService; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; @@ -23,10 +26,11 @@ import org.springframework.web.bind.annotation.PostMapping; @Controller public class SpeedOfferController { - private static final String VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM = "offers/speed/createOrUpdateSpeedOfferForm"; + private static final String VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM = "offers/speed/createOrUpdateSpeedOfferForm"; + + private final SpeedOfferService speedOfferService; + private final ClientService clientService; - private final SpeedOfferService speedOfferService; - private final ClientService clientService; public SpeedOfferController(final SpeedOfferService speedOfferService, final ClientService clientService) { this.speedOfferService = speedOfferService; @@ -46,43 +50,44 @@ public class SpeedOfferController { private boolean checkOffer(final SpeedOffer session, final SpeedOffer offer) { boolean res = false; - if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() - && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) { + if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !session.getStatus().equals(StatusOffer.inactive)) { res = true; } return res; } - + private boolean checkDates(final SpeedOffer speedOffer) { boolean res = false; - if(speedOffer.getEnd()==null || speedOffer.getStart()==null || speedOffer.getEnd().isAfter(speedOffer.getStart())) { + if (speedOffer.getEnd() == null || speedOffer.getStart() == null || speedOffer.getEnd().isAfter(speedOffer.getStart())) { res = true; } return res; } - + private boolean checkConditions(final SpeedOffer speedOffer) { boolean res = false; - if(speedOffer.getGold()==null || speedOffer.getSilver()==null || speedOffer.getBronze()==null) { - - }else if(speedOffer.getGold() <= speedOffer.getSilver() && speedOffer.getSilver() <= speedOffer.getBronze()) { + if (speedOffer.getGold() == null || speedOffer.getSilver() == null || speedOffer.getBronze() == null) { + + } else if (speedOffer.getGold() <= speedOffer.getSilver() && speedOffer.getSilver() <= speedOffer.getBronze()) { res = true; } return res; } - + private boolean checkDiscounts(final SpeedOffer speedOffer) { boolean res = false; - if(speedOffer.getDiscountGold()==null || speedOffer.getDiscountSilver()==null || speedOffer.getDiscountBronze()==null) { - }else if(speedOffer.getDiscountGold() >= speedOffer.getDiscountSilver() && speedOffer.getDiscountSilver() >= speedOffer.getDiscountBronze()) { + if (speedOffer.getDiscountGold() == null || speedOffer.getDiscountSilver() == null || speedOffer.getDiscountBronze() == null) { + } else if (speedOffer.getDiscountGold() >= speedOffer.getDiscountSilver() && speedOffer.getDiscountSilver() >= speedOffer.getDiscountBronze()) { res = true; } return res; } - - @GetMapping("/offers/speedOfferList") - public String processFindForm(Map model) { - List speedOfferLs=this.speedOfferService.findActiveSpeedOffer(); + + @GetMapping("/offers/speedOfferList/{page}") + public String processFindForm(@PathVariable("page") final int page, final Map model) { + Pageable elements = PageRequest.of(page, 5); + + List speedOfferLs = this.speedOfferService.findActiveSpeedOffer(elements); model.put("speedOfferLs", speedOfferLs); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); return "offers/speed/speedOffersList"; @@ -90,42 +95,42 @@ public class SpeedOfferController { } @GetMapping("/offers/speed/new") - public String initCreationForm(Map model) { + public String initCreationForm(final Map model) { SpeedOffer speedOffer = new SpeedOffer(); model.put("speedOffer", speedOffer); - return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping("/offers/speed/new") - public String processCreationForm(@Valid SpeedOffer speedOffer, BindingResult result) { - - if(!this.checkDates(speedOffer)) { - result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio"); - - } - if(!this.checkConditions(speedOffer)) { - result.rejectValue("gold","" ,"Oro debe ser menor o igual que plata, y plata menor o igual que bronce"); - - } - if(!this.checkDiscounts(speedOffer)) { - result.rejectValue("discountGold","" ,"El descuento de Oro debe ser menor o igual que el de plata, y el de plata menor o igual que el de bronce"); - - } - - if (result.hasErrors()) { - return VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; - } - - Client client = this.clientService.getCurrentClient(); - speedOffer.setClient(client); - speedOffer.setStatus(StatusOffer.hidden); - this.speedOfferService.saveSpeedOffer(speedOffer); - return "redirect:/offers/speed/" + speedOffer.getId(); - + public String processCreationForm(@Valid final SpeedOffer speedOffer, final BindingResult result) { + + if (!this.checkDates(speedOffer)) { + result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio"); + + } + if (!this.checkConditions(speedOffer)) { + result.rejectValue("gold", "", "Oro debe ser menor o igual que plata, y plata menor o igual que bronce"); + + } + if (!this.checkDiscounts(speedOffer)) { + result.rejectValue("discountGold", "", "El descuento de Oro debe ser menor o igual que el de plata, y el de plata menor o igual que el de bronce"); + + } + + if (result.hasErrors()) { + return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + } + + Client client = this.clientService.getCurrentClient(); + speedOffer.setClient(client); + speedOffer.setStatus(StatusOffer.hidden); + this.speedOfferService.saveSpeedOffer(speedOffer); + return "redirect:/offers/speed/" + speedOffer.getId(); + } @GetMapping(value = "/offers/speed/{speedOfferId}/activate") - public String activateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, ModelMap modelMap) { + public String activateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap modelMap) { SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); Client client = this.clientService.getCurrentClient(); if (speedOffer.getClient().equals(client)) { @@ -139,24 +144,24 @@ public class SpeedOfferController { } @GetMapping("/offers/speed/{speedOfferId}") - public String processShowForm(@PathVariable("speedOfferId") int speedOfferId, Map model) { + public String processShowForm(@PathVariable("speedOfferId") final int speedOfferId, final Map model) { SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); - if(speedOffer.getStatus().equals(StatusOffer.active)) { + if (speedOffer.getStatus().equals(StatusOffer.active)) { model.put("speedOffer", speedOffer); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); return "offers/speed/speedOffersShow"; - }else if(speedOffer.getStatus().equals(StatusOffer.hidden)&&(this.checkIdentity(speedOfferId))) { - model.put("speedOffer", speedOffer); - model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); - return "offers/speed/speedOffersShow"; - - }else { + } else if (speedOffer.getStatus().equals(StatusOffer.hidden) && this.checkIdentity(speedOfferId)) { + model.put("speedOffer", speedOffer); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "offers/speed/speedOffersShow"; + + } else { return "error"; } } @GetMapping(value = "/offers/speed/{speedOfferId}/edit") - public String updateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model, HttpServletRequest request) { + public String updateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model, final HttpServletRequest request) { if (!this.checkIdentity(speedOfferId)) { return "error"; @@ -172,8 +177,7 @@ public class SpeedOfferController { } @PostMapping(value = "/offers/speed/{speedOfferId}/edit") - public String updateSpeedOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, - final ModelMap model, HttpServletRequest request) { + public String updateSpeedOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, final ModelMap model, final HttpServletRequest request) { if (!this.checkIdentity(speedOfferEdit.getId())) { return "error"; @@ -184,29 +188,27 @@ public class SpeedOfferController { return "error"; } - if(!this.checkDates(speedOfferEdit)) { - result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio"); - - } - if(!this.checkConditions(speedOfferEdit)) { - result.rejectValue("gold","" ,"Oro debe ser menor o igual que plata, y plata menor o igual que bronce"); - - } - if(!this.checkDiscounts(speedOfferEdit)) { - result.rejectValue("discountGold","" ,"El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce"); - - } - - if (result.hasErrors()) { - model.addAttribute("speedOffer", speedOfferEdit); - return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + if (!this.checkDates(speedOfferEdit)) { + result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio"); - } - BeanUtils.copyProperties(this.speedOfferService.findSpeedOfferById(speedOfferEdit.getId()), speedOfferEdit, - "start", "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze"); - this.speedOfferService.saveSpeedOffer(speedOfferEdit); - return "redirect:/offers/speed/" + speedOfferEdit.getId(); - + } + if (!this.checkConditions(speedOfferEdit)) { + result.rejectValue("gold", "", "Oro debe ser menor o igual que plata, y plata menor o igual que bronce"); + + } + if (!this.checkDiscounts(speedOfferEdit)) { + result.rejectValue("discountGold", "", "El descuento de Oro debe ser mayor o igual que el de plata, y el de plata mayor o igual que el de bronce"); + + } + + if (result.hasErrors()) { + model.addAttribute("speedOffer", speedOfferEdit); + return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; + + } + BeanUtils.copyProperties(this.speedOfferService.findSpeedOfferById(speedOfferEdit.getId()), speedOfferEdit, "start", "end", "gold", "discount_gold", "silver", "discount_silver", "bronze", "discount_bronze"); + this.speedOfferService.saveSpeedOffer(speedOfferEdit); + return "redirect:/offers/speed/" + speedOfferEdit.getId(); } diff --git a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java index 23480e3b7..a7d9f0c98 100644 --- a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java @@ -1,3 +1,4 @@ + package org.springframework.cheapy.web; import java.time.format.DateTimeFormatter; @@ -13,6 +14,8 @@ import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.service.ClientService; import org.springframework.cheapy.service.TimeOfferService; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; @@ -23,11 +26,12 @@ import org.springframework.web.bind.annotation.PostMapping; @Controller public class TimeOfferController { - private static final String VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM = "offers/time/createOrUpdateTimeOfferForm"; - private final TimeOfferService timeOfferService; - private final ClientService clientService; + private static final String VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM = "offers/time/createOrUpdateTimeOfferForm"; + private final TimeOfferService timeOfferService; + private final ClientService clientService; - public TimeOfferController(final TimeOfferService timeOfferService, ClientService clientService) { + + public TimeOfferController(final TimeOfferService timeOfferService, final ClientService clientService) { this.timeOfferService = timeOfferService; this.clientService = clientService; } @@ -45,32 +49,33 @@ public class TimeOfferController { private boolean checkOffer(final TimeOffer session, final TimeOffer offer) { boolean res = false; - if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() - && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !(session.getStatus().equals(StatusOffer.inactive))) { + if (session.getId() == offer.getId() && session.getStatus() == offer.getStatus() && (session.getCode() == null ? offer.getCode() == "" : session.getCode().equals(offer.getCode())) && !session.getStatus().equals(StatusOffer.inactive)) { res = true; } return res; } - + private boolean checkDates(final TimeOffer timeOffer) { boolean res = false; - if(timeOffer.getEnd()==null || timeOffer.getStart()==null || timeOffer.getEnd().isAfter(timeOffer.getStart())) { + if (timeOffer.getEnd() == null || timeOffer.getStart() == null || timeOffer.getEnd().isAfter(timeOffer.getStart())) { res = true; } return res; } - + private boolean checkTimes(final TimeOffer timeOffer) { boolean res = false; - if(timeOffer.getFinish()==null || timeOffer.getInit()==null || timeOffer.getFinish().isAfter(timeOffer.getInit())) { + if (timeOffer.getFinish() == null || timeOffer.getInit() == null || timeOffer.getFinish().isAfter(timeOffer.getInit())) { res = true; } return res; } - - @GetMapping("/offers/timeOfferList") - public String processFindForm(Map model) { - List timeOfferLs=this.timeOfferService.findActiveTimeOffer(); + + @GetMapping("/offers/timeOfferList/{page}") + public String processFindForm(@PathVariable("page") final int page, final Map model) { + Pageable elements = PageRequest.of(page, 5); + + List timeOfferLs = this.timeOfferService.findActiveTimeOffer(elements); model.put("timeOfferLs", timeOfferLs); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); return "offers/time/timeOffersList"; @@ -78,38 +83,38 @@ public class TimeOfferController { } @GetMapping("/offers/time/new") - public String initCreationForm(Map model) { + public String initCreationForm(final Map model) { TimeOffer timeOffer = new TimeOffer(); model.put("timeOffer", timeOffer); - return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; } @PostMapping("/offers/time/new") - public String processCreationForm(@Valid TimeOffer timeOffer, BindingResult result) { - - if(!this.checkDates(timeOffer)) { - result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio"); - - } - - if(!this.checkTimes(timeOffer)) { - result.rejectValue("finish","" ,"La hora de fin debe ser posterior a la de inicio"); - - } - - if (result.hasErrors()) { - return VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; - } - - timeOffer.setStatus(StatusOffer.hidden); + public String processCreationForm(@Valid final TimeOffer timeOffer, final BindingResult result) { - Client client = this.clientService.getCurrentClient(); + if (!this.checkDates(timeOffer)) { + result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio"); - timeOffer.setClient(client); + } + + if (!this.checkTimes(timeOffer)) { + result.rejectValue("finish", "", "La hora de fin debe ser posterior a la de inicio"); + + } + + if (result.hasErrors()) { + return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + } + + timeOffer.setStatus(StatusOffer.hidden); + + Client client = this.clientService.getCurrentClient(); + + timeOffer.setClient(client); + + this.timeOfferService.saveTimeOffer(timeOffer); + return "redirect:/offers/time/" + timeOffer.getId(); - this.timeOfferService.saveTimeOffer(timeOffer); - return "redirect:/offers/time/" + timeOffer.getId(); - } @GetMapping(value = "/offers/time/{timeOfferId}/activate") @@ -129,26 +134,25 @@ public class TimeOfferController { } @GetMapping("/offers/time/{timeOfferId}") - public String processShowForm(@PathVariable("timeOfferId") int timeOfferId, Map model) { + public String processShowForm(@PathVariable("timeOfferId") final int timeOfferId, final Map model) { TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); - if(timeOffer.getStatus().equals(StatusOffer.active)) { + if (timeOffer.getStatus().equals(StatusOffer.active)) { model.put("timeOffer", timeOffer); model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); return "offers/time/timeOffersShow"; - - } else if(timeOffer.getStatus().equals(StatusOffer.hidden)&&(this.checkIdentity(timeOfferId))) { - model.put("timeOffer", timeOffer); - model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); - return "offers/time/timeOffersShow"; - - }else { + + } else if (timeOffer.getStatus().equals(StatusOffer.hidden) && this.checkIdentity(timeOfferId)) { + model.put("timeOffer", timeOffer); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "offers/time/timeOffersShow"; + + } else { return "error"; } } @GetMapping(value = "/offers/time/{timeOfferId}/edit") - public String updateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model, - HttpServletRequest request) { + public String updateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model, final HttpServletRequest request) { if (!this.checkIdentity(timeOfferId)) { return "error"; @@ -164,8 +168,7 @@ public class TimeOfferController { } @PostMapping(value = "/offers/time/{timeOfferId}/edit") - public String updateTimeOffer(@Valid final TimeOffer timeOfferEdit, final BindingResult result, - final ModelMap model, HttpServletRequest request) { + public String updateTimeOffer(@Valid final TimeOffer timeOfferEdit, final BindingResult result, final ModelMap model, final HttpServletRequest request) { if (!this.checkIdentity(timeOfferEdit.getId())) { return "error"; @@ -176,26 +179,23 @@ public class TimeOfferController { return "error"; } - - if(!this.checkDates(timeOfferEdit)) { - result.rejectValue("end","" ,"La fecha de fin debe ser posterior a la fecha de inicio"); - - } - if(!this.checkTimes(timeOfferEdit)) { - result.rejectValue("finish","" ,"La hora de fin debe ser posterior a la de inicio"); - - } - if (result.hasErrors()) { - model.addAttribute("timeOffer", timeOfferEdit); - return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + if (!this.checkDates(timeOfferEdit)) { + result.rejectValue("end", "", "La fecha de fin debe ser posterior a la fecha de inicio"); - } - - BeanUtils.copyProperties(this.timeOfferService.findTimeOfferById(timeOfferEdit.getId()), timeOfferEdit, - "start", "end", "init", "finish", "discount"); - this.timeOfferService.saveTimeOffer(timeOfferEdit); - return "redirect:/offers/time/" + timeOfferEdit.getId(); - + } + if (!this.checkTimes(timeOfferEdit)) { + result.rejectValue("finish", "", "La hora de fin debe ser posterior a la de inicio"); + + } + if (result.hasErrors()) { + model.addAttribute("timeOffer", timeOfferEdit); + return TimeOfferController.VIEWS_TIME_OFFER_CREATE_OR_UPDATE_FORM; + + } + + BeanUtils.copyProperties(this.timeOfferService.findTimeOfferById(timeOfferEdit.getId()), timeOfferEdit, "start", "end", "init", "finish", "discount"); + this.timeOfferService.saveTimeOffer(timeOfferEdit); + return "redirect:/offers/time/" + timeOfferEdit.getId(); } diff --git a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersList.jsp index 2ca621bf4..06c8cc2f3 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/food/foodOffersList.jsp @@ -9,23 +9,34 @@ - + + - + + + + + - + + - - + + - +

@@ -80,6 +91,23 @@
+ + + + + + + + + + + + +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersList.jsp index d3a0725ce..87e79f081 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/nu/nuOffersList.jsp @@ -9,24 +9,35 @@ - + + - - + + - + + + + + - + + - +

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

@@ -77,6 +88,23 @@
+ + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp index db1b101a0..252fcf04c 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -9,34 +9,38 @@ - + + - - + + - - + + - - + + -

-

No hay ninguna oferta por plato específico activa.

+

No hay ninguna oferta por plato específico activa.

@@ -88,6 +92,9 @@
+
@@ -143,6 +150,9 @@ +
@@ -200,6 +210,10 @@ + +
@@ -254,9 +268,12 @@ - - + + + diff --git a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersList.jsp index 01a638bd0..ce01ceef1 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/speed/speedOffersList.jsp @@ -9,24 +9,35 @@ - + + - - + + - - + + - + + + + + +

No hay ninguna oferta por tiempo empleado en comer activa.

@@ -78,5 +89,22 @@ + + + + + + + + + + + + +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersList.jsp index f51d2a1f9..8ec8da295 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/time/timeOffersList.jsp @@ -9,23 +9,34 @@ - + + - - + + - - + + - + + + + + +

@@ -77,6 +88,23 @@ + + + + + + + + + + + + +
diff --git a/src/main/webapp/WEB-INF/jsp/reviews/reviewsList.jsp b/src/main/webapp/WEB-INF/jsp/reviews/reviewsList.jsp index f09f9dfd9..394e6fbbe 100644 --- a/src/main/webapp/WEB-INF/jsp/reviews/reviewsList.jsp +++ b/src/main/webapp/WEB-INF/jsp/reviews/reviewsList.jsp @@ -21,7 +21,7 @@ - + @@ -56,4 +56,21 @@ + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index 97f1d6ced..a56f8cf35 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -61,7 +61,7 @@ --> - + Reseñas From eddd00b5fd128143945be4ecfe13ec19eef34a9a Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 11 Apr 2021 13:02:57 +0200 Subject: [PATCH 16/21] Filtro por nombre --- .../repository/FoodOfferRepository.java | 5 + .../cheapy/repository/NuOfferRepository.java | 5 +- .../repository/SpeedOfferRepository.java | 4 + .../repository/TimeOfferRepository.java | 4 + .../cheapy/service/FoodOfferService.java | 5 + .../cheapy/service/NuOfferService.java | 5 + .../cheapy/service/SpeedOfferService.java | 5 + .../cheapy/service/TimeOfferService.java | 5 + .../cheapy/web/OfertaController.java | 19 ++ .../webapp/WEB-INF/jsp/offers/offersList.jsp | 8 + .../WEB-INF/jsp/offers/offersListSearch.jsp | 239 ++++++++++++++++++ 11 files changed, 303 insertions(+), 1 deletion(-) create mode 100644 src/main/webapp/WEB-INF/jsp/offers/offersListSearch.jsp diff --git a/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java index 5ee262df4..b1f335860 100644 --- a/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java @@ -34,4 +34,9 @@ public interface FoodOfferRepository extends PagingAndSortingRepository findFoodOfferActOclByUserId(@Param("id") Integer id); + + @Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.name LIKE :name AND foodOffer.status= 'active'") + @Transactional(readOnly = true) + List findFoodOfferByClientName(String name); + } diff --git a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java index 7cc4b8335..ccd04b4e1 100644 --- a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java @@ -2,7 +2,6 @@ package org.springframework.cheapy.repository; import java.util.List; - import org.springframework.cheapy.model.NuOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.data.domain.Pageable; @@ -32,4 +31,8 @@ public interface NuOfferRepository extends PagingAndSortingRepository findNuOfferActOclByUserId(@Param("id") Integer id); + + @Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.name LIKE :name AND nuOffer.status= 'active'") + @Transactional(readOnly = true) + List findNuOfferByClientName(String name); } diff --git a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java index cb49d2b0a..1dd6203ba 100644 --- a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java @@ -34,4 +34,8 @@ public interface SpeedOfferRepository extends PagingAndSortingRepository findSpeedOfferActOclByUserId(@Param("id") Integer id); + + @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.name LIKE :name AND speedOffer.status= 'active'") + @Transactional(readOnly = true) + List findSpeedOfferByClientName(String name); } diff --git a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java index 77ada9fcb..8e14162bf 100644 --- a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java @@ -33,4 +33,8 @@ public interface TimeOfferRepository extends PagingAndSortingRepository findTimeOfferActOclByUserId(@Param("id") Integer id); + + @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.name LIKE :name AND timeOffer.status= 'active'") + @Transactional(readOnly = true) + List findTimeOfferByClientName(String name); } diff --git a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java index 79b98b494..4a17c91ae 100644 --- a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java @@ -45,4 +45,9 @@ public class FoodOfferService { public List findFoodOfferActOclByUserId(final int id) { return this.foodOfferRepository.findFoodOfferActOclByUserId(id); } + + public List findFoodOfferByClientName(String name) { + String nameEdit = "%"+name+"%"; + return this.foodOfferRepository.findFoodOfferByClientName(nameEdit); + } } diff --git a/src/main/java/org/springframework/cheapy/service/NuOfferService.java b/src/main/java/org/springframework/cheapy/service/NuOfferService.java index 2812df07b..b6d4ca743 100644 --- a/src/main/java/org/springframework/cheapy/service/NuOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/NuOfferService.java @@ -54,4 +54,9 @@ public class NuOfferService { public List findNuOfferActOclByUserId(final int id) { return this.nuOfferRepository.findNuOfferActOclByUserId(id); } + + public List findNuOfferByClientName(String name) { + String nameEdit = "%"+name+"%"; + return this.nuOfferRepository.findNuOfferByClientName(nameEdit); + } } diff --git a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java index 2827c0b0c..ad76224be 100644 --- a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java @@ -49,4 +49,9 @@ public class SpeedOfferService { public List findSpeedOfferActOclByUserId(final int id) { return this.speedOfferRepository.findSpeedOfferActOclByUserId(id); } + + public List findSpeedOfferByClientName(String name) { + String nameEdit = "%"+name+"%"; + return this.speedOfferRepository.findSpeedOfferByClientName(nameEdit); + } } diff --git a/src/main/java/org/springframework/cheapy/service/TimeOfferService.java b/src/main/java/org/springframework/cheapy/service/TimeOfferService.java index 8b7b6ebda..7f35930a8 100644 --- a/src/main/java/org/springframework/cheapy/service/TimeOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/TimeOfferService.java @@ -45,4 +45,9 @@ public class TimeOfferService { public List findTimeOfferActOclByUserId(final int id) { return this.timeOfferRepository.findTimeOfferActOclByUserId(id); } + + public List findTimeOfferByClientName(String name) { + String nameEdit = "%"+name+"%"; + return this.timeOfferRepository.findTimeOfferByClientName(nameEdit); + } } diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index 6d532b9ac..ec3db1b30 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -58,6 +58,25 @@ public class OfertaController { return "offers/offersList"; } + + @GetMapping("/offersByName") + public String processFindFormByName(final Map model, String name) { + + List foodOfferLs = this.foodOfferService.findFoodOfferByClientName(name); + List nuOfferLs = this.nuOfferService.findNuOfferByClientName(name); + List speedOfferLs = this.speedOfferService.findSpeedOfferByClientName(name); + List timeOfferLs = this.timeOfferService.findTimeOfferByClientName(name); + model.put("foodOfferLs", foodOfferLs); + model.put("nuOfferLs", nuOfferLs); + model.put("speedOfferLs", speedOfferLs); + model.put("timeOfferLs", timeOfferLs); + + //Se añade formateador de fecha al modelo + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + + return "offers/offersListSearch"; + + } @GetMapping("/myOffers") public String processMyOffersForm(final Map model) { diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp index 252fcf04c..7efb2bdb7 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -5,6 +5,7 @@ <%@ 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" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> @@ -36,6 +37,13 @@ + + +
+ + +
+

diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersListSearch.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersListSearch.jsp new file mode 100644 index 000000000..65fc09f67 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/offers/offersListSearch.jsp @@ -0,0 +1,239 @@ +<%@ 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" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + + +

+ + +

No hay ninguna oferta por plato específico activa.

+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+
+
+ +
+

+ +

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

+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+
+
+ +
+ +

+ +

No hay ninguna oferta por tiempo empleado en comer activa.

+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+
+
+ +
+ +

+ +

No hay ninguna oferta por franja horaria activa.

+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+ +
+
+
+
+ + +
From a26c2314e1a7e62a1a00a9b0cc57ebd0edd1fea6 Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 11 Apr 2021 17:02:24 +0200 Subject: [PATCH 17/21] Filtro por tipo de comida --- .../repository/FoodOfferRepository.java | 4 ++++ .../cheapy/repository/NuOfferRepository.java | 4 ++++ .../repository/SpeedOfferRepository.java | 4 ++++ .../repository/TimeOfferRepository.java | 4 ++++ .../cheapy/service/FoodOfferService.java | 5 +++++ .../cheapy/service/NuOfferService.java | 5 +++++ .../cheapy/service/SpeedOfferService.java | 5 +++++ .../cheapy/service/TimeOfferService.java | 5 +++++ .../cheapy/web/OfertaController.java | 19 +++++++++++++++++++ .../webapp/WEB-INF/jsp/offers/offersList.jsp | 5 +++++ 10 files changed, 60 insertions(+) diff --git a/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java index b1f335860..9a277197d 100644 --- a/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/FoodOfferRepository.java @@ -39,4 +39,8 @@ public interface FoodOfferRepository extends PagingAndSortingRepository findFoodOfferByClientName(String name); + @Query("SELECT foodOffer FROM FoodOffer foodOffer WHERE foodOffer.client.food LIKE :name AND foodOffer.status= 'active'") + @Transactional(readOnly = true) + List findFoodOfferByClientFood(String name); + } diff --git a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java index ccd04b4e1..d5631928e 100644 --- a/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/NuOfferRepository.java @@ -35,4 +35,8 @@ public interface NuOfferRepository extends PagingAndSortingRepository findNuOfferByClientName(String name); + + @Query("SELECT nuOffer FROM NuOffer nuOffer WHERE nuOffer.client.food LIKE :name AND nuOffer.status= 'active'") + @Transactional(readOnly = true) + List findNuOfferByClientFood(String name); } diff --git a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java index 1dd6203ba..b89ce1569 100644 --- a/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/SpeedOfferRepository.java @@ -38,4 +38,8 @@ public interface SpeedOfferRepository extends PagingAndSortingRepository findSpeedOfferByClientName(String name); + + @Query("SELECT speedOffer FROM SpeedOffer speedOffer WHERE speedOffer.client.food LIKE :name AND speedOffer.status= 'active'") + @Transactional(readOnly = true) + List findSpeedOfferByClientFood(String name); } diff --git a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java index 8e14162bf..b031d789c 100644 --- a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java @@ -37,4 +37,8 @@ public interface TimeOfferRepository extends PagingAndSortingRepository findTimeOfferByClientName(String name); + + @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.client.food LIKE :name AND timeOffer.status= 'active'") + @Transactional(readOnly = true) + List findTimeOfferByClientFood(String name); } diff --git a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java index 4a17c91ae..eb0a85b14 100644 --- a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java @@ -50,4 +50,9 @@ public class FoodOfferService { String nameEdit = "%"+name+"%"; return this.foodOfferRepository.findFoodOfferByClientName(nameEdit); } + + public List findFoodOfferByClientFood(String name) { + String nameEdit = "%"+name+"%"; + return this.foodOfferRepository.findFoodOfferByClientFood(nameEdit); + } } diff --git a/src/main/java/org/springframework/cheapy/service/NuOfferService.java b/src/main/java/org/springframework/cheapy/service/NuOfferService.java index b6d4ca743..be77144c1 100644 --- a/src/main/java/org/springframework/cheapy/service/NuOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/NuOfferService.java @@ -59,4 +59,9 @@ public class NuOfferService { String nameEdit = "%"+name+"%"; return this.nuOfferRepository.findNuOfferByClientName(nameEdit); } + + public List findNuOfferByClientFood(String name) { + String nameEdit = "%"+name+"%"; + return this.nuOfferRepository.findNuOfferByClientFood(nameEdit); + } } diff --git a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java index ad76224be..b9e5ffc2a 100644 --- a/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/SpeedOfferService.java @@ -54,4 +54,9 @@ public class SpeedOfferService { String nameEdit = "%"+name+"%"; return this.speedOfferRepository.findSpeedOfferByClientName(nameEdit); } + + public List findSpeedOfferByClientFood(String name) { + String nameEdit = "%"+name+"%"; + return this.speedOfferRepository.findSpeedOfferByClientFood(nameEdit); + } } diff --git a/src/main/java/org/springframework/cheapy/service/TimeOfferService.java b/src/main/java/org/springframework/cheapy/service/TimeOfferService.java index 7f35930a8..4859bca53 100644 --- a/src/main/java/org/springframework/cheapy/service/TimeOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/TimeOfferService.java @@ -50,4 +50,9 @@ public class TimeOfferService { String nameEdit = "%"+name+"%"; return this.timeOfferRepository.findTimeOfferByClientName(nameEdit); } + + public List findTimeOfferByClientFood(String name) { + String nameEdit = "%"+name+"%"; + return this.timeOfferRepository.findTimeOfferByClientFood(nameEdit); + } } diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index ec3db1b30..b2b302cf9 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -77,6 +77,25 @@ public class OfertaController { return "offers/offersListSearch"; } + + @GetMapping("/offersByFood") + public String processFindFormByFood(final Map model, String name) { + + List foodOfferLs = this.foodOfferService.findFoodOfferByClientFood(name); + List nuOfferLs = this.nuOfferService.findNuOfferByClientFood(name); + List speedOfferLs = this.speedOfferService.findSpeedOfferByClientFood(name); + List timeOfferLs = this.timeOfferService.findTimeOfferByClientFood(name); + model.put("foodOfferLs", foodOfferLs); + model.put("nuOfferLs", nuOfferLs); + model.put("speedOfferLs", speedOfferLs); + model.put("timeOfferLs", timeOfferLs); + + //Se añade formateador de fecha al modelo + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + + return "offers/offersListSearch"; + + } @GetMapping("/myOffers") public String processMyOffersForm(final Map model) { diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp index 7efb2bdb7..1bef89a39 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -44,6 +44,11 @@ +
+ + +
+

From e27ecdbf91d175cf79a903050746a260f6ad70f3 Mon Sep 17 00:00:00 2001 From: Thiloparn <48439369+Thiloparn@users.noreply.github.com> Date: Sun, 11 Apr 2021 17:57:03 +0200 Subject: [PATCH 18/21] 029 Done --- .../springframework/cheapy/repository/UsuarioRepository.java | 4 ++++ .../org/springframework/cheapy/service/UsuarioService.java | 5 +++++ .../springframework/cheapy/web/AdministratorController.java | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java index 87b11c04d..54402bb9b 100644 --- a/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/UsuarioRepository.java @@ -17,6 +17,10 @@ public interface UsuarioRepository extends Repository { @Transactional(readOnly = true) List findAllUsuario(); + @Query("SELECT usuario FROM Usuario usuario WHERE usuario.usuar.enabled = true") + @Transactional(readOnly = true) + List findUsuarioEnabled(); + void save(Usuario usuario); } diff --git a/src/main/java/org/springframework/cheapy/service/UsuarioService.java b/src/main/java/org/springframework/cheapy/service/UsuarioService.java index 5c994342d..b1b69236e 100644 --- a/src/main/java/org/springframework/cheapy/service/UsuarioService.java +++ b/src/main/java/org/springframework/cheapy/service/UsuarioService.java @@ -39,6 +39,11 @@ public class UsuarioService { public List findAllUsuario() throws DataAccessException { return this.usuarioRepository.findAllUsuario(); } + + @Transactional + public List findUsuarioEnabled() throws DataAccessException { + return this.usuarioRepository.findUsuarioEnabled(); + } @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 index d5e001f77..8dcec26fb 100644 --- a/src/main/java/org/springframework/cheapy/web/AdministratorController.java +++ b/src/main/java/org/springframework/cheapy/web/AdministratorController.java @@ -30,7 +30,7 @@ public class AdministratorController { @GetMapping("/administrators/usuarios") public String processFindUsuariosForm(Map model) { - List usuarioLs = this.usuarioService.findAllUsuario(); + List usuarioLs = this.usuarioService.findUsuarioEnabled(); model.put("usuarioLs", usuarioLs); return "usuarios/usuariosList"; } From 82ab37993471a7e1fc2d4ad8665a696ae190e5f9 Mon Sep 17 00:00:00 2001 From: abemorcardc Date: Sun, 11 Apr 2021 17:58:18 +0200 Subject: [PATCH 19/21] =?UTF-8?q?A=C3=B1adido=20funcionalidad=20de=20admin?= =?UTF-8?q?=20activa=20cliente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cheapy/web/AdministratorController.java | 16 ++++++++++++ .../WEB-INF/jsp/clients/clientActivate.jsp | 25 +++++++++++++++++++ .../webapp/WEB-INF/jsp/clients/clientShow.jsp | 14 +++++++++-- 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp diff --git a/src/main/java/org/springframework/cheapy/web/AdministratorController.java b/src/main/java/org/springframework/cheapy/web/AdministratorController.java index d5e001f77..82571e5f8 100644 --- a/src/main/java/org/springframework/cheapy/web/AdministratorController.java +++ b/src/main/java/org/springframework/cheapy/web/AdministratorController.java @@ -89,4 +89,20 @@ public class AdministratorController { this.clientService.saveClient(client); return "redirect:/administrators/clients"; } + + @GetMapping(value = "/administrators/clients/{username}/activate") + public String activateClient(@PathVariable("username") final String username, final ModelMap model) { + + Client client = this.clientService.findByUsername(username); + model.put("client", client); + return "clients/clientActivate"; + } + @PostMapping(value = "/administrators/clients/{username}/activate") + public String activateClientForm(@PathVariable("username") final String username, final ModelMap model, final HttpServletRequest request) { + + Client client = this.clientService.findByUsername(username); + client.getUsuar().setEnabled(true); + this.clientService.saveClient(client); + return "redirect:/administrators/clients"; + } } diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp new file mode 100644 index 000000000..07f6e365d --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp @@ -0,0 +1,25 @@ +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> + + + + +

¿Está seguro de que quiere activar esta cuenta?

+ + + +
+ +
+
+ +
+ +
diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp index e83809451..d3e07db78 100644 --- a/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp @@ -69,16 +69,26 @@ Borrar cliente
- +
- + + + + + + + + +
From 38ef66723a263913d4c8a57d405ff49018c9e592 Mon Sep 17 00:00:00 2001 From: abemorcardc Date: Sun, 11 Apr 2021 18:07:38 +0200 Subject: [PATCH 20/21] =?UTF-8?q?Revert=20"A=C3=B1adido=20funcionalidad=20?= =?UTF-8?q?de=20admin=20activa=20cliente"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 82ab37993471a7e1fc2d4ad8665a696ae190e5f9. --- .../cheapy/web/AdministratorController.java | 16 ------------ .../WEB-INF/jsp/clients/clientActivate.jsp | 25 ------------------- .../webapp/WEB-INF/jsp/clients/clientShow.jsp | 14 ++--------- 3 files changed, 2 insertions(+), 53 deletions(-) delete mode 100644 src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp diff --git a/src/main/java/org/springframework/cheapy/web/AdministratorController.java b/src/main/java/org/springframework/cheapy/web/AdministratorController.java index 82571e5f8..d5e001f77 100644 --- a/src/main/java/org/springframework/cheapy/web/AdministratorController.java +++ b/src/main/java/org/springframework/cheapy/web/AdministratorController.java @@ -89,20 +89,4 @@ public class AdministratorController { this.clientService.saveClient(client); return "redirect:/administrators/clients"; } - - @GetMapping(value = "/administrators/clients/{username}/activate") - public String activateClient(@PathVariable("username") final String username, final ModelMap model) { - - Client client = this.clientService.findByUsername(username); - model.put("client", client); - return "clients/clientActivate"; - } - @PostMapping(value = "/administrators/clients/{username}/activate") - public String activateClientForm(@PathVariable("username") final String username, final ModelMap model, final HttpServletRequest request) { - - Client client = this.clientService.findByUsername(username); - client.getUsuar().setEnabled(true); - this.clientService.saveClient(client); - return "redirect:/administrators/clients"; - } } diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp deleted file mode 100644 index 07f6e365d..000000000 --- a/src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp +++ /dev/null @@ -1,25 +0,0 @@ -<%@ page session="false" trimDirectiveWhitespaces="true"%> -<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> -<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> -<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> - - - - -

¿Está seguro de que quiere activar esta cuenta?

- - - -
- -
-
- -
- -
diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp index d3e07db78..e83809451 100644 --- a/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp @@ -69,26 +69,16 @@ Borrar cliente
- +
- + - - - - - - - -
From 5c0bd1f01550ff9bb66bcaffbb6ee91284440bbe Mon Sep 17 00:00:00 2001 From: abemorcardc Date: Sun, 11 Apr 2021 18:37:24 +0200 Subject: [PATCH 21/21] Admin activa cliente funcional y correccion admin desactiva cliente --- .../cheapy/web/AdministratorController.java | 52 ++++++++++++++++++- .../WEB-INF/jsp/clients/clientActivate.jsp | 25 +++++++++ .../webapp/WEB-INF/jsp/clients/clientShow.jsp | 11 ++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp diff --git a/src/main/java/org/springframework/cheapy/web/AdministratorController.java b/src/main/java/org/springframework/cheapy/web/AdministratorController.java index d5e001f77..adceea025 100644 --- a/src/main/java/org/springframework/cheapy/web/AdministratorController.java +++ b/src/main/java/org/springframework/cheapy/web/AdministratorController.java @@ -6,8 +6,17 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.cheapy.model.Client; +import org.springframework.cheapy.model.FoodOffer; +import org.springframework.cheapy.model.NuOffer; +import org.springframework.cheapy.model.SpeedOffer; +import org.springframework.cheapy.model.StatusOffer; +import org.springframework.cheapy.model.TimeOffer; import org.springframework.cheapy.model.Usuario; import org.springframework.cheapy.service.ClientService; +import org.springframework.cheapy.service.FoodOfferService; +import org.springframework.cheapy.service.NuOfferService; +import org.springframework.cheapy.service.SpeedOfferService; +import org.springframework.cheapy.service.TimeOfferService; import org.springframework.cheapy.service.UsuarioService; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; @@ -22,10 +31,21 @@ public class AdministratorController { private final UsuarioService usuarioService; private final ClientService clientService; + + private final FoodOfferService foodOfferService; + private final SpeedOfferService speedOfferService; + private final NuOfferService nuOfferService; + private final TimeOfferService timeOfferService; - public AdministratorController(final UsuarioService usuarioService, ClientService clientService) { + public AdministratorController(final UsuarioService usuarioService, ClientService clientService, + FoodOfferService foodOfferService, SpeedOfferService speedOfferService, NuOfferService nuOfferService, + TimeOfferService timeOfferService ) { this.usuarioService = usuarioService; this.clientService=clientService; + this.foodOfferService=foodOfferService; + this.speedOfferService=speedOfferService; + this.nuOfferService=nuOfferService; + this.timeOfferService=timeOfferService; } @GetMapping("/administrators/usuarios") @@ -86,6 +106,36 @@ public class AdministratorController { Client client = this.clientService.findByUsername(username); client.getUsuar().setEnabled(false); + + List foodOffers=this.foodOfferService.findFoodOfferByUserId(client.getId()); + List speedOffers=this.speedOfferService.findSpeedOfferByUserId(client.getId()); + List nuOffers=this.nuOfferService.findNuOfferByUserId(client.getId()); + List timeOffers=this.timeOfferService.findTimeOfferByUserId(client.getId()); + + foodOffers.stream().forEach(f->f.setStatus(StatusOffer.inactive)); + + speedOffers.stream().forEach(s->s.setStatus(StatusOffer.inactive)); + + nuOffers.stream().forEach(n->n.setStatus(StatusOffer.inactive)); + + timeOffers.stream().forEach(t->t.setStatus(StatusOffer.inactive)); + + this.clientService.saveClient(client); + return "redirect:/administrators/clients"; + } + + @GetMapping(value = "/administrators/clients/{username}/activate") + public String activateClient(@PathVariable("username") final String username, final ModelMap model) { + + Client client = this.clientService.findByUsername(username); + model.put("client", client); + return "clients/clientActivate"; + } + @PostMapping(value = "/administrators/clients/{username}/activate") + public String activateClientForm(@PathVariable("username") final String username, final ModelMap model, final HttpServletRequest request) { + + Client client = this.clientService.findByUsername(username); + client.getUsuar().setEnabled(true); this.clientService.saveClient(client); return "redirect:/administrators/clients"; } diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp new file mode 100644 index 000000000..43b68b4b3 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp @@ -0,0 +1,25 @@ +<%@ page session="false" trimDirectiveWhitespaces="true"%> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags"%> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> + + + + +

¿Está seguro de que quiere activar esta cuenta?

+ + + +
+ +
+
+ +
+ +
\ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp b/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp index e83809451..8b865dd99 100644 --- a/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/clients/clientShow.jsp @@ -73,12 +73,23 @@
+ + + + + + + + +