package com.jeeplus.pubmodules.knowledge.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.pubmodules.knowledge.domain.KnowledgeShareComment;
import com.jeeplus.pubmodules.knowledge.domain.KnowledgeShareDetail;
import com.jeeplus.pubmodules.knowledge.service.KnowledgeShareInfoService;
import com.jeeplus.pubmodules.knowledge.service.dto.KnowledgeShareInfoDto;
import com.jeeplus.pubmodules.knowledge.service.dto.KnowledgeShareListDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api("/知识分享")
@RequestMapping(value = "/knowledgeShare/info")
public class KnowledgeShareInfoController {

    @Resource
    private KnowledgeShareInfoService service;

    /**
     * 列表
     */
    @GetMapping("list")
    @ApiOperation(value = "列表")
    public ResponseEntity<IPage<KnowledgeShareListDto>> list(Page<KnowledgeShareListDto> page, KnowledgeShareDetail detail) {
        IPage<KnowledgeShareListDto> iPage = service.list(page, detail);
        return ResponseEntity.ok(iPage);
    }

    /**
     * 新增/修改
     */
    @PostMapping("save")
    @ApiOperation(value = "新增/修改")
    public ResponseEntity<String> save(@RequestBody KnowledgeShareInfoDto dto) {
        String s = service.save(dto);
        return ResponseEntity.ok(s);
    }

    /**
     * 查看
     */
    @GetMapping("/findById")
    @ApiOperation(value = "查看")
    public ResponseEntity<KnowledgeShareInfoDto> findById(String id, String method,Integer size) {
        KnowledgeShareInfoDto dto = service.findById(id, method,size);
        return ResponseEntity.ok(dto);
    }

    /**
     * 删除知识分享
     */
    @GetMapping("/removeById")
    @ApiOperation(value = "删除")
    public ResponseEntity<String> removeById(String id) {
        String s = service.removeById(id);
        return ResponseEntity.ok(s);
    }

    /**
     * 评论
     */
    @PostMapping("/addComment")
    @ApiOperation(value = "添加评论")
    public ResponseEntity<String> addComment(@RequestBody KnowledgeShareComment comment) {
        String s = service.addComment(comment);
        return ResponseEntity.ok(s);
    }

    /**
     * 删除评论
     */
    @GetMapping("/delComment")
    @ApiOperation(value = "删除评论")
    public ResponseEntity<String> delComment(String id) {
        String s = service.delComment(id);
        return ResponseEntity.ok(s);
    }

    /**
     * 查询评论
     */
    @GetMapping("/getComments")
    @ApiOperation(value = "查询评论")
    public ResponseEntity<KnowledgeShareInfoDto> getComments(String id){
        KnowledgeShareInfoDto list=service.getComments(id);
        return ResponseEntity.ok(list);
    }

}
