You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
3.5 KiB
143 lines
3.5 KiB
package api.menu.playa.controller;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import org.eclipse.microprofile.jwt.JsonWebToken;
|
|
|
|
import api.menu.playa.exceptions.NegocioException;
|
|
import api.menu.playa.helper.OrdenHelper;
|
|
import api.menu.playa.vo.CambioCantidadVO;
|
|
import api.menu.playa.vo.OrdenVO;
|
|
import api.menu.playa.vo.PagadoVO;
|
|
import api.menu.playa.vo.ProductoIdVO;
|
|
import api.menu.playa.vo.ResponseGlobal;
|
|
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
import javax.annotation.security.PermitAll;
|
|
import javax.annotation.security.RolesAllowed;
|
|
import javax.enterprise.context.RequestScoped;
|
|
import javax.inject.Inject;
|
|
import javax.ws.rs.Consumes;
|
|
import javax.ws.rs.GET;
|
|
import javax.ws.rs.POST;
|
|
import javax.ws.rs.Path;
|
|
import javax.ws.rs.PathParam;
|
|
import javax.ws.rs.Produces;
|
|
|
|
@RequestScoped
|
|
@Path("/order")
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
public class OrdenController {
|
|
|
|
private static final String SUCCESS = "SUCCESS";
|
|
//private static final String ERROR = "ERROR";
|
|
|
|
//@Inject
|
|
//JsonWebToken jwt;
|
|
|
|
|
|
@Inject
|
|
OrdenHelper ordenHelper;
|
|
|
|
/*
|
|
* Creacion de orden
|
|
*/
|
|
|
|
//@RolesAllowed({"USER", "ADMIN"})
|
|
@GET
|
|
@Path("/create")
|
|
public Response create() {
|
|
|
|
Long id = ordenHelper.creacion();
|
|
|
|
return Response.ok(new ResponseGlobal<>(0, SUCCESS, id)).build();
|
|
}
|
|
|
|
@RolesAllowed({"USER", "ADMIN"})
|
|
@POST
|
|
@Path("/status")
|
|
public Response status(PagadoVO vo) {
|
|
|
|
try {
|
|
ordenHelper.actualizarOrden(vo);
|
|
return Response.ok(new ResponseGlobal<>(0, SUCCESS)).build();
|
|
} catch (NegocioException e) {
|
|
return Response.ok(new ResponseGlobal<>(e.getCode(), e.getMessage())).build();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
* Agregar nuevo producto a la orden
|
|
*/
|
|
|
|
@RolesAllowed({"USER", "ADMIN"})
|
|
@POST
|
|
@Path("/add")
|
|
public Response add(ProductoIdVO vo) {
|
|
|
|
try {
|
|
ordenHelper.agregar(vo);
|
|
return Response.ok(new ResponseGlobal<>(0, SUCCESS)).build();
|
|
} catch (NegocioException e) {
|
|
return Response.ok(new ResponseGlobal<>(e.getCode(), e.getMessage())).build();
|
|
}
|
|
|
|
}
|
|
|
|
@RolesAllowed({"USER", "ADMIN"})
|
|
@POST
|
|
@Path("/detail")
|
|
public Response detail( CambioCantidadVO vo) {
|
|
|
|
//Optional<String> userOptional = jwt.claim("preferred_username");
|
|
|
|
try {
|
|
ordenHelper.cambiar(vo);
|
|
return Response.ok(new ResponseGlobal<>(0, SUCCESS)).build();
|
|
} catch (NegocioException e) {
|
|
return Response.ok(new ResponseGlobal<>(e.getCode(), e.getMessage())).build();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
* Obtener todas las ordenes
|
|
*/
|
|
@RolesAllowed({"USER", "ADMIN"})
|
|
@GET
|
|
@Path("/getall")
|
|
public Response getAll() {
|
|
|
|
List<OrdenVO> ordenes = ordenHelper.obtenerTodo();
|
|
|
|
return Response.ok(new ResponseGlobal<>(0, SUCCESS, ordenes)).build();
|
|
}
|
|
|
|
@RolesAllowed({"USER", "ADMIN"})
|
|
@GET
|
|
@Path("/get/{id}")
|
|
public Response get(@PathParam("id") Long id) {
|
|
|
|
OrdenVO orden = ordenHelper.obtener(id);
|
|
|
|
return Response.ok(new ResponseGlobal<>(0, SUCCESS, orden)).build();
|
|
}
|
|
|
|
@PermitAll
|
|
@GET
|
|
@Path("/getall/pedidos")
|
|
public Response getAllPrdidos() {
|
|
|
|
List<OrdenVO> ordenes = ordenHelper.obtenerPedidos();
|
|
|
|
return Response.ok(new ResponseGlobal<>(0, SUCCESS, ordenes)).build();
|
|
}
|
|
|
|
}
|
|
|