NotificationController.java 2.21 KB
package com.tanpu.community.controller;

import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.AuthLogin;
import com.tanpu.common.auth.UserHolder;
import com.tanpu.community.api.beans.qo.NotificationQo;
import com.tanpu.community.api.beans.qo.ThemeNotifyQo;
import com.tanpu.community.api.beans.req.notification.NotifyQueryReq;
import com.tanpu.community.manager.NotificationManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 消息通知
 */
@Slf4j
@RestController
@RequestMapping("/api/notification")
@Api(value = "圈子消息通知")
public class NotificationController {

    @Autowired
    private UserHolder userHolder;

    @Autowired
    private NotificationManager notificationManager;

    @AuthLogin
    @PostMapping("/query")
    @ResponseBody
    @ApiOperation(value = "查找用戶的消息通知列表")
    public CommonResp<List<ThemeNotifyQo>> query(@RequestBody NotifyQueryReq req){

        List<ThemeNotifyQo> query = notificationManager.queryList(req, userHolder.getUserId());
        return CommonResp.success(query);
    }

    @AuthLogin
    @GetMapping("/updateCount")
    @ResponseBody
    @ApiOperation(value = "更新推送")
    public CommonResp<NotificationQo> query(){
        NotificationQo notificationQO = notificationManager.queryBriefInfo(userHolder.getUserId());

        return CommonResp.success(notificationQO);
    }

    @AuthLogin
    @GetMapping("/init")
    @ResponseBody
    @ApiOperation(value = "初始化数据")
    public CommonResp<Void> initData(){
        if (!"admin".equals(userHolder.getUserId())){
            return CommonResp.failed("权限不足");
        }
        notificationManager.initAllData();
        return CommonResp.success();
    }

}