package microblogging.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import microblogging.service.BlogService;
import microblogging.service.UserService;

@Controller
@RequestMapping("blog")
public class BlogController {

    @Autowired
    private BlogService blogService;

    @Autowired
    private UserService userService;

//    @RequestMapping(value = "/list", method = RequestMethod.GET)
//    public @ResponseBody List<BlogVO> list(HttpServletRequest request, HttpServletResponse response) {
//        // get user info
//        String username = ((User) request.getSession().getAttribute("user")).getUsername();
//        User u = userService.getUserByName(username);
//
//        List<Blog> blogs = blogService.getAllBlogsByUser(u);
//        List<BlogVO> result = new ArrayList<BlogVO>();
//        for (Blog blog : blogs) {
//            result.add(new BlogVO(blog));
//        }
//
//        return result;
//    }
//
//    @RequestMapping(value = "/tracking", method = RequestMethod.GET)
//    public @ResponseBody List<BlogVO> tracking(HttpServletRequest request, HttpServletResponse response) {
//        // get user info
//        String username = ((User) request.getSession().getAttribute("user")).getUsername();
//
//        List<Blog> blogs = userService.getBlogTracking(username);
//        List<BlogVO> result = new ArrayList<BlogVO>();
//        for (Blog blog : blogs) {
//            result.add(new BlogVO(blog));
//        }
//
//        return result;
//    }
//
//    @RequestMapping(value = "/add", method = RequestMethod.POST)
//    public @ResponseBody BlogVO add(HttpServletRequest request, HttpServletResponse response,
//            @RequestParam(value = "blogContent", required = true) String blogContent) {
//        // get user info
//        String username = ((User) request.getSession().getAttribute("user")).getUsername();
//
//        // save blog
//        Blog blog = blogService.save(blogContent, username);
//        BlogVO vo = new BlogVO(blog);
//
//        return vo;
//    }
}

@@ -28,16 +28,162 @@
 oller;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0A
 import o
@@ -350,16 +350,205 @@
 apping;%0A
+import org.springframework.web.bind.annotation.RequestMethod;%0Aimport org.springframework.web.bind.annotation.ResponseBody;%0A%0Aimport microblogging.model.Blog;%0Aimport microblogging.model.User;
 %0Aimport 
@@ -623,16 +623,48 @@
 Service;
+%0Aimport microblogging.vo.BlogVO;
 %0A%0A@Contr
@@ -1422,37 +1422,33 @@
 result;%0A//    %7D%0A
-//%0A//
+%0A
     @RequestMapp
@@ -1492,34 +1492,32 @@
 uestMethod.GET)%0A
-//
     public @Resp
@@ -1599,34 +1599,32 @@
 nse response) %7B%0A
-//
         // get u
@@ -1624,34 +1624,32 @@
 / get user info%0A
-//
         String u
@@ -1643,36 +1643,34 @@
      String user
-name
+Id
  = ((User) reque
@@ -1710,33 +1710,23 @@
 r%22)).get
-Username();%0A//%0A//
+Id();%0A%0A
         
@@ -1744,28 +1744,28 @@
 blogs = 
-user
+blog
 Service.
 getBlogT
@@ -1760,37 +1760,30 @@
 ice.
-getBlogTracking
+findByUserId
 (user
-name
+Id
 );%0A
-//
     
@@ -1825,34 +1825,32 @@
 List%3CBlogVO%3E();%0A
-//
         for (Blo
@@ -1859,34 +1859,32 @@
 blog : blogs) %7B%0A
-//
             resu
@@ -1901,34 +1901,32 @@
  BlogVO(blog));%0A
-//
         %7D%0A//%0A// 
@@ -1911,37 +1911,33 @@
 og));%0A        %7D%0A
-//%0A//
+%0A
         return r
@@ -1947,18 +1947,14 @@
 lt;%0A
-//
     %7D%0A
-//
 %0A// 

fix tracking