Files
ios-client/IosClientKit/Sources/CoreRepository/FakeHomeRepository.swift
2026-09-14 21:10:44 +08:00

41 lines
1.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import CoreCommon
import CoreDomain
import CoreModel
/// Fake 仓库实现(骨架阶段返回假数据,后续替换为 OfflineFirst 实现)。
public struct FakeHomeRepository: HomeRepository {
public init() {}
public func observeHome() -> AsyncThrowingStream<HomeData, Error> {
AsyncThrowingStream { continuation in
let task = Task {
do {
// 模拟网络延迟。
try await Task.sleep(for: .milliseconds(400))
try Task.checkCancellation()
Logger.info("FakeHomeRepository 返回假数据")
continuation.yield(Self.fakeData)
continuation.finish()
} catch {
continuation.finish(throwing: error)
}
}
continuation.onTermination = { _ in
task.cancel()
}
}
}
private static let fakeData = HomeData(
id: "home-1",
greeting: "早上好,Andy",
summary: "今日已完成 2 / 4",
habits: [
Habit(id: "habit-1", title: "晨跑 5 公里", detail: "保持运动习惯", isCheckedInToday: true, streakDays: 12),
Habit(id: "habit-2", title: "阅读 30 分钟", detail: "每天进步一点", isCheckedInToday: true, streakDays: 8),
Habit(id: "habit-3", title: "喝水 8 杯", detail: "健康补水", isCheckedInToday: false, streakDays: 0),
Habit(id: "habit-4", title: "写日记", detail: "记录今日所思", isCheckedInToday: false, streakDays: 3),
]
)
}