package com.ruoyi.xq.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.PageModel;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.xq.domain.Dynamic;
import com.ruoyi.xq.dto.app.dynamic.AddDynamicReq;
import com.ruoyi.xq.dto.app.dynamic.DynamicListVo;
import com.ruoyi.xq.dto.app.dynamic.DynamicQuery;
import com.ruoyi.xq.service.DynamicService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.Registration;
import java.util.List;

@RestController
@RequestMapping("/api/dynamic")
@Tag(name = "动态相关接口")
public class DynamicAppController {
    @Autowired
    private DynamicService dynamicService;

    @PostMapping("/add")
    @Operation(summary = "新增动态")
    @Log(title = "新增动态", businessType = BusinessType.OTHER, isSaveDb = false)
    public R<Void> addDynamic(@RequestBody AddDynamicReq req){
        req.setUserId(LoginHelper.getUserId());
        dynamicService.push(req);
        return R.ok();
    }

    @GetMapping("/page")
    @Operation(summary = "动态列表-分页")
    @Log(title = "动态列表-分页", businessType = BusinessType.OTHER, isSaveDb = false)
    public R<PageModel<DynamicListVo>> page(PageQuery pageQuery, DynamicQuery dynamicQuery){
        Page<DynamicListVo> page = dynamicService.pageApp(pageQuery, dynamicQuery);
        return R.ok(PageModel.build(page));
    }
}
