From 5460b83a9615759213fa7c8511139749fc0741cc Mon Sep 17 00:00:00 2001 From: Minseok Kang Date: Thu, 22 Aug 2024 01:19:04 +0900 Subject: [PATCH] =?UTF-8?q?[CAT-295]=20Database=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EC=A1=B4=EC=9E=AC=20=EC=97=AC=EB=B6=80=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20(#49)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interface/DatabaseClientInterface.swift | 2 ++ .../Core/DatabaseClient/Sources/DatabaseClient.swift | 11 +++++++++++ .../MyPageFeature/Sources/MyPage/MyPageCore.swift | 1 + 3 files changed, 14 insertions(+) diff --git a/Projects/Core/DatabaseClient/Interface/DatabaseClientInterface.swift b/Projects/Core/DatabaseClient/Interface/DatabaseClientInterface.swift index e8b0f09..a2dac35 100644 --- a/Projects/Core/DatabaseClient/Interface/DatabaseClientInterface.swift +++ b/Projects/Core/DatabaseClient/Interface/DatabaseClientInterface.swift @@ -31,6 +31,8 @@ public struct DatabaseClient { /// Use delete(_ type:). public var deleteAllTable: @Sendable () async throws -> Void + public var checkHasTable: @Sendable () async throws -> Bool + public func create(object: T) async throws { try await create(object) } diff --git a/Projects/Core/DatabaseClient/Sources/DatabaseClient.swift b/Projects/Core/DatabaseClient/Sources/DatabaseClient.swift index de1519f..a86c4b6 100644 --- a/Projects/Core/DatabaseClient/Sources/DatabaseClient.swift +++ b/Projects/Core/DatabaseClient/Sources/DatabaseClient.swift @@ -79,6 +79,13 @@ extension DatabaseClient: DependencyKey { } else { throw(NSError(domain: "Realm is not initialized", code: 0)) } + }, + checkHasTable: { + if let realmActor { + await realmActor.checkHasTable() + } else { + throw(NSError(domain: "Realm is not initialized", code: 0)) + } } ) } @@ -135,4 +142,8 @@ extension DatabaseClient.RealmActor { realm.deleteAll() } } + + public func checkHasTable() -> Bool{ + return !realm.isEmpty + } } diff --git a/Projects/Feature/MyPageFeature/Sources/MyPage/MyPageCore.swift b/Projects/Feature/MyPageFeature/Sources/MyPage/MyPageCore.swift index 6612087..c404964 100644 --- a/Projects/Feature/MyPageFeature/Sources/MyPage/MyPageCore.swift +++ b/Projects/Feature/MyPageFeature/Sources/MyPage/MyPageCore.swift @@ -42,6 +42,7 @@ public struct MyPageCore { @Dependency(APIClient.self) var apiClient @Dependency(UserService.self) var userService @Dependency(UserDefaultsClient.self) var userDefaultsClient + @Dependency(NetworkTracking.self) var networkTracking public init() {}