package com.ruoyi.platform.controller.image;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.platform.domain.ImageVersion;
import com.ruoyi.platform.service.ImageVersionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (ImageVersion)表控制层
 *
 * @author Xidaray
 * @since 2024-03-05 15:00:02
 */
@RestController
@RequestMapping("imageVersion")
public class ImageVersionController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ImageVersionService imageVersionService;

    /**
     * 分页查询
     *
     * @param imageVersion 筛选条件
     * @param page         分页对象
     * @param size         分页对象
     * @return 查询结果
     */
    @GetMapping
    @ApiOperation("分页查询")
    public GenericsAjaxResult<Page<ImageVersion>> queryByPage(ImageVersion imageVersion, @RequestParam("page") int page,
                                                              @RequestParam("size") int size,
                                                              @RequestParam(value = "image_id") int imageId) {
        imageVersion.setImageId(imageId);
        PageRequest pageRequest = PageRequest.of(page,size);
        return genericsSuccess(this.imageVersionService.queryByPage(imageVersion, pageRequest));

    }



    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public GenericsAjaxResult<ImageVersion> queryById(@PathVariable("id") Integer id) {
        return genericsSuccess(this.imageVersionService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param imageVersion 实体
     * @return 新增结果
     */
    @PostMapping
    public GenericsAjaxResult<ImageVersion> add(@RequestBody ImageVersion imageVersion) {
        return genericsSuccess(this.imageVersionService.insert(imageVersion));
    }

    /**
     * 编辑数据
     *
     * @param imageVersion 实体
     * @return 编辑结果
     */
    @PutMapping
    public GenericsAjaxResult<ImageVersion> edit(@RequestBody ImageVersion imageVersion) {
        return genericsSuccess(this.imageVersionService.update(imageVersion));
    }

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

}

