package com.ym.mec.teacher.controller;

import com.ym.mec.biz.dal.entity.TeacherSchool;
import com.ym.mec.biz.service.TeacherSchoolService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Author Joburgess
 * @Date 2019/10/14
 */
@Api(value = "教师vip课教学点服务")
@RequestMapping("teacherVipSchool")
@RestController
public class TeacherVipSchoolController extends BaseController {

    @Autowired
    private TeacherSchoolService teacherSchoolService;

    @ApiOperation("单查询")
    @GetMapping(value = "/query")
    public Object query(Long id) {
        return succeed(teacherSchoolService.get(id));
    }

    @ApiOperation("根据教师编号获取教学点")
    @GetMapping(value = "/queryAll")
    public Object queryAll(Integer teacherId) {
        return succeed(teacherSchoolService.findByTeacherId(teacherId));
    }

    @ApiOperation("新增")
    @PostMapping(value = "/add")
    public Object add(TeacherSchool teacherSchool) {
        Date date = new Date();
        teacherSchool.setCreateTime(date);
        teacherSchool.setUpdateTime(date);
        teacherSchoolService.insert(teacherSchool);
        return succeed();
    }

    @ApiOperation("修改")
    @PostMapping(value = "/update")
    public Object update(TeacherSchool teacherSchool) {
        Date date = new Date();
        teacherSchool.setUpdateTime(date);
        teacherSchoolService.update(teacherSchool);
        return succeed();
    }

    @ApiOperation("删除")
    @PostMapping(value = "/delete")
    public Object delete(Long id) {
        teacherSchoolService.delete(id);
        return succeed();
    }

}
