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.common.IdReq;
import com.ruoyi.xq.dto.app.uservisitor.UserVisitorQuery;
import com.ruoyi.xq.dto.app.uservisitor.vo.UserVisitorListVo;
import com.ruoyi.xq.service.UserVisitorService;
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/visitor")
@Tag(name = "用户访问接口")
public class UserVisitorAppController {
    @Autowired
    private UserVisitorService userVisitorService;

    @PostMapping("/visitor")
    @Operation(summary = "访问用户")
    public R<Void> starUpdate(@RequestBody IdReq req){
        userVisitorService.visitor(LoginHelper.getUserId(),req.getId());
        return R.ok();
    }

    @GetMapping("/me/page")
    @Operation(summary = "查询谁看过我-分页")
    @Log(title = "查询谁看过我-分页", businessType = BusinessType.OTHER,isPrintResponseData = false, isSaveDb = false)
    public R<PageModel<UserVisitorListVo>> page(PageQuery pageQuery, UserVisitorQuery query){
        query.setUserId(LoginHelper.getUserId());
        Page<UserVisitorListVo> app = userVisitorService.pageApp(pageQuery, query);
        return R.ok(PageModel.build(app));
    }
}
