From 5c0bd1f01550ff9bb66bcaffbb6ee91284440bbe Mon Sep 17 00:00:00 2001 From: abemorcardc Date: Sun, 11 Apr 2021 18:37:24 +0200 Subject: [PATCH] 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 @@
+ + + + + + + + +