package com.neusoft.smart.pos.user.controller;

import com.neusoft.smart.pos.dto.user.TreeNode;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.user.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/permission")
public class PermissionsController {
    @Autowired
    PermissionService permissionService;

    @GetMapping("/all/{id}")
    public ResponseData<List<TreeNode>> all(@PathVariable Integer id) {
        return new ResponseData<>(permissionService.userPermissionList(id));
    }

    @GetMapping("/checked/{id}")
    public ResponseData<Set<Integer>> checked(@PathVariable Integer id) {
        return new ResponseData<>(permissionService.checked(id));
    }

    @PostMapping("/checked/{id}")
    public ResponseData check(@PathVariable Integer id, @RequestBody List<Integer> checked) {
        permissionService.check(id, checked);
        return new ResponseData();
    }

}
