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.dto.app.userstar.UserStarQuery;
import com.ruoyi.xq.dto.app.userstar.UserStarReq;
import com.ruoyi.xq.dto.app.userstar.vo.UserStarListVo;
import com.ruoyi.xq.service.UserStarService;
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.*;

@RestController
@RequestMapping("/api/star")
@Tag(name = "用户关注接口")
public class UserStarAppController {
    @Autowired
    private UserStarService userStarService;

    @PostMapping("/update")
    @Operation(summary = "用户关注和取消关注")
    @Log(title = "用户关注和取消关注", businessType = BusinessType.OTHER, isSaveDb = true)
    public R<Void> starUpdate(@RequestBody UserStarReq req){
        req.setUserId(LoginHelper.getUserId());
        userStarService.starUpdate(req);
        return R.ok();
    }

    @GetMapping("/page")
    @Operation(summary = "关注查询-分页")
    @Log(title = "关注查询-分页", businessType = BusinessType.OTHER,isPrintResponseData = false, isSaveDb = false)
    public R<PageModel<UserStarListVo>> page(PageQuery pageQuery, UserStarQuery query){
        query.setUserId(LoginHelper.getUserId());
        Page<UserStarListVo> app = userStarService.pageApp(pageQuery, query);
        return R.ok(PageModel.build(app));
    }
}
