package com.hs.api.unusecontroller;

import com.hs.api.common.base.RequestResult;
import com.hs.api.common.enums.RequestResultType;
import com.hs.api.model.SysUserRoleRs;
import com.hs.api.model.respmodel.ListPage;
import com.hs.api.service.SysUserRoleRsService;
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("userRole")
@RestController
public class SysUserRoleRsController {
    @Autowired
    private SysUserRoleRsService sysUserRoleRsService;


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

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

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

    @PostMapping("add")
    public Object add(SysUserRoleRs sysUserRoleRs) {
        sysUserRoleRsService.add(sysUserRoleRs);
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),null);
    }

    @PostMapping("update")
    public Object update(SysUserRoleRs sysUserRoleRs) {
        sysUserRoleRsService.update(sysUserRoleRs);
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),null);
    }

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