package com.koobietech.eas.controller;

import com.github.pagehelper.PageHelper;
import com.koobietech.eas.common.result.JsonPageResult;
import com.koobietech.eas.common.result.JsonResult;
import com.koobietech.eas.common.result.PageDataResult;
import com.koobietech.eas.mbg.model.EasEduClassroom;
import com.koobietech.eas.service.EasEduClassroomService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Tag(name = "教室模块")
@RequestMapping("/classroom")
public class EasEduClassroomController {
    @Resource
    EasEduClassroomService easEduClassroomService;


    @PostMapping("/query")
    @Operation(summary = "查询教室", description = "根据参数查询教室表信息")
    public JsonPageResult query(@RequestBody EasEduClassroom classroom,
                                @RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        PageDataResult ret = easEduClassroomService.query(classroom);
        return JsonPageResult.data(ret);
    }

    @PostMapping("/add")
    @Operation(summary = "添加教室", description = "用于添加教室信息")
    public JsonResult add(@RequestBody EasEduClassroom classroom) {
        Boolean ret = easEduClassroomService.add(classroom);
        if (ret) {
            return JsonResult.data(ret);
        }
        return JsonResult.fail();
    }


    @DeleteMapping("/delete")
    @Operation(summary = "删除教室", description = "删除教室信息表数据根据ID")
    public JsonResult delete(@RequestParam Integer id) {
        Boolean ret = easEduClassroomService.delete(id);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }


    @PutMapping("/update")
    @Operation(summary = "更新教室", description = "更新教室信息")
    public JsonResult update(@RequestBody EasEduClassroom classroom) {
        Boolean ret = easEduClassroomService.update(classroom);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }


}
