feat(user): add identity and verification status to user DTOs
Add Identity and VerificationStatus fields to UserResponse, UserSelfResponse, and UserDetailResponse. Only expose identity information when verification status is approved to protect privacy of pending/rejected applicants.
This commit is contained in:
@@ -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 ====================
|
||||||
|
|||||||
@@ -12,25 +12,36 @@ 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 仅在认证通过时返回身份和状态,避免泄漏审核中/已拒绝等隐私信息
|
||||||
|
func publicVerificationFields(user *model.User) (model.UserIdentity, model.VerificationStatus) {
|
||||||
|
if user.VerificationStatus == model.VerificationStatusApproved {
|
||||||
|
return user.Identity, user.VerificationStatus
|
||||||
|
}
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
|
|
||||||
// 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,
|
||||||
Nickname: user.Nickname,
|
Nickname: user.Nickname,
|
||||||
EmailVerified: user.EmailVerified,
|
EmailVerified: user.EmailVerified,
|
||||||
Avatar: getAvatarOrDefault(user),
|
Avatar: getAvatarOrDefault(user),
|
||||||
CoverURL: user.CoverURL,
|
CoverURL: user.CoverURL,
|
||||||
Bio: user.Bio,
|
Bio: user.Bio,
|
||||||
Website: user.Website,
|
Website: user.Website,
|
||||||
Location: user.Location,
|
Location: user.Location,
|
||||||
PostsCount: user.PostsCount,
|
PostsCount: user.PostsCount,
|
||||||
FollowersCount: user.FollowersCount,
|
FollowersCount: user.FollowersCount,
|
||||||
FollowingCount: user.FollowingCount,
|
FollowingCount: user.FollowingCount,
|
||||||
CreatedAt: FormatTime(user.CreatedAt),
|
CreatedAt: FormatTime(user.CreatedAt),
|
||||||
|
Identity: identity,
|
||||||
|
VerificationStatus: vs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,23 +51,25 @@ func ConvertUserToSelfResponse(user *model.User, postsCount int) *UserSelfRespon
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &UserSelfResponse{
|
return &UserSelfResponse{
|
||||||
ID: user.ID,
|
ID: user.ID,
|
||||||
Username: user.Username,
|
Username: user.Username,
|
||||||
Nickname: user.Nickname,
|
Nickname: user.Nickname,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
Phone: user.Phone,
|
Phone: user.Phone,
|
||||||
EmailVerified: user.EmailVerified,
|
EmailVerified: user.EmailVerified,
|
||||||
Avatar: getAvatarOrDefault(user),
|
Avatar: getAvatarOrDefault(user),
|
||||||
CoverURL: user.CoverURL,
|
CoverURL: user.CoverURL,
|
||||||
Bio: user.Bio,
|
Bio: user.Bio,
|
||||||
Website: user.Website,
|
Website: user.Website,
|
||||||
Location: user.Location,
|
Location: user.Location,
|
||||||
PostsCount: postsCount,
|
PostsCount: postsCount,
|
||||||
FollowersCount: user.FollowersCount,
|
FollowersCount: user.FollowersCount,
|
||||||
FollowingCount: user.FollowingCount,
|
FollowingCount: user.FollowingCount,
|
||||||
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,22 +90,25 @@ 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,
|
||||||
Nickname: user.Nickname,
|
Nickname: user.Nickname,
|
||||||
EmailVerified: user.EmailVerified,
|
EmailVerified: user.EmailVerified,
|
||||||
Avatar: getAvatarOrDefault(user),
|
Avatar: getAvatarOrDefault(user),
|
||||||
CoverURL: user.CoverURL,
|
CoverURL: user.CoverURL,
|
||||||
Bio: user.Bio,
|
Bio: user.Bio,
|
||||||
Website: user.Website,
|
Website: user.Website,
|
||||||
Location: user.Location,
|
Location: user.Location,
|
||||||
PostsCount: user.PostsCount,
|
PostsCount: user.PostsCount,
|
||||||
FollowersCount: user.FollowersCount,
|
FollowersCount: user.FollowersCount,
|
||||||
FollowingCount: user.FollowingCount,
|
FollowingCount: user.FollowingCount,
|
||||||
IsFollowing: isFollowing,
|
IsFollowing: isFollowing,
|
||||||
IsFollowingMe: false,
|
IsFollowingMe: false,
|
||||||
CreatedAt: FormatTime(user.CreatedAt),
|
CreatedAt: FormatTime(user.CreatedAt),
|
||||||
|
Identity: identity,
|
||||||
|
VerificationStatus: vs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,20 +117,23 @@ 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,
|
||||||
Nickname: user.Nickname,
|
Nickname: user.Nickname,
|
||||||
EmailVerified: user.EmailVerified,
|
EmailVerified: user.EmailVerified,
|
||||||
Avatar: getAvatarOrDefault(user),
|
Avatar: getAvatarOrDefault(user),
|
||||||
CoverURL: user.CoverURL,
|
CoverURL: user.CoverURL,
|
||||||
Bio: user.Bio,
|
Bio: user.Bio,
|
||||||
Website: user.Website,
|
Website: user.Website,
|
||||||
Location: user.Location,
|
Location: user.Location,
|
||||||
PostsCount: postsCount,
|
PostsCount: postsCount,
|
||||||
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,22 +142,25 @@ 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,
|
||||||
Nickname: user.Nickname,
|
Nickname: user.Nickname,
|
||||||
EmailVerified: user.EmailVerified,
|
EmailVerified: user.EmailVerified,
|
||||||
Avatar: getAvatarOrDefault(user),
|
Avatar: getAvatarOrDefault(user),
|
||||||
CoverURL: user.CoverURL,
|
CoverURL: user.CoverURL,
|
||||||
Bio: user.Bio,
|
Bio: user.Bio,
|
||||||
Website: user.Website,
|
Website: user.Website,
|
||||||
Location: user.Location,
|
Location: user.Location,
|
||||||
PostsCount: user.PostsCount,
|
PostsCount: user.PostsCount,
|
||||||
FollowersCount: user.FollowersCount,
|
FollowersCount: user.FollowersCount,
|
||||||
FollowingCount: user.FollowingCount,
|
FollowingCount: user.FollowingCount,
|
||||||
IsFollowing: isFollowing,
|
IsFollowing: isFollowing,
|
||||||
IsFollowingMe: isFollowingMe,
|
IsFollowingMe: isFollowingMe,
|
||||||
CreatedAt: FormatTime(user.CreatedAt),
|
CreatedAt: FormatTime(user.CreatedAt),
|
||||||
|
Identity: identity,
|
||||||
|
VerificationStatus: vs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,22 +169,25 @@ 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,
|
||||||
Nickname: user.Nickname,
|
Nickname: user.Nickname,
|
||||||
EmailVerified: user.EmailVerified,
|
EmailVerified: user.EmailVerified,
|
||||||
Avatar: getAvatarOrDefault(user),
|
Avatar: getAvatarOrDefault(user),
|
||||||
CoverURL: user.CoverURL,
|
CoverURL: user.CoverURL,
|
||||||
Bio: user.Bio,
|
Bio: user.Bio,
|
||||||
Website: user.Website,
|
Website: user.Website,
|
||||||
Location: user.Location,
|
Location: user.Location,
|
||||||
PostsCount: postsCount,
|
PostsCount: postsCount,
|
||||||
FollowersCount: user.FollowersCount,
|
FollowersCount: user.FollowersCount,
|
||||||
FollowingCount: user.FollowingCount,
|
FollowingCount: user.FollowingCount,
|
||||||
IsFollowing: isFollowing,
|
IsFollowing: isFollowing,
|
||||||
IsFollowingMe: isFollowingMe,
|
IsFollowingMe: isFollowingMe,
|
||||||
CreatedAt: FormatTime(user.CreatedAt),
|
CreatedAt: FormatTime(user.CreatedAt),
|
||||||
|
Identity: identity,
|
||||||
|
VerificationStatus: vs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,22 +197,24 @@ func ConvertUserToDetailResponse(user *model.User) *UserDetailResponse {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &UserDetailResponse{
|
return &UserDetailResponse{
|
||||||
ID: user.ID,
|
ID: user.ID,
|
||||||
Username: user.Username,
|
Username: user.Username,
|
||||||
Nickname: user.Nickname,
|
Nickname: user.Nickname,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
EmailVerified: user.EmailVerified,
|
EmailVerified: user.EmailVerified,
|
||||||
Avatar: getAvatarOrDefault(user),
|
Avatar: getAvatarOrDefault(user),
|
||||||
CoverURL: user.CoverURL,
|
CoverURL: user.CoverURL,
|
||||||
Bio: user.Bio,
|
Bio: user.Bio,
|
||||||
Website: user.Website,
|
Website: user.Website,
|
||||||
Location: user.Location,
|
Location: user.Location,
|
||||||
PostsCount: user.PostsCount,
|
PostsCount: user.PostsCount,
|
||||||
FollowersCount: user.FollowersCount,
|
FollowersCount: user.FollowersCount,
|
||||||
FollowingCount: user.FollowingCount,
|
FollowingCount: user.FollowingCount,
|
||||||
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,23 +224,25 @@ func ConvertUserToDetailResponseWithPostsCount(user *model.User, postsCount int)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &UserDetailResponse{
|
return &UserDetailResponse{
|
||||||
ID: user.ID,
|
ID: user.ID,
|
||||||
Username: user.Username,
|
Username: user.Username,
|
||||||
Nickname: user.Nickname,
|
Nickname: user.Nickname,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
EmailVerified: user.EmailVerified,
|
EmailVerified: user.EmailVerified,
|
||||||
Phone: user.Phone,
|
Phone: user.Phone,
|
||||||
Avatar: getAvatarOrDefault(user),
|
Avatar: getAvatarOrDefault(user),
|
||||||
CoverURL: user.CoverURL,
|
CoverURL: user.CoverURL,
|
||||||
Bio: user.Bio,
|
Bio: user.Bio,
|
||||||
Website: user.Website,
|
Website: user.Website,
|
||||||
Location: user.Location,
|
Location: user.Location,
|
||||||
PostsCount: postsCount,
|
PostsCount: postsCount,
|
||||||
FollowersCount: user.FollowersCount,
|
FollowersCount: user.FollowersCount,
|
||||||
FollowingCount: user.FollowingCount,
|
FollowingCount: user.FollowingCount,
|
||||||
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user