feat(admin): add admin endpoint to list user devices with JPush registration IDs
- Add AdminDeviceTokenResponse DTO including push_token (RegistrationID) for push debugging - Add DeviceTokenToAdminResponse and DeviceTokensToAdminResponse converters - Inject PushService into AdminUserHandler for retrieving user devices - Register GET /api/v1/admin/users/:id/devices route for querying target user's device tokens
This commit is contained in:
@@ -499,6 +499,22 @@ type DeviceTokenResponse struct {
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// AdminDeviceTokenResponse 管理端设备Token响应
|
||||
// 相比 DeviceTokenResponse,额外包含 user_id 与 push_token(即 JPush RegistrationID),
|
||||
// 供后台查询用户设备 registration_id 使用。
|
||||
type AdminDeviceTokenResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
DeviceID string `json:"device_id"`
|
||||
DeviceType string `json:"device_type"`
|
||||
PushToken string `json:"push_token,omitempty"` // JPush RegistrationID
|
||||
IsActive bool `json:"is_active"`
|
||||
DeviceName string `json:"device_name,omitempty"`
|
||||
LastUsedAt time.Time `json:"last_used_at,omitzero"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// ==================== 推送记录 DTOs ====================
|
||||
|
||||
// PushRecordResponse 推送记录响应
|
||||
|
||||
@@ -199,3 +199,34 @@ func DeviceTokensToResponse(tokens []*model.DeviceToken) []*DeviceTokenResponse
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// DeviceTokenToAdminResponse 将DeviceToken转换为管理端响应(含 registration_id)
|
||||
func DeviceTokenToAdminResponse(token *model.DeviceToken) *AdminDeviceTokenResponse {
|
||||
if token == nil {
|
||||
return nil
|
||||
}
|
||||
resp := &AdminDeviceTokenResponse{
|
||||
ID: token.ID,
|
||||
UserID: token.UserID,
|
||||
DeviceID: token.DeviceID,
|
||||
DeviceType: string(token.DeviceType),
|
||||
PushToken: token.PushToken,
|
||||
IsActive: token.IsActive,
|
||||
DeviceName: token.DeviceName,
|
||||
CreatedAt: token.CreatedAt,
|
||||
UpdatedAt: token.UpdatedAt,
|
||||
}
|
||||
if token.LastUsedAt != nil {
|
||||
resp.LastUsedAt = *token.LastUsedAt
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
// DeviceTokensToAdminResponse 将DeviceToken列表转换为管理端响应列表
|
||||
func DeviceTokensToAdminResponse(tokens []*model.DeviceToken) []*AdminDeviceTokenResponse {
|
||||
result := make([]*AdminDeviceTokenResponse, 0, len(tokens))
|
||||
for _, token := range tokens {
|
||||
result = append(result, DeviceTokenToAdminResponse(token))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user