AdminController.java 3.1 KB
Newer Older
刘基明's avatar
刘基明 committed
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
package com.tanpu.community.controller;

import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.UserHolder;
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.api.beans.TopicDataAnalysDTO;
import com.tanpu.community.api.beans.req.topic.TopicConcealReq;
import com.tanpu.community.api.beans.req.topic.TopicModifyMountReq;
import com.tanpu.community.api.beans.req.topic.TopicTopReq;
import com.tanpu.community.manager.TopicManager;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping(value = "/api/admin")
public class AdminController {


    @Autowired
    private TopicManager topicManager;

    @Autowired
    private UserHolder userHolder;

刘基明's avatar
刘基明 committed
30
    @GetMapping(value="/insertTopic")
刘基明's avatar
刘基明 committed
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
    @ApiOperation("新增话题")
    @ResponseBody
    public CommonResp<Void> addTopic(@RequestParam String topicTitle){
        String userId = userHolder.getUserId();
        topicManager.insertTopic(topicTitle,userId);
        return CommonResp.success();
    }

    @ApiOperation("单个话题详细数据")
    @PostMapping("/topic/detailData")
    @ResponseBody
    public CommonResp<TopicDTO> selectOne(@RequestParam String topicId) throws MissingServletRequestParameterException {
        if (StringUtils.isEmpty(topicId)){
            throw new MissingServletRequestParameterException("topicId","String");
        }
        TopicDTO topicDTO=topicManager.getDetail(topicId);
        return CommonResp.success(topicDTO);
    }

    @PostMapping(value = "/topic/setTop")
    @ApiOperation("顶置/取消顶置话题")
    @ResponseBody
    public CommonResp<Void> setTopTopic(@RequestBody TopicTopReq req) throws MissingServletRequestParameterException {
        topicManager.setTopTopic(req.getTopicId(),req.isTop());
        return CommonResp.success();
    }

    @PostMapping(value = "/topic/setConceal")
    @ApiOperation("隐藏/显示话题")
    @ResponseBody
    public CommonResp<Void> setConceal(@RequestBody TopicConcealReq req) throws MissingServletRequestParameterException {
        topicManager.setTopicConceal(req.getTopicId(),req.isConceal());
        return CommonResp.success();
    }

    @PostMapping(value = "/topic/modifyViewNum")
    @ApiOperation("话题浏览数调整(后台管理)")
    @ResponseBody
    public CommonResp<Void> modifyViewNum(@RequestBody TopicModifyMountReq req) throws MissingServletRequestParameterException {
刘基明's avatar
刘基明 committed
70
        topicManager.modifyViewCount(req.getTopicId(),req.getModifyMount());
刘基明's avatar
刘基明 committed
71 72 73 74 75 76 77 78 79 80 81
        return CommonResp.success();
    }

    @PostMapping(value = "/topic/dataAnalyse")
    @ApiOperation("话题数据分析")
    @ResponseBody
    public CommonResp<TopicDataAnalysDTO> dataAnalyse(@RequestParam String topicId) throws MissingServletRequestParameterException {
        TopicDataAnalysDTO result =topicManager.queryDataAnalysis(topicId);
        return CommonResp.success(result);
    }
}