package com.yc.ship.module.miniapplet.controller.app.content;

import com.yc.ship.framework.common.pojo.CommonResult;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.util.object.BeanUtils;
import com.yc.ship.module.miniapplet.controller.app.content.vo.AppContentPageReqVO;
import com.yc.ship.module.miniapplet.controller.app.content.vo.AppContentRespVO;
import com.yc.ship.module.miniapplet.dal.dataobject.content.ContentDO;
import com.yc.ship.module.miniapplet.service.content.ContentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.yc.ship.framework.common.pojo.CommonResult.success;

/**
 *
 * @description ：TODO
 * @date ：2024/8/19 17:13
 */
@Tag(name = "用户 APP - 内容接口")
@RestController
@RequestMapping("/applet/content")
@Validated
@Slf4j
public class AppContentController {

    @Resource
    private ContentService contentService;


    @PostMapping("/page")
    @Operation(summary = "获取内容分页列表")
    public CommonResult<PageResult<AppContentRespVO>> page(@RequestBody @Valid AppContentPageReqVO reqVO) {
        PageResult<ContentDO> page = contentService.getAppContentPage(reqVO);
        return success(BeanUtils.toBean(page, AppContentRespVO.class));
    }

    @PostMapping("/pageByCatalogueId")
    @Operation(summary = "获取内容分页列表")
    public CommonResult<PageResult<AppContentRespVO>> pageByCatalogueId(@RequestBody @Valid AppContentPageReqVO reqVO) {
        PageResult<ContentDO> page = contentService.getAppContentPageByCatalogueId(reqVO);
        return success(BeanUtils.toBean(page, AppContentRespVO.class));
    }

    // 内容详情
    @GetMapping("/detail")
    @Operation(summary = "获取内容详情")
    public CommonResult<AppContentRespVO> detail(@RequestParam("id") Long id) {
        ContentDO content = contentService.getContent(id);
        return success(BeanUtils.toBean(content, AppContentRespVO.class));
    }



}
