149 lines
3.2 KiB
Go
149 lines
3.2 KiB
Go
package usecase
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"cmroubao/backend-api/internal/domain"
|
|
)
|
|
|
|
type DeviceHeartbeatUpdate struct {
|
|
UserID string
|
|
DeviceID string
|
|
AppVersion string
|
|
AndroidVersion string
|
|
PDDVersion string
|
|
AccessibilityEnabled bool
|
|
PDDInstalled bool
|
|
ReportedAt time.Time
|
|
}
|
|
|
|
type DeviceHeartbeatRecord struct {
|
|
Device domain.Device
|
|
ActiveTaskID *string
|
|
}
|
|
|
|
type ClaimNextRepositoryRequest struct {
|
|
CreatorSubject string
|
|
UserID string
|
|
DeviceID string
|
|
IdempotencyKey string
|
|
RequestHash string
|
|
ClaimTokenHash string
|
|
Now time.Time
|
|
ExpiresAt time.Time
|
|
ReadinessAfter time.Time
|
|
Event domain.TaskEvent
|
|
}
|
|
|
|
type ClaimNextRepositoryResult struct {
|
|
Task *domain.PurchaseTask
|
|
Replayed bool
|
|
}
|
|
|
|
type StartTaskRepositoryRequest struct {
|
|
UserID string
|
|
DeviceID string
|
|
TaskID string
|
|
ClaimGeneration int64
|
|
ClaimTokenHash string
|
|
ExpectedVersion int64
|
|
IdempotencyKey string
|
|
RequestHash string
|
|
Now time.Time
|
|
ExpiresAt time.Time
|
|
Execution domain.TaskExecution
|
|
Event domain.TaskEvent
|
|
}
|
|
|
|
type StartTaskRepositoryResult struct {
|
|
Task domain.PurchaseTask
|
|
Execution domain.TaskExecution
|
|
Replayed bool
|
|
}
|
|
|
|
type TaskHeartbeatRepositoryRequest struct {
|
|
UserID string
|
|
DeviceID string
|
|
TaskID string
|
|
ExecutionID string
|
|
ClaimGeneration int64
|
|
ClaimTokenHash string
|
|
Step string
|
|
Now time.Time
|
|
MinimumExpiry time.Time
|
|
}
|
|
|
|
type TaskClaimRepositoryRequest struct {
|
|
UserID string
|
|
DeviceID string
|
|
TaskID string
|
|
ClaimGeneration int64
|
|
ClaimTokenHash string
|
|
Now time.Time
|
|
}
|
|
|
|
type TaskHeartbeatRepositoryResult struct {
|
|
Task domain.PurchaseTask
|
|
Execution domain.TaskExecution
|
|
CancelRequested bool
|
|
}
|
|
|
|
type ReleaseTaskRepositoryRequest struct {
|
|
UserID string
|
|
DeviceID string
|
|
TaskID string
|
|
ClaimGeneration int64
|
|
ClaimTokenHash string
|
|
ExpectedVersion int64
|
|
IdempotencyKey string
|
|
RequestHash string
|
|
Now time.Time
|
|
Event domain.TaskEvent
|
|
}
|
|
|
|
type CancelAcknowledgementRepositoryRequest struct {
|
|
UserID string
|
|
DeviceID string
|
|
TaskID string
|
|
ExecutionID string
|
|
ClaimGeneration int64
|
|
ClaimTokenHash string
|
|
ExpectedVersion int64
|
|
IdempotencyKey string
|
|
RequestHash string
|
|
Now time.Time
|
|
Event domain.TaskEvent
|
|
}
|
|
|
|
type LifecycleRepository interface {
|
|
RecordDeviceHeartbeat(
|
|
context.Context,
|
|
DeviceHeartbeatUpdate,
|
|
) (DeviceHeartbeatRecord, error)
|
|
ClaimNext(
|
|
context.Context,
|
|
ClaimNextRepositoryRequest,
|
|
) (ClaimNextRepositoryResult, error)
|
|
StartTask(
|
|
context.Context,
|
|
StartTaskRepositoryRequest,
|
|
) (StartTaskRepositoryResult, error)
|
|
HeartbeatTask(
|
|
context.Context,
|
|
TaskHeartbeatRepositoryRequest,
|
|
) (TaskHeartbeatRepositoryResult, error)
|
|
GetActiveClaimTask(
|
|
context.Context,
|
|
TaskClaimRepositoryRequest,
|
|
) (domain.PurchaseTask, error)
|
|
ReleaseTask(
|
|
context.Context,
|
|
ReleaseTaskRepositoryRequest,
|
|
) (domain.PurchaseTask, bool, error)
|
|
AcknowledgeTaskCancellation(
|
|
context.Context,
|
|
CancelAcknowledgementRepositoryRequest,
|
|
) (domain.PurchaseTask, bool, error)
|
|
}
|