package com.hs.api.unusecontroller;

import com.hs.api.common.base.RequestResult;
import com.hs.api.common.enums.RequestResultType;
import com.hs.api.model.SysRole;
import com.hs.api.model.respmodel.ListPage;
import com.hs.api.service.SysRoleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = {"角色"}, hidden = true)
@RequestMapping("role")
@RestController
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;


    @GetMapping("list")
    public Object list() {
        List<SysRole> list = sysRoleService.findAll();
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),list);
    }

    @GetMapping("listpage")
    public Object listpage(Integer pageSize,Integer pageIndex) {
        List<SysRole> list = sysRoleService.findAll();
        ListPage<SysRole> listPage = new ListPage(list,pageSize,pageIndex,0);
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),list);
    }

    @GetMapping("info")
    public Object info(Long id) {
        sysRoleService.find(id);
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),null);
    }

    @PostMapping("add")
    public Object add(SysRole sysRole) {
        sysRoleService.add(sysRole);
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),null);
    }

    @PostMapping("update")
    public Object update(SysRole sysRole) {
        sysRoleService.update(sysRole);
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),null);
    }

    @PostMapping("delete")
    public Object delete(Long id) {
        sysRoleService.delete(id);
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),null);
    }
}
