package com.hc.web.controller.browser.app;

import com.hc.business.model.ZccmUserCourse;
import com.hc.business.service.ZccmUserCourseService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 用户课程表(UserCourse)表控制层
 *
 * @author java
 * @since 2020-11-09 10:05:20
 */

@RestController
@RequestMapping("/new/api/app/userCourse")
public class AppUserCourseController {

    /**
     * 服务对象
     */
    private final ZccmUserCourseService userCourseService;

    public AppUserCourseController(ZccmUserCourseService userCourseService) {
        this.userCourseService = userCourseService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 UserCourse", response = Result.class)
    public Result selectAppUserCourse(@PathVariable("id") Integer id) {
        return Result.success(this.userCourseService.queryById(id));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增 UserCourse", response = Result.class)
    public Result addAppUserCourse(@Valid @RequestBody ZccmUserCourse userCourse) {
        return Result.success(userCourseService.insert(userCourse));
    }

    @GetMapping("/list")
    @ApiOperation(value = "根据用户id 获取 UserCourse列表(分页)", response = Result.class)
    public Result listAppUserCourse(@ApiParam(value = "用户id") @RequestParam Integer userId,
                                    @ApiParam(value = "班次id") @RequestParam Integer classId,
                                    @RequestParam(defaultValue = "0") Integer page,
                                    @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(userCourseService.queryAllByLimit(userId, classId, page, size));
    }


}