@RequestMapping(value = "/deletePost/{id}", method = RequestMethod.GET)
 public String deleteComment(@PathVariable(value = "id") int postId) {
   WallPost post = postService.getPost(postId);
   List<Comment> commentListOnThisPost = commentService.getAllCommentsOnPost(post);
   commentService.deleteComment(commentListOnThisPost);
   postService.deletePost(post);
   return "redirect:/posts";
 }
  @RequestMapping(method = RequestMethod.POST)
  public String addNewPost(
      WallPost wallPost,
      BindingResult result,
      HttpServletRequest request,
      @RequestParam(value = "holler") MultipartFile file) {
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("loggedUser");
    wallPost.setAudioFileName(file.getOriginalFilename());
    wallPost.setAudioContentType(file.getContentType());
    wallPost.setPostBy(user);
    wallPost.setPostTo(user);
    wallPost.setDate(new Date());
    try {
      wallPost.setAudioContent(file.getBytes());
    } catch (IOException e) {
      e.printStackTrace();
    }
    postValidator.validate(wallPost, result);
    if (!result.hasErrors()) {
      postService.saveNewPost(wallPost);
    }

    return "redirect:/posts";
  }
  @RequestMapping(value = "/saveFriendsPost/{id}", method = RequestMethod.POST)
  public String saveFriendsPost(
      WallPost wallPost,
      BindingResult result,
      HttpServletRequest request,
      @PathVariable(value = "id") int friendId,
      @RequestParam(value = "holler") MultipartFile file) {
    User postBy = (User) request.getSession().getAttribute("loggedUser");
    User postTo = userService.getUser(friendId);
    wallPost.setPostTo(postTo);
    wallPost.setPostBy(postBy);
    wallPost.setDate(new Date());
    wallPost.setAudioContentType(file.getContentType());
    wallPost.setAudioFileName(file.getOriginalFilename());
    try {
      wallPost.setAudioContent(file.getBytes());
    } catch (IOException e) {
      e.printStackTrace();
    }
    postValidator.validate(wallPost, result);
    if (!result.hasErrors()) {
      log.debug("Saved the wall Post" + wallPost.getPostContent());
      postService.saveNewPost(wallPost);
    }

    if (request.getSession().getAttribute("friend") != null) {
      User friend = (User) request.getSession().getAttribute("friend");
      String id = Integer.toString(friend.getUserId());
      request.getSession().setAttribute("friend", null);
      return "redirect:/friends/showFullProfile/" + id;
    } else {
      return "redirect:/posts";
    }
  }
 @RequestMapping(method = RequestMethod.GET)
 public String showHomePage(ModelMap model, HttpServletRequest request) {
   WallPost wallPost = new WallPost();
   Comment comment = new Comment();
   HttpSession session = request.getSession();
   User user = (User) session.getAttribute("loggedUser");
   List<WallPost> allPosts = postService.getPosts(user);
   if (allPosts != null) {
     model.addAttribute("posts", allPosts);
   } else {
     model.addAttribute("noPosts", "There is no new Post in this wall");
   }
   model.addAttribute("wallPost", wallPost);
   model.addAttribute("comment", comment);
   setModelAttributes(user, model);
   return "/homePage";
 }
  @RequestMapping(value = "/playAudio/{id}")
  public void playAudio(HttpServletResponse response, @PathVariable(value = "id") int id) {
    log.debug("in audio streaming, id = {}", id);
    WallPost post = postService.getPost(id);
    OutputStream output = null;

    try {
      output = response.getOutputStream();
      response.setContentType(post.getAudioContentType());
      output.write(post.getAudioContent());
      output.flush();
    } catch (IOException e) {
      e.printStackTrace();

    } finally {
      try {
        output.close();
      } catch (IOException e) {

      }
    }
  }