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:
2026-03-14 18:01:55 +08:00
parent ae5b997924
commit d3065b30cc
28 changed files with 4018 additions and 107 deletions

View File

@@ -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
}