feat: 查询权限信息列表
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.onixbyte.helix.controller;
|
||||
|
||||
import com.onixbyte.helix.domain.entity.Authority;
|
||||
import com.onixbyte.helix.domain.web.request.QueryAuthorityRequest;
|
||||
import com.onixbyte.helix.service.AuthorityService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/authorities")
|
||||
public class AuthorityController {
|
||||
|
||||
private final AuthorityService authorityService;
|
||||
|
||||
public AuthorityController(AuthorityService authorityService) {
|
||||
this.authorityService = authorityService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Page<Authority> getAuthorities(
|
||||
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(required = false, defaultValue = "10") Integer pageSize,
|
||||
@Validated @ModelAttribute QueryAuthorityRequest request
|
||||
) {
|
||||
var pageRequest = PageRequest.of(pageNum - 1, pageSize);
|
||||
return authorityService.getAuthorities(pageRequest, request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.onixbyte.helix.domain.web.request;
|
||||
|
||||
public record QueryAuthorityRequest() {
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.onixbyte.helix.manager;
|
||||
|
||||
import com.onixbyte.helix.repository.AuthorityRepository;
|
||||
import com.onixbyte.helix.shared.CacheName;
|
||||
import com.onixbyte.helix.domain.entity.Authority;
|
||||
import com.onixbyte.helix.mapper.AuthorityMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
@@ -13,14 +16,20 @@ import java.util.List;
|
||||
public class AuthorityManager {
|
||||
|
||||
private final AuthorityMapper authorityMapper;
|
||||
private final AuthorityRepository authorityRepository;
|
||||
|
||||
@Autowired
|
||||
public AuthorityManager(AuthorityMapper authorityMapper) {
|
||||
public AuthorityManager(AuthorityMapper authorityMapper, AuthorityRepository authorityRepository) {
|
||||
this.authorityMapper = authorityMapper;
|
||||
this.authorityRepository = authorityRepository;
|
||||
}
|
||||
|
||||
@Cacheable(cacheNames = CacheName.AUTHORITIES_OF_USER, key = "#userId")
|
||||
public List<Authority> queryByUserId(Long userId) {
|
||||
return authorityMapper.selectByUserId(userId);
|
||||
}
|
||||
|
||||
public Page<Authority> selectAll(Pageable pageable) {
|
||||
return authorityRepository.findAll(pageable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.onixbyte.helix.service;
|
||||
|
||||
import com.onixbyte.helix.domain.entity.Authority;
|
||||
import com.onixbyte.helix.domain.web.request.QueryAuthorityRequest;
|
||||
import com.onixbyte.helix.manager.AuthorityManager;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class AuthorityService {
|
||||
|
||||
private final AuthorityManager authorityManager;
|
||||
|
||||
public AuthorityService(AuthorityManager authorityManager) {
|
||||
this.authorityManager = authorityManager;
|
||||
}
|
||||
|
||||
public Page<Authority> getAuthorities(Pageable pageable, QueryAuthorityRequest request) {
|
||||
return authorityManager.selectAll(pageable);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user