package com.izouma.nineth.web;

import com.izouma.nineth.repo.AuthorityRepo;
import com.izouma.nineth.security.Authority;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/authority")
@AllArgsConstructor
public class AuthorityController extends BaseController {
    private AuthorityRepo authorityRepo;

    @PreAuthorize("hasRole('ADMIN')")
    @GetMapping("/all")
    public List<Authority> all() {
        return authorityRepo.findAll();
    }

    @PreAuthorize("hasRole('ADMIN')")
    @PostMapping("/save")
    public Authority save(Authority authority) {
        return authorityRepo.save(authority);
    }
}
