feature/flea-market #4

Merged
lan merged 2 commits from feature/flea-market into master 2026-04-26 19:44:32 +08:00
3 changed files with 162 additions and 121 deletions

View File

@@ -24,6 +24,9 @@ type UserResponse struct {
IsFollowing bool `json:"is_following"` IsFollowing bool `json:"is_following"`
IsFollowingMe bool `json:"is_following_me"` IsFollowingMe bool `json:"is_following_me"`
CreatedAt string `json:"created_at"` CreatedAt string `json:"created_at"`
// 认证信息
Identity model.UserIdentity `json:"identity,omitempty"`
VerificationStatus model.VerificationStatus `json:"verification_status,omitempty"`
} }
// UserSelfResponse 用户自身信息响应(包含敏感信息,仅本人可见) // UserSelfResponse 用户自身信息响应(包含敏感信息,仅本人可见)
@@ -46,6 +49,9 @@ type UserSelfResponse struct {
CreatedAt string `json:"created_at"` CreatedAt string `json:"created_at"`
// 隐私设置 // 隐私设置
PrivacySettings *PrivacySettingsResponse `json:"privacy_settings,omitempty"` PrivacySettings *PrivacySettingsResponse `json:"privacy_settings,omitempty"`
// 认证信息
Identity model.UserIdentity `json:"identity,omitempty"`
VerificationStatus model.VerificationStatus `json:"verification_status,omitempty"`
} }
// UserDetailResponse 用户详情响应(仅本人可见,包含敏感信息) // UserDetailResponse 用户详情响应(仅本人可见,包含敏感信息)
@@ -70,6 +76,9 @@ type UserDetailResponse struct {
CreatedAt string `json:"created_at"` CreatedAt string `json:"created_at"`
// 隐私设置 // 隐私设置
PrivacySettings *PrivacySettingsResponse `json:"privacy_settings,omitempty"` PrivacySettings *PrivacySettingsResponse `json:"privacy_settings,omitempty"`
// 认证信息
Identity model.UserIdentity `json:"identity,omitempty"`
VerificationStatus model.VerificationStatus `json:"verification_status,omitempty"`
} }
// ==================== Admin User DTOs ==================== // ==================== Admin User DTOs ====================

View File

@@ -12,11 +12,22 @@ func getAvatarOrDefault(user *model.User) string {
return utils.GetAvatarOrDefault(user.Username, user.Nickname, user.Avatar) return utils.GetAvatarOrDefault(user.Username, user.Nickname, user.Avatar)
} }
// publicVerificationFields 返回认证信息:
// - approved 时返回真实身份和状态
// - 其他状态统一返回 general + none不暴露具体审核状态
func publicVerificationFields(user *model.User) (model.UserIdentity, model.VerificationStatus) {
if user.VerificationStatus == model.VerificationStatusApproved {
return user.Identity, user.VerificationStatus
}
return model.UserIdentityGeneral, model.VerificationStatusNone
}
// ConvertUserToResponse 将User转换为UserResponse公开信息不包含敏感数据 // ConvertUserToResponse 将User转换为UserResponse公开信息不包含敏感数据
func ConvertUserToResponse(user *model.User) *UserResponse { func ConvertUserToResponse(user *model.User) *UserResponse {
if user == nil { if user == nil {
return nil return nil
} }
identity, vs := publicVerificationFields(user)
return &UserResponse{ return &UserResponse{
ID: user.ID, ID: user.ID,
Username: user.Username, Username: user.Username,
@@ -31,6 +42,8 @@ func ConvertUserToResponse(user *model.User) *UserResponse {
FollowersCount: user.FollowersCount, FollowersCount: user.FollowersCount,
FollowingCount: user.FollowingCount, FollowingCount: user.FollowingCount,
CreatedAt: FormatTime(user.CreatedAt), CreatedAt: FormatTime(user.CreatedAt),
Identity: identity,
VerificationStatus: vs,
} }
} }
@@ -57,6 +70,8 @@ func ConvertUserToSelfResponse(user *model.User, postsCount int) *UserSelfRespon
IsVerified: user.IsVerified, IsVerified: user.IsVerified,
CreatedAt: FormatTime(user.CreatedAt), CreatedAt: FormatTime(user.CreatedAt),
PrivacySettings: convertPrivacySettingsToResponse(&user.PrivacySettings), PrivacySettings: convertPrivacySettingsToResponse(&user.PrivacySettings),
Identity: user.Identity,
VerificationStatus: user.VerificationStatus,
} }
} }
@@ -77,6 +92,7 @@ func ConvertUserToResponseWithFollowing(user *model.User, isFollowing bool) *Use
if user == nil { if user == nil {
return nil return nil
} }
identity, vs := publicVerificationFields(user)
return &UserResponse{ return &UserResponse{
ID: user.ID, ID: user.ID,
Username: user.Username, Username: user.Username,
@@ -93,6 +109,8 @@ func ConvertUserToResponseWithFollowing(user *model.User, isFollowing bool) *Use
IsFollowing: isFollowing, IsFollowing: isFollowing,
IsFollowingMe: false, IsFollowingMe: false,
CreatedAt: FormatTime(user.CreatedAt), CreatedAt: FormatTime(user.CreatedAt),
Identity: identity,
VerificationStatus: vs,
} }
} }
@@ -101,6 +119,7 @@ func ConvertUserToResponseWithPostsCount(user *model.User, postsCount int) *User
if user == nil { if user == nil {
return nil return nil
} }
identity, vs := publicVerificationFields(user)
return &UserResponse{ return &UserResponse{
ID: user.ID, ID: user.ID,
Username: user.Username, Username: user.Username,
@@ -115,6 +134,8 @@ func ConvertUserToResponseWithPostsCount(user *model.User, postsCount int) *User
FollowersCount: user.FollowersCount, FollowersCount: user.FollowersCount,
FollowingCount: user.FollowingCount, FollowingCount: user.FollowingCount,
CreatedAt: FormatTime(user.CreatedAt), CreatedAt: FormatTime(user.CreatedAt),
Identity: identity,
VerificationStatus: vs,
} }
} }
@@ -123,6 +144,7 @@ func ConvertUserToResponseWithMutualFollow(user *model.User, isFollowing, isFoll
if user == nil { if user == nil {
return nil return nil
} }
identity, vs := publicVerificationFields(user)
return &UserResponse{ return &UserResponse{
ID: user.ID, ID: user.ID,
Username: user.Username, Username: user.Username,
@@ -139,6 +161,8 @@ func ConvertUserToResponseWithMutualFollow(user *model.User, isFollowing, isFoll
IsFollowing: isFollowing, IsFollowing: isFollowing,
IsFollowingMe: isFollowingMe, IsFollowingMe: isFollowingMe,
CreatedAt: FormatTime(user.CreatedAt), CreatedAt: FormatTime(user.CreatedAt),
Identity: identity,
VerificationStatus: vs,
} }
} }
@@ -147,6 +171,7 @@ func ConvertUserToResponseWithMutualFollowAndPostsCount(user *model.User, isFoll
if user == nil { if user == nil {
return nil return nil
} }
identity, vs := publicVerificationFields(user)
return &UserResponse{ return &UserResponse{
ID: user.ID, ID: user.ID,
Username: user.Username, Username: user.Username,
@@ -163,6 +188,8 @@ func ConvertUserToResponseWithMutualFollowAndPostsCount(user *model.User, isFoll
IsFollowing: isFollowing, IsFollowing: isFollowing,
IsFollowingMe: isFollowingMe, IsFollowingMe: isFollowingMe,
CreatedAt: FormatTime(user.CreatedAt), CreatedAt: FormatTime(user.CreatedAt),
Identity: identity,
VerificationStatus: vs,
} }
} }
@@ -188,6 +215,8 @@ func ConvertUserToDetailResponse(user *model.User) *UserDetailResponse {
IsVerified: user.IsVerified, IsVerified: user.IsVerified,
CreatedAt: FormatTime(user.CreatedAt), CreatedAt: FormatTime(user.CreatedAt),
PrivacySettings: convertPrivacySettingsToResponse(&user.PrivacySettings), PrivacySettings: convertPrivacySettingsToResponse(&user.PrivacySettings),
Identity: user.Identity,
VerificationStatus: user.VerificationStatus,
} }
} }
@@ -214,6 +243,8 @@ func ConvertUserToDetailResponseWithPostsCount(user *model.User, postsCount int)
IsVerified: user.IsVerified, IsVerified: user.IsVerified,
CreatedAt: FormatTime(user.CreatedAt), CreatedAt: FormatTime(user.CreatedAt),
PrivacySettings: convertPrivacySettingsToResponse(&user.PrivacySettings), PrivacySettings: convertPrivacySettingsToResponse(&user.PrivacySettings),
Identity: user.Identity,
VerificationStatus: user.VerificationStatus,
} }
} }

View File

@@ -54,6 +54,7 @@ const (
VerificationStatusPending VerificationStatus = "pending" // 审核中 VerificationStatusPending VerificationStatus = "pending" // 审核中
VerificationStatusApproved VerificationStatus = "approved" // 已通过 VerificationStatusApproved VerificationStatus = "approved" // 已通过
VerificationStatusRejected VerificationStatus = "rejected" // 已拒绝 VerificationStatusRejected VerificationStatus = "rejected" // 已拒绝
VerificationStatusNone VerificationStatus = "none" // 无认证(对外展示用)
) )
// User 用户实体 // User 用户实体