forked from fanchaoo/hahu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopicController.java
More file actions
93 lines (77 loc) · 2.92 KB
/
TopicController.java
File metadata and controls
93 lines (77 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.fc.controller;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.fc.model.Topic;
import com.fc.service.TopicService;
import com.fc.service.UserService;
import com.fc.util.Response;
@Controller
@RequestMapping("/")
public class TopicController {
@Autowired
private TopicService topicService;
@Autowired
private UserService userService;
@RequestMapping("/topic")
public String topic(Model model) {
return "topic";
}
@RequestMapping("/topics")
public String topics(Model model) {
Map<String, Object> map = topicService.listAllTopic();
model.addAllAttributes(map);
return "topics";
}
@RequestMapping("/listTopicByTopicName")
public String listTopicByTopicName(String topicName, Model model) throws UnsupportedEncodingException {
topicName = new String(topicName.getBytes("iso8859-1"), "utf-8");
Map<String, Object> map = topicService.listTopicByTopicName(topicName);
model.addAllAttributes(map);
return "topicList";
}
@RequestMapping("/listTopicByParentTopicId")
@ResponseBody
public Response listTopicByParentTopicId(Integer parentTopicId) {
List<Topic> list = topicService.listTopicByParentTopicId(parentTopicId);
Map<String, Object> map = new HashMap<>();
map.put("topicList", list);
return new Response(0, "", map);
}
@RequestMapping("/topicDetail/{topicId}")
public String topicDetail(@PathVariable Integer topicId, Integer page, Boolean allQuestion, Model model, HttpServletRequest request) {
Integer userId = userService.getUserIdFromRedis(request);
Map<String, Object> map = topicService.getTopicDetail(topicId, allQuestion, page, userId);
model.addAllAttributes(map);
return "topicDetail";
}
@RequestMapping("/judgePeopleFollowTopic")
@ResponseBody
public Response judgePeopleFollowTopic(Integer topicId, HttpServletRequest request) {
Integer userId = userService.getUserIdFromRedis(request);
boolean status = topicService.judgePeopleFollowTopic(userId, topicId);
return new Response(0, "", status);
}
@RequestMapping("/followTopic")
@ResponseBody
public Response followTopic(Integer topicId, HttpServletRequest request) {
Integer userId = userService.getUserIdFromRedis(request);
topicService.followTopic(userId, topicId);
return new Response(0, "");
}
@RequestMapping("/unfollowTopic")
@ResponseBody
public Response unfollowTopic(Integer topicId, HttpServletRequest request) {
Integer userId = userService.getUserIdFromRedis(request);
topicService.unfollowTopic(userId, topicId);
return new Response(0, "");
}
}