feat(admin): add comprehensive admin management system
- Add admin handlers and services for users, posts, comments, groups, and dashboard - Implement role permission management with ability to view and update permissions - Add database seeding for roles and Casbin permission policies - Upgrade Casbin from v2 to v3 with GORM adapter for persistent policy storage - Add admin-specific repository methods with filtering and pagination - Register new admin API routes under /api/v1/admin/*
This commit is contained in:
@@ -30,6 +30,9 @@ type RoleRepository interface {
|
||||
|
||||
// GetAllRoles 获取所有角色
|
||||
GetAllRoles(ctx context.Context) ([]model.Role, error)
|
||||
|
||||
// GetRoleUserCount 获取角色对应的用户数量
|
||||
GetRoleUserCount(ctx context.Context, role string) (int64, error)
|
||||
}
|
||||
|
||||
type roleRepository struct {
|
||||
@@ -95,3 +98,12 @@ func (r *roleRepository) GetAllRoles(ctx context.Context) ([]model.Role, error)
|
||||
err := r.db.WithContext(ctx).Order("priority DESC").Find(&roles).Error
|
||||
return roles, err
|
||||
}
|
||||
|
||||
func (r *roleRepository) GetRoleUserCount(ctx context.Context, role string) (int64, error) {
|
||||
var count int64
|
||||
err := r.db.WithContext(ctx).
|
||||
Model(&model.UserRole{}).
|
||||
Where("role = ?", role).
|
||||
Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user