package com.ruoyi.web.controller.ie;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ie.domain.Papers;
import com.ruoyi.ie.domain.Questions;
import com.ruoyi.ie.service.IPapersService;
import com.ruoyi.ie.service.IQuestionsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "前端V2 收藏")
@RestController
@RequestMapping("front/favorites")
public class FrontFavoritesController extends BaseController {
    @Autowired
    private IPapersService papersService;
    @Autowired
    private IQuestionsService questionsService;

    @ApiOperation("收藏的试卷列表")
    @GetMapping("papers")
    public TableDataInfo papers(Integer subjectId) {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        startPage();
        Papers papers = new Papers();
        papers.setSubjectId(subjectId);
        papers.setExamineeId(userId);
        papers.setCollect(true);
        List<Papers> list = papersService.selectPapersListFromFavorites(papers);
        list.stream().forEach(t -> t.setCollect(true));
        return getDataTable(list);
    }
    
    @ApiOperation("收藏的问题列表")
    @GetMapping("questions")
    public TableDataInfo questions(Integer subjectId) {
        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
        startPage();
        Questions questions = new Questions();
        questions.setSubjectId(subjectId);
        questions.setUserId(userId);
        List<Questions> list = questionsService.selectCollectedList(questions);
        questionsService.replaceImage(list);
        questionsService.fillCollectInfo(SecurityUtils.getLoginUser().getUser().getUserId(), list);
        return getDataTable(list);
    }
    
}
