private void setLike(long id, String user, HttpServletResponse res, boolean isLike) { Video v = videos.findOne(id); int code = HttpServletResponse.SC_OK; if (v == null) { code = HttpServletResponse.SC_NOT_FOUND; } else { if (isLike ? v.addLikedUser(user) : v.removeLikedUser(user)) { videos.save(v); } else { code = HttpServletResponse.SC_BAD_REQUEST; } } res.setStatus(code); }
@RequestMapping(value = VIDEO_LIKEDBY_PATH, method = RequestMethod.GET) public @ResponseBody Set<String> likedbyVideo(@PathVariable(VIDEO_ID) long id) { Video v = videos.findOne(id); if (v == null) { throw new ResourceNotFoundException(); } return v.getLikedUsers(); }
@RequestMapping(method = RequestMethod.POST) public @ResponseBody Video addVideo(@RequestBody Video v) { return videos.save(v); }
@RequestMapping(value = VIDEO_ID_PATH, method = RequestMethod.GET) public @ResponseBody Video getVideo(@PathVariable long id) { return videos.findOne(id); }
@RequestMapping(method = RequestMethod.GET) public @ResponseBody Collection<Video> getVideoList() { return Lists.newArrayList(videos.findAll()); }