package com.microservices.cms.doc.controller;

import com.alibaba.fastjson2.JSONObject;
import com.microservices.cms.doc.domain.CmsDocCommentInputDto;
import com.microservices.cms.doc.domain.CmsDocCommentUpdateDto;
import com.microservices.cms.doc.service.ICmsDocCommentService;
import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 文章评论Controller
 *
 * @author otto
 * @date 2023-11-28
 */
@Api(tags = "文章评论相关接口")
@RestController
@RequestMapping("/docComment")
public class CmsDocCommentController extends BaseController {
    @Autowired
    private ICmsDocCommentService cmsDocCommentService;

    /**
     * 新增评论
     */
    @PostMapping("/{docId}")
    @ApiOperation(value = "新增评论")
    public AjaxResult addComment(@ApiParam("文章Id") @PathVariable Long docId,
                                 @RequestBody CmsDocCommentInputDto cmsDocCommentInputDto) {

        JSONObject result = cmsDocCommentService.addCmsDocComment(docId, cmsDocCommentInputDto);
        return success(result);
    }

    /**
     * 删除文章下评论
     */
    @DeleteMapping("/{docId}/{journalId}")
    @ApiOperation(value = "删除文章下评论")
    public AjaxResult removeComment(@ApiParam("文章Id") @PathVariable Long docId,
                                    @ApiParam("评论Id") @PathVariable Long journalId
    ) {

        JSONObject result = cmsDocCommentService.removeComment(docId, journalId);
        return success(result);
    }

    /**
     * 编辑文章评论
     */
    @PutMapping("/{docId}/{journalId}")
    @ApiOperation(value = "编辑文章评论")
    public AjaxResult editComment(@ApiParam("文章Id") @PathVariable Long docId,
                                  @ApiParam("评论Id") @PathVariable Long journalId,
                                  @RequestBody CmsDocCommentUpdateDto cmsDocCommentUpdateDto

    ) {

        JSONObject result = cmsDocCommentService.editComment(docId, journalId, cmsDocCommentUpdateDto);
        return success(result);
    }

}
