package com.xindazhou.business.controller.admin.community.comment;

import com.xindazhou.business.controller.admin.community.comment.vo.CommentPageReqVO;
import com.xindazhou.business.controller.admin.community.comment.vo.CommentRespVO;
import com.xindazhou.business.service.community.comment.CommentService;
import com.xindazhou.framework.common.pojo.CommonResult;
import com.xindazhou.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.xindazhou.framework.common.pojo.CommonResult.success;

/**
 * 管理后台 - 评论 Controller
 *
 * @author xindazhou
 */
@Tag(name = "管理后台 - 评论管理")
@RestController("communityCommentController")
@RequestMapping("/admin-api/community/comment")
@Validated
@Slf4j
public class CommentController {

    @Resource
    private CommentService commentService;

    @GetMapping("/page")
    @Operation(summary = "获得评论分页列表")
    @PreAuthorize("@ss.hasPermission('community:comment:query')")
    public CommonResult<PageResult<CommentRespVO>> getCommentPage(@Valid CommentPageReqVO pageReqVO) {
        PageResult<CommentRespVO> pageResult = commentService.getCommentPageAdmin(pageReqVO);
        return success(pageResult);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除评论")
    @Parameter(name = "id", description = "评论ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('community:comment:delete')")
    public CommonResult<Boolean> deleteComment(@RequestParam("id") Long id) {
        commentService.deleteCommentAdmin(id);
        return success(true);
    }

}

