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:
@@ -50,6 +50,56 @@ type UserDetailResponse struct {
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
// ==================== Admin User DTOs ====================
|
||||
|
||||
// AdminUserListResponse 管理端用户列表响应
|
||||
type AdminUserListResponse struct {
|
||||
ID string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Nickname string `json:"nickname"`
|
||||
Email *string `json:"email,omitempty"`
|
||||
Phone *string `json:"phone,omitempty"`
|
||||
EmailVerified bool `json:"email_verified"`
|
||||
Avatar string `json:"avatar"`
|
||||
Status string `json:"status"`
|
||||
PostsCount int `json:"posts_count"`
|
||||
FollowersCount int `json:"followers_count"`
|
||||
FollowingCount int `json:"following_count"`
|
||||
LastLoginAt string `json:"last_login_at,omitempty"`
|
||||
LastLoginIP string `json:"last_login_ip,omitempty"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
// AdminUserDetailResponse 管理端用户详情响应
|
||||
type AdminUserDetailResponse struct {
|
||||
ID string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Nickname string `json:"nickname"`
|
||||
Email *string `json:"email"`
|
||||
Phone *string `json:"phone"`
|
||||
EmailVerified bool `json:"email_verified"`
|
||||
Avatar string `json:"avatar"`
|
||||
CoverURL string `json:"cover_url"`
|
||||
Bio string `json:"bio"`
|
||||
Website string `json:"website"`
|
||||
Location string `json:"location"`
|
||||
IsVerified bool `json:"is_verified"`
|
||||
Status string `json:"status"`
|
||||
PostsCount int `json:"posts_count"`
|
||||
CommentsCount int64 `json:"comments_count"`
|
||||
FollowersCount int `json:"followers_count"`
|
||||
FollowingCount int `json:"following_count"`
|
||||
LastLoginAt string `json:"last_login_at,omitempty"`
|
||||
LastLoginIP string `json:"last_login_ip,omitempty"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
// AdminUpdateUserStatusRequest 更新用户状态请求
|
||||
type AdminUpdateUserStatusRequest struct {
|
||||
Status string `json:"status" binding:"required,oneof=active banned"`
|
||||
}
|
||||
|
||||
// ==================== Post DTOs ====================
|
||||
|
||||
// PostImageResponse 帖子图片响应
|
||||
@@ -819,3 +869,293 @@ type WSResponse struct {
|
||||
Data interface{} `json:"data,omitempty"` // 响应数据
|
||||
Error string `json:"error,omitempty"` // 错误信息
|
||||
}
|
||||
|
||||
// ==================== Admin Post DTOs ====================
|
||||
|
||||
// AdminPostListResponse 管理端帖子列表响应
|
||||
type AdminPostListResponse struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Images []PostImageResponse `json:"images"`
|
||||
Status string `json:"status"`
|
||||
LikesCount int `json:"likes_count"`
|
||||
CommentsCount int `json:"comments_count"`
|
||||
FavoritesCount int `json:"favorites_count"`
|
||||
ViewsCount int `json:"views_count"`
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
IsFeatured bool `json:"is_featured"`
|
||||
IsLocked bool `json:"is_locked"`
|
||||
RejectReason string `json:"reject_reason,omitempty"`
|
||||
ReviewedAt string `json:"reviewed_at,omitempty"`
|
||||
ReviewedBy string `json:"reviewed_by,omitempty"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
Author *UserResponse `json:"author"`
|
||||
}
|
||||
|
||||
// AdminPostDetailResponse 管理端帖子详情响应
|
||||
type AdminPostDetailResponse struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
CommunityID string `json:"community_id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Images []PostImageResponse `json:"images"`
|
||||
Status string `json:"status"`
|
||||
LikesCount int `json:"likes_count"`
|
||||
CommentsCount int `json:"comments_count"`
|
||||
FavoritesCount int `json:"favorites_count"`
|
||||
SharesCount int `json:"shares_count"`
|
||||
ViewsCount int `json:"views_count"`
|
||||
HotScore float64 `json:"hot_score"`
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
IsFeatured bool `json:"is_featured"`
|
||||
IsLocked bool `json:"is_locked"`
|
||||
IsVote bool `json:"is_vote"`
|
||||
RejectReason string `json:"reject_reason,omitempty"`
|
||||
ReviewedAt string `json:"reviewed_at,omitempty"`
|
||||
ReviewedBy string `json:"reviewed_by,omitempty"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
Author *UserResponse `json:"author"`
|
||||
}
|
||||
|
||||
// AdminModeratePostRequest 审核帖子请求
|
||||
type AdminModeratePostRequest struct {
|
||||
Status string `json:"status" binding:"required,oneof=published rejected"`
|
||||
Reason string `json:"reason"` // 拒绝理由(当status为rejected时)
|
||||
}
|
||||
|
||||
// AdminBatchDeletePostsRequest 批量删除帖子请求
|
||||
type AdminBatchDeletePostsRequest struct {
|
||||
IDs []string `json:"ids" binding:"required,min=1"`
|
||||
}
|
||||
|
||||
// AdminBatchModeratePostsRequest 批量审核帖子请求
|
||||
type AdminBatchModeratePostsRequest struct {
|
||||
IDs []string `json:"ids" binding:"required,min=1"`
|
||||
Status string `json:"status" binding:"required,oneof=published rejected"`
|
||||
}
|
||||
|
||||
// AdminSetPostPinRequest 置顶帖子请求
|
||||
type AdminSetPostPinRequest struct {
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
}
|
||||
|
||||
// AdminSetPostFeatureRequest 加精帖子请求
|
||||
type AdminSetPostFeatureRequest struct {
|
||||
IsFeatured bool `json:"is_featured"`
|
||||
}
|
||||
|
||||
// AdminBatchOperationResponse 批量操作响应
|
||||
type AdminBatchOperationResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
Failed []string `json:"failed,omitempty"` // 失败的ID列表
|
||||
}
|
||||
|
||||
// ==================== Admin Comment DTOs ====================
|
||||
|
||||
// AdminCommentListResponse 管理端评论列表响应
|
||||
type AdminCommentListResponse struct {
|
||||
ID string `json:"id"`
|
||||
PostID string `json:"post_id"`
|
||||
UserID string `json:"user_id"`
|
||||
ParentID *string `json:"parent_id"`
|
||||
RootID *string `json:"root_id"`
|
||||
Content string `json:"content"`
|
||||
Images []CommentImageResponse `json:"images"`
|
||||
Status string `json:"status"`
|
||||
LikesCount int `json:"likes_count"`
|
||||
RepliesCount int `json:"replies_count"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
Author *UserResponse `json:"author"`
|
||||
Post *AdminCommentPostInfo `json:"post"`
|
||||
}
|
||||
|
||||
// AdminCommentPostInfo 评论关联的帖子简要信息
|
||||
type AdminCommentPostInfo struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
// AdminCommentDetailResponse 管理端评论详情响应
|
||||
type AdminCommentDetailResponse struct {
|
||||
ID string `json:"id"`
|
||||
PostID string `json:"post_id"`
|
||||
UserID string `json:"user_id"`
|
||||
ParentID *string `json:"parent_id"`
|
||||
RootID *string `json:"root_id"`
|
||||
Content string `json:"content"`
|
||||
Images []CommentImageResponse `json:"images"`
|
||||
Status string `json:"status"`
|
||||
LikesCount int `json:"likes_count"`
|
||||
RepliesCount int `json:"replies_count"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
Author *UserResponse `json:"author"`
|
||||
Post *AdminCommentPostInfo `json:"post"`
|
||||
ReplyToUser *UserResponse `json:"reply_to_user,omitempty"` // 被回复的用户信息
|
||||
}
|
||||
|
||||
// AdminBatchDeleteCommentsRequest 批量删除评论请求
|
||||
type AdminBatchDeleteCommentsRequest struct {
|
||||
IDs []string `json:"ids" binding:"required,min=1"`
|
||||
}
|
||||
|
||||
// ==================== Admin Group DTOs ====================
|
||||
|
||||
// AdminGroupListResponse 管理端群组列表响应
|
||||
type AdminGroupListResponse struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"avatar"`
|
||||
Description string `json:"description"`
|
||||
OwnerID string `json:"owner_id"`
|
||||
Owner *UserResponse `json:"owner"`
|
||||
MemberCount int `json:"member_count"`
|
||||
MaxMembers int `json:"max_members"`
|
||||
JoinType int `json:"join_type"`
|
||||
MuteAll bool `json:"mute_all"`
|
||||
Status string `json:"status"`
|
||||
PostCount int64 `json:"post_count"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
// AdminGroupDetailResponse 管理端群组详情响应
|
||||
type AdminGroupDetailResponse struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"avatar"`
|
||||
Description string `json:"description"`
|
||||
OwnerID string `json:"owner_id"`
|
||||
Owner *UserResponse `json:"owner"`
|
||||
MemberCount int `json:"member_count"`
|
||||
MaxMembers int `json:"max_members"`
|
||||
JoinType int `json:"join_type"`
|
||||
MuteAll bool `json:"mute_all"`
|
||||
Status string `json:"status"`
|
||||
PostCount int64 `json:"post_count"`
|
||||
Announcement *GroupAnnouncementResponse `json:"announcement,omitempty"`
|
||||
IsPublic bool `json:"is_public"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
// AdminGroupMemberResponse 管理端群组成员响应
|
||||
type AdminGroupMemberResponse struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
Username string `json:"username"`
|
||||
Nickname string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
Role string `json:"role"`
|
||||
Muted bool `json:"muted"`
|
||||
JoinedAt string `json:"joined_at"`
|
||||
User *UserResponse `json:"user,omitempty"`
|
||||
}
|
||||
|
||||
// AdminGroupMemberListResponse 管理端群组成员列表响应
|
||||
type AdminGroupMemberListResponse struct {
|
||||
List []*AdminGroupMemberResponse `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
|
||||
// AdminUpdateGroupStatusRequest 更新群组状态请求
|
||||
type AdminUpdateGroupStatusRequest struct {
|
||||
Status string `json:"status" binding:"required,oneof=active dissolved"`
|
||||
}
|
||||
|
||||
// AdminTransferGroupOwnerRequest 转让群主请求
|
||||
type AdminTransferGroupOwnerRequest struct {
|
||||
NewOwnerID string `json:"new_owner_id" binding:"required"`
|
||||
}
|
||||
|
||||
// ==================== Admin Dashboard DTOs ====================
|
||||
|
||||
// DashboardStatsResponse 仪表盘统计数据响应
|
||||
type DashboardStatsResponse struct {
|
||||
TotalUsers int64 `json:"total_users"` // 总用户数
|
||||
TodayNewUsers int64 `json:"today_new_users"` // 今日新增用户
|
||||
ActiveUsersToday int64 `json:"active_users_today"` // 今日活跃用户 (DAU)
|
||||
ActiveUsersWeek int64 `json:"active_users_week"` // 本周活跃用户 (WAU)
|
||||
ActiveUsersMonth int64 `json:"active_users_month"` // 本月活跃用户 (MAU)
|
||||
Retention1Day int64 `json:"retention_1_day"` // 次日留存率 (百分比 0-100)
|
||||
Retention7Day int64 `json:"retention_7_day"` // 7日留存率 (百分比 0-100)
|
||||
Retention30Day int64 `json:"retention_30_day"` // 30日留存率 (百分比 0-100)
|
||||
TotalPosts int64 `json:"total_posts"` // 总帖子数
|
||||
TodayPosts int64 `json:"today_posts"` // 今日帖子数
|
||||
PendingPosts int64 `json:"pending_posts"` // 待审核帖子数
|
||||
TotalComments int64 `json:"total_comments"` // 总评论数
|
||||
TodayComments int64 `json:"today_comments"` // 今日评论数
|
||||
TotalGroups int64 `json:"total_groups"` // 总群组数
|
||||
TodayNewGroups int64 `json:"today_new_groups"` // 今日新建群组
|
||||
PendingReview int64 `json:"pending_review"` // 待审核总数
|
||||
PendingPostsCount int64 `json:"pending_posts_count"` // 待审核帖子数
|
||||
PendingComments int64 `json:"pending_comments_count"` // 待审核评论数
|
||||
}
|
||||
|
||||
// UserActivityTrendResponse 用户活跃度趋势响应
|
||||
type UserActivityTrendResponse struct {
|
||||
Date string `json:"date"` // 日期
|
||||
NewUsers int64 `json:"new_users"` // 新增用户数
|
||||
ActiveUsers int64 `json:"active_users"` // 活跃用户数
|
||||
Posts int64 `json:"posts"` // 帖子数
|
||||
Comments int64 `json:"comments"` // 评论数
|
||||
}
|
||||
|
||||
// ContentStatsResponse 内容统计响应
|
||||
type ContentStatsResponse struct {
|
||||
ContentDistribution []ContentDistributionItem `json:"content_distribution"` // 内容分布
|
||||
PostStatusDistribution []PostStatusDistributionItem `json:"post_status_distribution"` // 帖子状态分布
|
||||
UserGrowth []UserGrowthItem `json:"user_growth"` // 用户增长趋势
|
||||
}
|
||||
|
||||
// ContentDistributionItem 内容分布项
|
||||
type ContentDistributionItem struct {
|
||||
Type string `json:"type"` // 类型:posts, comments, groups
|
||||
Name string `json:"name"` // 名称
|
||||
Count int64 `json:"count"` // 数量
|
||||
}
|
||||
|
||||
// PostStatusDistributionItem 帖子状态分布项
|
||||
type PostStatusDistributionItem struct {
|
||||
Status string `json:"status"` // 状态
|
||||
Name string `json:"name"` // 名称
|
||||
Count int64 `json:"count"` // 数量
|
||||
}
|
||||
|
||||
// UserGrowthItem 用户增长项
|
||||
type UserGrowthItem struct {
|
||||
Date string `json:"date"` // 日期
|
||||
NewUsers int64 `json:"new_users"` // 新增用户数
|
||||
}
|
||||
|
||||
// PendingContentResponse 待审核内容响应
|
||||
type PendingContentResponse struct {
|
||||
ID string `json:"id"` // 内容ID
|
||||
Type string `json:"type"` // 内容类型(post/comment)
|
||||
Title string `json:"title"` // 标题(帖子有,评论可能为空)
|
||||
Content string `json:"content"` // 内容
|
||||
Author *PendingContentAuthor `json:"author"` // 作者信息
|
||||
CreatedAt string `json:"created_at"` // 创建时间
|
||||
}
|
||||
|
||||
// PendingContentAuthor 待审核内容作者信息
|
||||
type PendingContentAuthor struct {
|
||||
ID string `json:"id"` // 用户ID
|
||||
Username string `json:"username"` // 用户名
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
}
|
||||
|
||||
// OnlineUsersResponse 在线用户数响应
|
||||
type OnlineUsersResponse struct {
|
||||
Count int64 `json:"count"` // 在线用户数
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user