package com.salpa.web.controller.subject;
import com.salpa.common.core.controller.BaseController;
import com.salpa.common.core.domain.AjaxResult;
import com.salpa.common.core.domain.entity.SysUser;
import com.salpa.common.core.page.TableDataInfo;
import com.salpa.common.utils.SecurityUtils;
import com.salpa.subject.domain.MonitorDocumentDiscussion;
import com.salpa.subject.service.DocumentDiscussionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评论
 * @author
 */
@RestController
@RequestMapping("/subject/documentDiscussion")
public class DocumentDiscussionController extends BaseController {
    @Autowired
    private DocumentDiscussionService documentDiscussionService;
    /**
     * 添加评论
     * @author rhl
     * @param monitorDocumentDiscussion
     * @return
     */
    @PostMapping("add")
    public AjaxResult addDiscussion(@RequestBody MonitorDocumentDiscussion monitorDocumentDiscussion) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        monitorDocumentDiscussion.setUserId(user.getUserId());
        return  AjaxResult.success(documentDiscussionService.add(monitorDocumentDiscussion));
    }
    /**
     * 获取评论列表
     * @author hzl
     * @return
     */
    @PostMapping ("list")
    public TableDataInfo getList(@RequestBody MonitorDocumentDiscussion monitorDocumentDiscussion) {
        List<MonitorDocumentDiscussion> list = documentDiscussionService.getList(monitorDocumentDiscussion);
        return getDataTable(list);
    }
    /**
     * 删除评论
     * @author hzl
     * @param id
     * @return
     */
    @DeleteMapping("delete")
    public AjaxResult deleteComment(Integer id){
        return toAjax(documentDiscussionService.deleteComment(id));
    }
}
