package com.fs.app.controller;

import com.fs.common.core.domain.R;
import com.fs.course.service.IFsUserCourseService;
import com.fs.course.vo.FsUserCourseVideoAppletVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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;

@Slf4j
@Api("课堂接口")
@RestController
@RequestMapping(value="/app/course")
public class CourseController {

    @Autowired
    private IFsUserCourseService courseService;


    @ApiOperation("查询全部公域的课程")
    @GetMapping("/getAppletCourse")
    public R getAppletCourse()
    {
        List<FsUserCourseVideoAppletVO> course = courseService.selectFsUserCourseVideoApplet();
        if(course != null && !course.isEmpty()){
            for (FsUserCourseVideoAppletVO appletVO : course) {
                List<FsUserCourseVideoAppletVO.FsUserCourseVideo> courseVideos = courseService.selectFsUserCourseVideoAppletByCourseId(appletVO.getCourseId());
                appletVO.setFsUserCourseVideoList(courseVideos);
                appletVO.setVideoTotal((long) courseVideos.size());
            }
        }
        return R.ok().put("data",course);
    }

    @ApiOperation("查询全部公域的课程")
    @GetMapping("/getAppletCourseVideo")
    public R getAppletCourseVideo(@RequestParam("courseId") Long courseId)
    {
        List<FsUserCourseVideoAppletVO.FsUserCourseVideo> courseVideos = courseService.selectFsUserCourseVideoAppletByCourseId(courseId);
        return R.ok().put("data",courseVideos);
    }
}
