package jnpf.cultivate.controller.web.gained;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.base.ActionResult;
import jnpf.base.Pagination;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.cultivate.service.FtbCourseGainedShareService;
import jnpf.model.cultivate.po.gained.FtbCourseGainedShareEntity;
import jnpf.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * app岗位学习课程-心得分享
 *
 */
@RestController
@Tag(name = "心得分享", description = "心得分享")
@RequestMapping("/course_gained_share")
public class FtbCourseGainedShareController  {
    @Autowired
    private FtbCourseGainedShareService ftbCourseGainedShareService;

    @Operation(summary = "获取列表")
    @GetMapping("/list")
    public ActionResult<PageListVO<FtbCourseGainedShareEntity>> list(Pagination pagination) {
        List<FtbCourseGainedShareEntity> entity = ftbCourseGainedShareService.getList(pagination);
        List<FtbCourseGainedShareEntity> listVo = JsonUtil.getJsonToList(JsonUtil.getObjectToStringDateFormat(entity, "yyyy-MM-dd HH:mm:ss"), FtbCourseGainedShareEntity.class);
        PaginationVO vo = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
        return ActionResult.page(listVo, vo);
    }

    @Operation(summary = "获取详情")
    @GetMapping("/{id}")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
    })
    public ActionResult<FtbCourseGainedShareEntity> info(@PathVariable("id") String id) {
        FtbCourseGainedShareEntity entity = ftbCourseGainedShareService.getInfo(id);
        return ActionResult.success(entity);
    }

    @Operation(summary = "新建")
    @PostMapping
    public ActionResult<String> create(@RequestBody @Valid FtbCourseGainedShareEntity entity) {
        ftbCourseGainedShareService.create(entity);
        return ActionResult.success("保存成功");
    }

    @Operation(summary = "修改")
    @PutMapping("/{id}")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
    })
    public ActionResult<String> update(@PathVariable("id") String id, @RequestBody @Valid FtbCourseGainedShareEntity entity) {
        entity.setId(id);
        ftbCourseGainedShareService.updateById(entity);
        return ActionResult.success("修改成功");
    }

    @Operation(summary = "删除")
    @DeleteMapping("/{id}")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
    })
    public ActionResult<String> delete(@PathVariable("id") String id) {
        ftbCourseGainedShareService.removeById(id);
        return ActionResult.success("删除成功");
    }

//    @Operation(summary = "心得分享到广场")
//    @PostMapping("/sharingSquare")
//    public ActionResult<String> sharingSquare(@RequestBody SharingSquareVO sharingSquareVO) {
//        ftbCourseGainedShareService.sharingSquare(sharingSquareVO.getId());
//        return ActionResult.success("分享成功");
//    }
}