package com.liquidnet.client.admin.web.controller.zhengzai.smile;


import com.github.pagehelper.PageInfo;
import com.liquidnet.client.admin.common.core.domain.AjaxResult;
import com.liquidnet.client.admin.common.core.page.TableDataInfo;
import com.liquidnet.client.admin.zhengzai.smile.dto.SmileSchoolParam;
import com.liquidnet.client.admin.zhengzai.smile.service.ISmileSchoolService;
import com.liquidnet.service.smile.entity.SmileSchool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liquidnet
 * @since 2022-03-14
 */
@Api(tags = "学校管理")
@RestController
@RequestMapping("/smile/school")
public class SmileSchoolController {

    @Autowired
    ISmileSchoolService iSmileSchoolService;


    @PostMapping("/list")
    @ApiOperation("获取学校列表")
    @ResponseBody
    public TableDataInfo schoolList(SmileSchoolParam smileSchoolParam) {
        PageInfo<SmileSchool> smileSchools = iSmileSchoolService.schoolList(smileSchoolParam);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(smileSchools.getList());
        rspData.setTotal(smileSchools.getTotal());
        return rspData;
    }

    @GetMapping("/getSchoolById")
    @ApiOperation("根据id获取学校")
    @ResponseBody
    public AjaxResult getSchoolById(@RequestParam(name = "id", required = true)Long id){
        return AjaxResult.success(iSmileSchoolService.getSchoolById(id));
    }

    @PostMapping("/create")
    @ApiOperation("新建学校")
    @ResponseBody
    public AjaxResult create(@RequestBody SmileSchool smileSchool){
        return iSmileSchoolService.create(smileSchool);
    }

    @PostMapping("/updateById")
    @ApiOperation("更具id修改学校")
    @ResponseBody
    public AjaxResult updateSchoolById(@RequestBody SmileSchool smileSchool){
         return iSmileSchoolService.updateSchoolById(smileSchool);
    }

    @PostMapping("/del")
    @ApiOperation("根据id删除学校")
    @ResponseBody
    public AjaxResult del(@RequestParam(name = "id", required = true)Long id){
        return iSmileSchoolService.del(id);
    }
}
