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


import com.liquidnet.client.admin.common.core.domain.AjaxResult;
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.*;

import java.util.List;

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

    @Autowired
    ISmileSchoolService iSmileSchoolService;


    @GetMapping("/schoolList")
    @ApiOperation("获取学校列表")
    @ResponseBody
    public AjaxResult schoolList() {
        List<SmileSchool> smileSchools = iSmileSchoolService.schoolList();
        return AjaxResult.success(smileSchools);
    }

    @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 AjaxResult.success(iSmileSchoolService.create(smileSchool));
    }

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

        }
    }
}
