// remove photo api @Override @DELETE @Path("/remove") @Produces(MediaType.APPLICATION_XML) @Transactional(propagation = Propagation.NESTED) public Response removePhoto(Integer photoId, @Context HttpServletRequest request) { try { Photo photo = photoDao.load(photoId); Token tokenObj = (Token) request.getAttribute("token"); User user = tokenObj.getUser(); if (user.equals(photo.getUser())) { new File(photo.getPath()).delete(); // delete the file photoDao.delete(photo); } GetPhotoResponseDTO dto = buildDTO(200, null); dto.setImageId(photoId); return Response.status(200).entity(dto).build(); } catch (HibernateException e) { e.printStackTrace(); return Response.status(500).entity(buildDTO(500, null)).build(); } }
private GetPhotoResponseDTO buildDTO(int b, List<String> idList) { GetPhotoResponseDTO dto = new GetPhotoResponseDTO(); ErrorDTO error = dto.getErrorDTO(); switch (b) { case 200: error = new ErrorDTO(b, "OK"); break; case 500: error = new ErrorDTO(b, "Internal Error"); break; default: break; } dto.setErrorDTO(error); if (idList != null) for (String s : idList) { dto.getPhoto().add(s); } return dto; }