package dto import ( "time" "tyapi-server/internal/domains/user/entities" ) // RegisterRequest 用户注册请求 type RegisterRequest struct { Phone string `json:"phone" binding:"required,len=11" example:"13800138000"` Password string `json:"password" binding:"required,min=6,max=128" example:"password123"` ConfirmPassword string `json:"confirm_password" binding:"required,eqfield=Password" example:"password123"` Code string `json:"code" binding:"required,len=6" example:"123456"` } // LoginWithPasswordRequest 密码登录请求 type LoginWithPasswordRequest struct { Phone string `json:"phone" binding:"required,len=11" example:"13800138000"` Password string `json:"password" binding:"required" example:"password123"` } // LoginWithSMSRequest 短信验证码登录请求 type LoginWithSMSRequest struct { Phone string `json:"phone" binding:"required,len=11" example:"13800138000"` Code string `json:"code" binding:"required,len=6" example:"123456"` } // ChangePasswordRequest 修改密码请求 type ChangePasswordRequest struct { OldPassword string `json:"old_password" binding:"required" example:"oldpassword123"` NewPassword string `json:"new_password" binding:"required,min=6,max=128" example:"newpassword123"` ConfirmNewPassword string `json:"confirm_new_password" binding:"required,eqfield=NewPassword" example:"newpassword123"` Code string `json:"code" binding:"required,len=6" example:"123456"` } // UpdateProfileRequest 更新用户信息请求 type UpdateProfileRequest struct { Phone string `json:"phone" binding:"omitempty,len=11" example:"13800138000"` // 可以在这里添加更多用户信息字段,如昵称、头像等 } // UserResponse 用户响应 type UserResponse struct { ID string `json:"id" example:"123e4567-e89b-12d3-a456-426614174000"` Phone string `json:"phone" example:"13800138000"` CreatedAt time.Time `json:"created_at" example:"2024-01-01T00:00:00Z"` UpdatedAt time.Time `json:"updated_at" example:"2024-01-01T00:00:00Z"` } // LoginResponse 登录响应 type LoginResponse struct { User *UserResponse `json:"user"` AccessToken string `json:"access_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."` TokenType string `json:"token_type" example:"Bearer"` ExpiresIn int64 `json:"expires_in" example:"86400"` LoginMethod string `json:"login_method" example:"password"` // password 或 sms } // 转换方法 func (r *RegisterRequest) ToEntity() *entities.User { return &entities.User{ Phone: r.Phone, Password: r.Password, } } func (r *LoginWithPasswordRequest) ToEntity() *entities.User { return &entities.User{ Phone: r.Phone, Password: r.Password, } } func (r *LoginWithSMSRequest) ToEntity() *entities.User { return &entities.User{ Phone: r.Phone, } } func FromEntity(user *entities.User) *UserResponse { if user == nil { return nil } return &UserResponse{ ID: user.ID, Phone: user.Phone, CreatedAt: user.CreatedAt, UpdatedAt: user.UpdatedAt, } }