package com.qmth.teachcloud.common.api.api;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.teachcloud.common.bean.dto.SchoolDto;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.entity.BasicSchool;
import com.qmth.teachcloud.common.service.BasicSchoolService;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 学校表 前端控制器
 * </p>
 *
 * @author xf
 * @since 2021-03-23
 */
@Api(tags = "学校Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX  + SystemConstant.PREFIX_URL_COMMON + "/school")
public class BasicSchoolController {

    @Autowired
    private BasicSchoolService basicSchoolService;

    /**
     * 学校查询
     * @return
     */
    @ApiOperation(value = "查询")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result list() {
        List<SchoolDto> list = basicSchoolService.listSchool();
        return ResultUtil.ok(list);
    }

    /**
     * 学校查询
     * @return
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result update(@RequestParam(value = "id") Long id,
                         @RequestParam(value = "code") String code,
                         @RequestParam(value = "name") String name,
                         @RequestParam(value = "logo", required = false) MultipartFile logo,
                         @RequestParam(value = "logoMd5") String logoMd5) {
        return ResultUtil.ok(basicSchoolService.updateSchool(id, code, name, logo, logoMd5));
    }
}

