package com.app.controller.admin.basics;

import com.app.annotation.platform.OperationLog;
import com.app.dto.PageResult;
import com.app.dto.Result;
import com.app.dto.basics.SaveTeacherDto;
import com.app.dto.basics.search.SaveTeacherTagDto;
import com.app.dto.basics.search.SearchTeacherDto;
import com.app.service.basics.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 功能描述：机构教师
 *
 * @Auther: 梁展鹏
 * @Date: 2018/7/24 11:38
 */
@Api(tags = "机构教师")
@Slf4j
@Validated
@RestController("AdminOrganTeacherController")
@RequestMapping("/admin/teacher")
public class TeacherController {

    @Autowired
    private TeacherService service;

    /**
     * 功能描述：查询所有[机构教师]
     *
     * @param params 查询对象
     * @return
     */
    @ApiOperation(value = "查询所有[机构教师]")
    @PostMapping("/page")
    public ResponseEntity<Result<PageResult<SaveTeacherTagDto>>> page(@Valid @RequestBody SearchTeacherDto params) {
        return new ResponseEntity(new Result().ok(service.page(params)), HttpStatus.OK);
    }

    @OperationLog("更新 - 机构教师")
    @ApiOperation(value = "保存/更新[机构教师]")
    @PostMapping("/save-or-update")
    public ResponseEntity<Result> saveOrUpdate(@Valid @RequestBody SaveTeacherDto saveTeacherDto) {
        service.saveOrUpdate(saveTeacherDto);
        return new ResponseEntity(new Result().ok(), HttpStatus.OK);
    }

}
