Add ProfileManager methods to return full profiles
This commit is contained in:
parent
9d9dc2b2f6
commit
7771b50b56
|
@ -39,6 +39,8 @@ public protocol ProfileManager {
|
||||||
|
|
||||||
var headers: [Profile.Header] { get }
|
var headers: [Profile.Header] { get }
|
||||||
|
|
||||||
|
var profiles: [Profile] { get }
|
||||||
|
|
||||||
func isExistingProfile(withId id: UUID) -> Bool
|
func isExistingProfile(withId id: UUID) -> Bool
|
||||||
|
|
||||||
func isExistingProfile(withName name: String) -> Bool
|
func isExistingProfile(withName name: String) -> Bool
|
||||||
|
|
|
@ -42,6 +42,10 @@ public class CoreDataProfileManagerStrategy: ProfileManagerStrategy {
|
||||||
fetchedHeaders.value
|
fetchedHeaders.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func profiles() -> [Profile] {
|
||||||
|
profileRepository.profiles()
|
||||||
|
}
|
||||||
|
|
||||||
public func profile(withId id: UUID) -> Profile? {
|
public func profile(withId id: UUID) -> Profile? {
|
||||||
profileRepository.profile(withId: id)
|
profileRepository.profile(withId: id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,10 @@ extension DefaultProfileManager {
|
||||||
Array(allHeaders.values)
|
Array(allHeaders.values)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var profiles: [Profile] {
|
||||||
|
strategy.profiles()
|
||||||
|
}
|
||||||
|
|
||||||
public func isExistingProfile(withId id: UUID) -> Bool {
|
public func isExistingProfile(withId id: UUID) -> Bool {
|
||||||
allHeaders[id] != nil
|
allHeaders[id] != nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ import PassepartoutCore
|
||||||
public protocol ProfileManagerStrategy {
|
public protocol ProfileManagerStrategy {
|
||||||
var allHeaders: [UUID: Profile.Header] { get }
|
var allHeaders: [UUID: Profile.Header] { get }
|
||||||
|
|
||||||
|
func profiles() -> [Profile]
|
||||||
|
|
||||||
func profile(withId: UUID) -> Profile?
|
func profile(withId: UUID) -> Profile?
|
||||||
|
|
||||||
func saveProfiles(_ profiles: [Profile])
|
func saveProfiles(_ profiles: [Profile])
|
||||||
|
|
|
@ -65,6 +65,21 @@ class ProfileRepository: Repository {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func profiles() -> [Profile] {
|
||||||
|
let request = CDProfile.fetchRequest()
|
||||||
|
request.sortDescriptors = [
|
||||||
|
.init(keyPath: \CDProfile.uuid, ascending: true),
|
||||||
|
.init(keyPath: \CDProfile.lastUpdate, ascending: false)
|
||||||
|
]
|
||||||
|
do {
|
||||||
|
let results = try context.fetch(request)
|
||||||
|
return try results.compactMap(ProfileMapper.toModel)
|
||||||
|
} catch {
|
||||||
|
pp_log.error("Unable to fetch profiles: \(error)")
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func profile(withId id: UUID) -> Profile? {
|
func profile(withId id: UUID) -> Profile? {
|
||||||
let request = CDProfile.fetchRequest()
|
let request = CDProfile.fetchRequest()
|
||||||
request.predicate = NSPredicate(
|
request.predicate = NSPredicate(
|
||||||
|
|
Loading…
Reference in New Issue