mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 15:55:49 +00:00
Admin activa cliente funcional y correccion admin desactiva cliente
This commit is contained in:
parent
4597e3ae85
commit
5c0bd1f015
3 changed files with 87 additions and 1 deletions
|
@ -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<FoodOffer> foodOffers=this.foodOfferService.findFoodOfferByUserId(client.getId());
|
||||
List<SpeedOffer> speedOffers=this.speedOfferService.findSpeedOfferByUserId(client.getId());
|
||||
List<NuOffer> nuOffers=this.nuOfferService.findNuOfferByUserId(client.getId());
|
||||
List<TimeOffer> 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";
|
||||
}
|
||||
|
|
25
src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp
Normal file
25
src/main/webapp/WEB-INF/jsp/clients/clientActivate.jsp
Normal file
|
@ -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" %>
|
||||
|
||||
<cheapy:layout pageName="client">
|
||||
|
||||
<jsp:body>
|
||||
<h2 class="text-center" style="font-family: 'Lobster'; font-size: 30px; color: rgb(0, 64, 128); padding:30px"><em>¿Está seguro de que quiere activar esta cuenta?</em></h2>
|
||||
|
||||
<form:form modelAttribute="client" class="form-horizontal">
|
||||
|
||||
<div class="btns-edit2">
|
||||
<button type="submit" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon glyphicon-trash" aria-hidden="true" style="padding: 5px"> </span>
|
||||
Activar</button>
|
||||
</div>
|
||||
</form:form>
|
||||
|
||||
</jsp:body>
|
||||
|
||||
</cheapy:layout>
|
|
@ -73,12 +73,23 @@
|
|||
<sec:authentication var="principal" property="principal" />
|
||||
<div class="btns-edit">
|
||||
|
||||
<c:if test="${ client.usuar.enabled eq true}">
|
||||
<spring:url value="/administrators/clients/{username}/disable" var="deactivateUrl">
|
||||
<spring:param name="username" value="${client.usuar.username}"/>
|
||||
</spring:url>
|
||||
<button type="button" role="link" onclick="window.location='${fn:escapeXml(deactivateUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon glyphicon-trash" aria-hidden="true" style="padding: 5px"> </span>
|
||||
Desactivar cliente</button>
|
||||
</c:if>
|
||||
|
||||
<c:if test="${ client.usuar.enabled eq false}">
|
||||
<spring:url value="/administrators/clients/{username}/activate" var="activateUrl">
|
||||
<spring:param name="username" value="${client.usuar.username}"/>
|
||||
</spring:url>
|
||||
<button type="button" role="link" onclick="window.location='${fn:escapeXml(activateUrl)}'" style="font-family: 'Lobster'; font-size: 20px;">
|
||||
<span class="glyphicon glyphicon glyphicon-trash" aria-hidden="true" style="padding: 5px"> </span>
|
||||
Activar cliente</button>
|
||||
</c:if>
|
||||
</div>
|
||||
</sec:authorize>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue