package org.dromara.main.controller.miniapp;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.main.domain.bo.MainStudentCollectionBo;
import org.dromara.main.domain.vo.MainStudentCollectionVo;
import org.dromara.main.service.IMainStudentCollectionService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 小程序收藏接口
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/miniapp/collection")
public class MiniappCollectionController extends BaseController {

    private final IMainStudentCollectionService collectionService;

    /**
     * 查询收藏列表
     */
    @SaIgnore
    @GetMapping("/list")
    public TableDataInfo<MainStudentCollectionVo> list(MainStudentCollectionBo bo, PageQuery pageQuery) {
        return collectionService.queryPageList(bo, pageQuery);
    }

    /**
     * 添加收藏
     */
    @SaIgnore
    @PostMapping
    public R<Void> add(@RequestBody MainStudentCollectionBo bo) {
        return toAjax(collectionService.insertByBo(bo));
    }

    /**
     * 取消收藏
     */
    @SaIgnore
    @DeleteMapping("/{id}")
    public R<Void> remove(@PathVariable Long id) {
        return toAjax(collectionService.deleteById(id));
    }

    /**
     * 检查是否已收藏
     */
    @SaIgnore
    @GetMapping("/check")
    public R<MainStudentCollectionVo> check(Long studentId, Long targetId, String type) {
        return R.ok(collectionService.checkCollection(studentId, targetId, type));
    }
}
