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

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

import javax.validation.Valid;


/**
 * (ZccmUserTeacher)表控制层
 *
 * @author java
 * @since 2020-11-20 11:08:21
 */

@RestController
@RequestMapping("/new/api/back/userTeacher")
public class BackUserTeacherController {

    /**
     * 服务对象
     */
    private final ZccmUserTeacherService userTeacherService;

    public BackUserTeacherController(ZccmUserTeacherService userTeacherService) {
        this.userTeacherService = userTeacherService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 ZccmUserTeacher", response = Result.class)
    public Result addBackUserTeacher(@Valid @RequestBody ZccmUserTeacher userTeacher) {
        return Result.success(userTeacherService.insert(userTeacher));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 ZccmUserTeacher", response = Result.class)
    public Result updateBackUserTeacher(@RequestBody ZccmUserTeacher userTeacher) {
        return Result.success(userTeacherService.update(userTeacher));
    }

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

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

    @GetMapping("/list/name")
    @ApiOperation(value = "依据老师名称 获取 ZccmUserTeacher列表", response = Result.class)
    public Result listZccmUserTeacherByName(@RequestParam String name) {
        return Result.success(userTeacherService.queryByName(name));
    }

}