package com.xjrsoft.module.base.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xjrsoft.common.exception.MyException;
import com.xjrsoft.common.model.result.RT;
import com.xjrsoft.module.base.dto.BaseClassroomChangeStatusDto;
import com.xjrsoft.module.base.entity.BaseClassroom;
import com.xjrsoft.module.base.service.IBaseClassroomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
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;

/**
* @title: 场所管理
* @Author dzx
* @Date: 2024年3月28日
* @Version 1.0
*/
@RestController
@RequestMapping("/classroom")
@Api(value = "/classroom",tags = "场所管理")
@AllArgsConstructor
public class ClassroomController {
    private final IBaseClassroomService baseClassroomService;


    @PostMapping(value = "/change-status")
    @ApiOperation(value="修改状态")
    @SaCheckPermission("classroom:detail")
    public RT<Boolean> changeStatus(@Valid @RequestBody BaseClassroomChangeStatusDto dto) throws Exception {
        BaseClassroom classroom = baseClassroomService.getById(dto.getId());
        if(classroom == null){
            throw new MyException("未能找到场所信息");
        }
        classroom.setStatus(dto.getStatus());
        baseClassroomService.updateById(classroom);
        return RT.ok(true);
    }

    @DeleteMapping
    @ApiOperation(value = "删除")
    @SaCheckPermission("classroom:delete")
    public RT<Boolean> delete(@Valid @RequestBody Long id){
        return RT.ok(baseClassroomService.removeById(id));
    }
}