@POST @Path("{id}/imagenes/create") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response addImages(@PathParam(value = "id") Long id, List<String> images) { try { Producto p = em.find(Producto.class, id); List<String> images_old = new ArrayList<>(); if (p.getTags() != null && !p.getTags().equals("")) { images_old = Arrays.asList(p.getImagenes().split(",")); } HashSet<String> set = new HashSet<>(images_old); set.addAll(images); String joined = String.join(",", set); p.setImagenes(joined); // MONGO DataProducto dp = p.getDataProducto(); new MongoController().upsertProduct(dp); return Response.status(200).entity(dp).build(); } catch (Exception e) { e.printStackTrace(); DataResponse dr = new DataResponse(); dr.setMensaje("Error agregar imagenes"); dr.setDescripcion("Problema en mongodb"); return Response.status(500).entity(dr).build(); } }
@POST @Path("{id}/tags/remove") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response removeTag(@PathParam(value = "id") Long id, List<String> tag) { Producto p = em.find(Producto.class, id); List<String> tags_old = new ArrayList<>(); if (p.getTags() != null && !p.getTags().equals("")) { tags_old = Arrays.asList(p.getTags().split(",")); } HashSet<String> set = new HashSet<>(tags_old); set.removeAll(tag); String joined = String.join(",", set); p.setTags(joined); // Mongo DataProducto dp = p.getDataProducto(); new MongoController().upsertProduct(dp); return Response.status(200).entity(tag).build(); }