package com.huimv.management.controller;

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

import com.huimv.management.limit.annotation.Limit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huimv.management.entity.TestEntity;
import com.huimv.management.service.TestService;
import com.huimv.common.utils.PageUtils;
import com.huimv.common.utils.R;


/**
 * @author yinhao
 * @email yinhao@163.com
 * @date 2021-04-28 19:33:24
 */
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private TestService testService;

    /**
     * 列表
     */
    @Limit(key = "test_list",name = "test/list",prefix = "management")
    @RequestMapping("/list")
    //@RequiresPermissions("management:test:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = testService.queryPage(params);

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


    /**
     * 信息
     */
    @RequestMapping("/info/{name}")
    //@RequiresPermissions("management:test:info")
    public R info(@PathVariable("name") String name) {
        TestEntity test = testService.getById(name);

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

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("management:test:save")
    public R save(@RequestBody TestEntity test) {
        testService.save(test);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("management:test:update")
    public R update(@RequestBody TestEntity test) {
        testService.updateById(test);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("management:test:delete")
    public R delete(@RequestBody String[] names) {
        testService.removeByIds(Arrays.asList(names));

        return R.ok();
    }

}
