package com.huimv.admin.controller.primary;


import com.huimv.admin.domain.primary.SysGroupEntity;
import com.huimv.admin.service.primary.IGroupService;
import com.huimv.admin.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@CrossOrigin
@RestController
@RequestMapping("/group")
public class SysGroupController {

    @Autowired
    private IGroupService groupService;

    @RequestMapping("/add")
    public Result addGroup (@RequestParam(name = "groupName") String groupName,
                          @RequestParam(name = "remark") String remark){
        return groupService.addGroup(groupName,remark);
    }


    @RequestMapping("/edit")
    public Result updateGroup( @RequestParam(name = "groupId",required = false) Integer groupId,
                             @RequestParam(name = "groupName") String groupName,
                             @RequestParam(name = "remark") String remark ){
        return groupService.updateGroup(groupId,groupName,remark);
    }

    @RequestMapping("/remove")
    public Result removeGroup( @RequestParam("groupId") Integer groupId) {
        return groupService.removeGroup(groupId);
    }

    @RequestMapping("/list")
    public Page<SysGroupEntity> listGroup(@RequestParam(name = "pageNum") int pageNum,
                                          @RequestParam(name = "pageSize") int pageSize,
                                          @RequestParam(name = "searchStr", required = false) String searchStr) {
        return groupService.listGroup(pageNum,pageSize,searchStr);
    }
}
