Skip to content

Commit

Permalink
Make DataServices open
Browse files Browse the repository at this point in the history
  • Loading branch information
matolah committed Aug 28, 2023
1 parent 94da9ca commit 3885be5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions CoreData/Sources/CoreDataService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public protocol CoreDataDataServiceProtocol<DataType>: DataServiceProtocol where
func createEmpty() -> DataType?
}

public final class CoreDataDataService<T: CoreDataEntity>: DataService<T>, CoreDataDataServiceProtocol {
open class CoreDataDataService<T: CoreDataEntity>: DataService<T>, CoreDataDataServiceProtocol {
typealias DataType = T

private let managedObjectContext: NSManagedObjectContext
Expand All @@ -17,7 +17,7 @@ public final class CoreDataDataService<T: CoreDataEntity>: DataService<T>, CoreD
self.managedObjectContext = managedObjectContext
}

public override func fetchAll() async -> Result<[T], Error> {
open override func fetchAll() async -> Result<[T], Error> {
do {
latestValues = try fetchValues(withPredicate: nil)

Expand All @@ -34,7 +34,7 @@ public final class CoreDataDataService<T: CoreDataEntity>: DataService<T>, CoreD
return try managedObjectContext.fetch(request) as? [T] ?? []
}

public override func fetch(by id: String) async -> Result<T?, Error> {
open override func fetch(by id: String) async -> Result<T?, Error> {
do {
let predicate = NSPredicate(
format: "id = %@", id
Expand All @@ -54,7 +54,7 @@ public final class CoreDataDataService<T: CoreDataEntity>: DataService<T>, CoreD
}
}

public override func create(value: T) async -> Result<T, Error> {
open override func create(value: T) async -> Result<T, Error> {
do {
managedObjectContext.insert(value)

Expand All @@ -66,7 +66,7 @@ public final class CoreDataDataService<T: CoreDataEntity>: DataService<T>, CoreD
}
}

public override func update(value: T) async -> Result<T, Error> {
open override func update(value: T) async -> Result<T, Error> {
do {
try managedObjectContext.save()

Expand All @@ -76,7 +76,7 @@ public final class CoreDataDataService<T: CoreDataEntity>: DataService<T>, CoreD
}
}

public func createEmpty() -> T? {
open func createEmpty() -> T? {
return NSEntityDescription.insertNewObject(
forEntityName: T.entityName,
into: managedObjectContext
Expand Down
10 changes: 5 additions & 5 deletions RemoteCollection/Sources/RemoteCollectionDataService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Foundation
import LeezyData

public final class RemoteCollectionDataService<T: RemoteEntity>: DataService<T> {
open class RemoteCollectionDataService<T: RemoteEntity>: DataService<T> {
typealias DataType = T

private let database: RemoteCollectionDatabase
Expand All @@ -12,7 +12,7 @@ public final class RemoteCollectionDataService<T: RemoteEntity>: DataService<T>
self.database = database
}

public override func fetchAll() async -> Result<[T], Error> {
open override func fetchAll() async -> Result<[T], Error> {
do {
latestValues = try await collection().documents().map {
return try $0.decoded(as: T.self)
Expand All @@ -24,7 +24,7 @@ public final class RemoteCollectionDataService<T: RemoteEntity>: DataService<T>
}
}

public override func fetch(by id: String) async -> Result<T?, Error> {
open override func fetch(by id: String) async -> Result<T?, Error> {
do {
guard let value = try await collection().document(by: id)?.decoded(as: T.self) else {
return .success(nil)
Expand All @@ -43,7 +43,7 @@ public final class RemoteCollectionDataService<T: RemoteEntity>: DataService<T>
.collection(named: T.collectionName)
}

public override func create(value: T) async -> Result<T, Error> {
open override func create(value: T) async -> Result<T, Error> {
do {
let value = try await collection().addDocument(value)

Expand All @@ -53,7 +53,7 @@ public final class RemoteCollectionDataService<T: RemoteEntity>: DataService<T>
}
}

public override func update(value: T) async -> Result<T, Error> {
open override func update(value: T) async -> Result<T, Error> {
do {
try await collection().updateDocument(value, id: value.id)

Expand Down

0 comments on commit 3885be5

Please sign in to comment.