package io.renren.modules.generator.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.generator.entity.VolumesEntity;
import io.renren.modules.generator.service.VolumesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-07-30 15:08:06
 */
@RestController
@RequestMapping("generator/volumes")
public class VolumesController {
    @Autowired
    private VolumesService volumesService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:volumes:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = volumesService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{volumesId}")
    @RequiresPermissions("generator:volumes:info")
    public R info(@PathVariable("volumesId") Integer volumesId) {
        VolumesEntity volumes = volumesService.getById(volumesId);

        return R.ok().put("volumes", volumes);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:volumes:save")
    public R save(@RequestBody VolumesEntity volumes) {
        volumesService.save(volumes);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:volumes:update")
    public R update(@RequestBody VolumesEntity volumes) {
        volumesService.updateById(volumes);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:volumes:delete")
    public R delete(@RequestBody Integer[] volumesIds) {
        volumesService.removeByIds(Arrays.asList(volumesIds));

        return R.ok();
    }

}
