package com.ruoyi.platform.controller.devEnvironment;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.platform.domain.DevEnvironment;
import com.ruoyi.platform.service.DevEnvironmentService;
import com.ruoyi.platform.vo.DevEnvironmentVo;
import io.swagger.annotations.Api;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (DevEnvironment)表控制层
 *
 * @author Xidaray
 * @since 2024-06-03 15:17:37
 */
@RestController
@RequestMapping("devEnvironment")
@Api("开发环境管理")
public class DevEnvironmentController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private DevEnvironmentService devEnvironmentService;

    /**
     * 分页查询
     *
     * @param devEnvironment 筛选条件
     * @param page 页数
     * @param size 每页大小
     * @return 查询结果
     */
    @GetMapping
    public GenericsAjaxResult<Page<DevEnvironment>> queryByPage(DevEnvironment devEnvironment, int page, int size) {
        PageRequest pageRequest = PageRequest.of(page,size);
        return genericsSuccess(this.devEnvironmentService.queryByPage(devEnvironment, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<DevEnvironment> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.devEnvironmentService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param devEnvironmentVo 实体
     * @return 新增结果
     */
    @PostMapping
    public GenericsAjaxResult<DevEnvironment> add(@RequestBody DevEnvironmentVo devEnvironmentVo) throws Exception {
        return genericsSuccess(this.devEnvironmentService.insert(devEnvironmentVo));
    }

    /**
     * 编辑数据
     *
     * @param devEnvironment 实体
     * @return 编辑结果
     */
    @PutMapping
    public GenericsAjaxResult<DevEnvironment> edit(@RequestBody DevEnvironment devEnvironment) throws Exception {
        return genericsSuccess(this.devEnvironmentService.update(devEnvironment));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("{id}")
    public GenericsAjaxResult<String> deleteById(@PathVariable("id") Integer id) throws Exception {
        return genericsSuccess(this.devEnvironmentService.removeById(id));
    }

}

