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

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

import javax.validation.Valid;


/**
 * 用户班级学习进度表
 * (UserStatus)表控制层
 *
 * @author java
 * @since 2020-12-06 11:26:46
 */

@RestController
@RequestMapping("/new/api/back/userStatus")
public class BackUserStatusController {

    /**
     * 服务对象
     */
    private final UserStatusService userStatusService;

    public BackUserStatusController(UserStatusService userStatusService) {
        this.userStatusService = userStatusService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 UserStatus", response = Result.class)
    public Result addUserStatus(@Valid @RequestBody UserStatus userStatus) {
        return Result.success(userStatusService.insert(userStatus));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 UserStatus", response = Result.class)
    public Result updateUserStatus(@RequestBody UserStatus userStatus) {
        return Result.success(userStatusService.update(userStatus));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "依据主键删除 UserStatus", response = Result.class)
    public Result deleteUserStatus(@PathVariable("id") Integer id) {
        return Result.success(userStatusService.deleteById(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取 UserStatus列表(分页)", response = Result.class)
    public Result listUserStatus(@RequestParam(defaultValue = "0") Integer page,
                                 @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(userStatusService.queryAllByLimit(page, size));
    }

    @GetMapping("/list/user")
    @ApiOperation(value = "获取 User列表(分页)", response = Result.class)
    public Result listUserByClassId(@RequestParam Integer classId,
                                    @RequestParam(defaultValue = "0") Integer page,
                                    @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(userStatusService.queryByClassId(classId, page, size));
    }


}