package com.xunwang.education.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.xunwang.commonutils.R;
import com.xunwang.education.entity.dto.MyTeacherCoursesDto;
import com.xunwang.education.service.MyFavoriteCoursesService;
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.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Long
 * @since 2023-01-12
 */
@RestController
@RequestMapping("/education/my-favorite-courses")
@ApiSupport(author = "Long")
public class MyFavoriteCoursesController {

    @Autowired
    private MyFavoriteCoursesService favoriteCoursesService;

    @ApiOperation("查询个人收藏的课程ids")
    @GetMapping("/findPersonCollect")
    public R findPersonCollect(HttpServletRequest request) {
        List<String> personCollect = favoriteCoursesService.findPersonCollect(request);
        return R.ok().data("requires", personCollect);
    }

    @ApiOperation("收藏课程")
    @GetMapping("/collect")
    public R collect(HttpServletRequest request) {
        int collect = favoriteCoursesService.collect(request);
        if (collect > 0) {
            return R.ok().message("收藏成功");
        }
        return R.ok().message("收藏失败");
    }

    @ApiOperation("取消收藏课程")
    @GetMapping("/cancelCollect")
    public R cancelCollect(HttpServletRequest request) {
        boolean b = favoriteCoursesService.cancelCollect(request);
        if (b) {
            return R.ok().message("取消收藏成功");
        }
        return R.ok().message("取消收藏失败");
    }

    @ApiOperation("查询个人收藏的课程部分信息")
    @GetMapping("findPersonCollection")
    public R findPersonCollection(HttpServletRequest request) {
        List<MyTeacherCoursesDto> personCollection = favoriteCoursesService.findPersonCollection(request);
        return R.ok().data("course", personCollection);
    }

}

