package com.ruoyi.cai.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.cai.dto.app.query.StarOrVisitorReq;
import com.ruoyi.cai.dto.app.query.VisitorQuery;
import com.ruoyi.cai.dto.app.vo.user.UserStarOrVisitorList;
import com.ruoyi.cai.service.UserVisitorService;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user/visitor")
@Slf4j
@Tag(name = "访问记录相关接口")
public class UserVisitorAppController {

    @Autowired
    private UserVisitorService userVisitorService;

    // 除网络问题不返回异常。避免影响业务
    @PostMapping("/visitor")
    @Operation(summary = "新增浏览记录")
    public R<Boolean> visitor(@RequestBody StarOrVisitorReq starOrVisitorReq){
        try {
            boolean bool = userVisitorService.visitor(starOrVisitorReq);
        }catch (Exception e){
            log.error("记录访客失败",e);
        }
        return R.ok(true);
    }

    @GetMapping("/page")
    @Operation(summary = "我的浏览记录、访客查询-分页")
    public TableDataInfo<UserStarOrVisitorList> page(VisitorQuery query, PageQuery pageQuery){
        Page<UserStarOrVisitorList> res = userVisitorService.pageApp(pageQuery,query);
        return TableDataInfo.build(res);
    }

}
