package com.ruoyi.interfaces.controller;

import com.ruoyi.interfaces.core.page.Page;
import com.ruoyi.interfaces.core.page.PageParam;
import com.ruoyi.interfaces.core.page.PageUtils;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.interfaces.domain.PtServiceComment;
import com.ruoyi.interfaces.service.PtServiceCommentService;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author
 * @date 2022-1-17
 */
@RestController
@RequestMapping("/pt/service/comment")
public class PtServiceCommentController extends BaseController {

    @Autowired
    private PtServiceCommentService ptServiceCommentService;


    @ApiOperation("添加/修改服务评论")
    @RequestMapping(value = "", method = RequestMethod.POST)
    public AjaxResult save(@RequestBody PtServiceComment ptServiceComment) {
        ptServiceComment.setUserId(String.valueOf(getUserId()));
        return AjaxResult.success(ptServiceCommentService.save(ptServiceComment));
    }

    @ApiOperation("根据ID删除服务评论")
    @RequestMapping(value = "delete/{id}", method = RequestMethod.GET)
    public AjaxResult delete(@PathVariable String id) {
        int ret = ptServiceCommentService.delete(id);
        return AjaxResult.success();
    }

    @ApiOperation("根据ID获取服务评论（单表）")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public AjaxResult get(@PathVariable String id) {
        PtServiceComment ptServiceComment = ptServiceCommentService.get(id);
        return AjaxResult.success(ptServiceComment);
    }

    @ApiOperation("服务评论列表")
    @PostMapping(value = "/list")
    public AjaxResult listOf(@RequestBody PageParam<PtServiceComment> ptServiceCommentPageParam) {
        return AjaxResult.success(PageUtils.convert(ptServiceCommentService.findPageInfo(ptServiceCommentPageParam)));
    }

}
