diff --git a/Modules/AccountKit/Sources/Extensions/Library+Codable.swift b/Modules/AccountKit/Sources/Extensions/Library+Codable.swift index 40de1b0109..d7c54f7c49 100644 --- a/Modules/AccountKit/Sources/Extensions/Library+Codable.swift +++ b/Modules/AccountKit/Sources/Extensions/Library+Codable.swift @@ -2,33 +2,24 @@ // Copyright APF France handicap // SPDX-License-Identifier: Apache-2.0 -import FirebaseFirestore import SwiftUI extension Library: Codable { public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - self.id = try container.decodeIfPresent(String.self, forKey: .id) - self.rootOwnerUid = try container.decode(String.self, forKey: .rootOwnerUid) self.savedActivities = try container.decodeIfPresent([SavedActivity].self, forKey: .savedActivities) ?? [] self.savedCurriculums = try container.decodeIfPresent([SavedCurriculum].self, forKey: .savedCurriculums) ?? [] self.savedStories = try container.decodeIfPresent([SavedStory].self, forKey: .savedStories) ?? [] self.savedGamepads = try container.decodeIfPresent([SavedGamepad].self, forKey: .savedGamepads) ?? [] - self.createdAt = try container.decodeIfPresent(Timestamp.self, forKey: .createdAt)?.dateValue() - self.lastEditedAt = try container.decodeIfPresent(Timestamp.self, forKey: .lastEditedAt)?.dateValue() } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(self.id, forKey: .id) - try container.encode(self.rootOwnerUid, forKey: .rootOwnerUid) try container.encode(self.savedActivities, forKey: .savedActivities) try container.encode(self.savedCurriculums, forKey: .savedCurriculums) try container.encode(self.savedStories, forKey: .savedStories) try container.encode(self.savedGamepads, forKey: .savedGamepads) - try container.encodeIfPresent(self.createdAt.map { Timestamp(date: $0) }, forKey: .createdAt) - try container.encodeIfPresent(self.lastEditedAt.map { Timestamp(date: $0) }, forKey: .lastEditedAt) } } diff --git a/Modules/AccountKit/Sources/Extensions/RootAccount+Codable.swift b/Modules/AccountKit/Sources/Extensions/RootAccount+Codable.swift index c877c6d222..53996529aa 100644 --- a/Modules/AccountKit/Sources/Extensions/RootAccount+Codable.swift +++ b/Modules/AccountKit/Sources/Extensions/RootAccount+Codable.swift @@ -9,7 +9,7 @@ public extension RootAccount { let container = try decoder.container(keyedBy: CodingKeys.self) self.id = try container.decodeIfPresent(String.self, forKey: .id) self.rootOwnerUid = try container.decode(String.self, forKey: .rootOwnerUid) - self.library = try container.decodeIfPresent(Library.self, forKey: .library) ?? Library() + self.library = try container.decode(Library.self, forKey: .library) self.createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt) self.lastEditedAt = try container.decodeIfPresent(Date.self, forKey: .lastEditedAt) } diff --git a/Modules/AccountKit/Sources/Extensions/SavedActivity+Codable.swift b/Modules/AccountKit/Sources/Extensions/SavedActivity+Codable.swift index 36a894d61e..9e5ea2a895 100644 --- a/Modules/AccountKit/Sources/Extensions/SavedActivity+Codable.swift +++ b/Modules/AccountKit/Sources/Extensions/SavedActivity+Codable.swift @@ -10,19 +10,15 @@ extension SavedActivity: Codable { let container = try decoder.container(keyedBy: CodingKeys.self) self.id = try container.decodeIfPresent(String.self, forKey: .id) - self.rootOwnerUid = try container.decode(String.self, forKey: .rootOwnerUid) self.caregiverID = try container.decodeIfPresent(String.self, forKey: .caregiverID) ?? "" - self.createdAt = try container.decodeIfPresent(Timestamp.self, forKey: .createdAt)?.dateValue() - self.lastEditedAt = try container.decodeIfPresent(Timestamp.self, forKey: .lastEditedAt)?.dateValue() + self.createdAt = try container.decode(Date.self, forKey: .createdAt) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(self.id, forKey: .id) - try container.encode(self.rootOwnerUid, forKey: .rootOwnerUid) try container.encode(self.caregiverID, forKey: .caregiverID) - try container.encodeIfPresent(self.createdAt.map { Timestamp(date: $0) }, forKey: .createdAt) - try container.encodeIfPresent(self.lastEditedAt.map { Timestamp(date: $0) }, forKey: .lastEditedAt) + try container.encode(self.createdAt, forKey: .createdAt) } } diff --git a/Modules/AccountKit/Sources/Extensions/SavedCurriculum+Codable.swift b/Modules/AccountKit/Sources/Extensions/SavedCurriculum+Codable.swift index c11ea2fe3b..caba54ef81 100644 --- a/Modules/AccountKit/Sources/Extensions/SavedCurriculum+Codable.swift +++ b/Modules/AccountKit/Sources/Extensions/SavedCurriculum+Codable.swift @@ -10,19 +10,15 @@ extension SavedCurriculum: Codable { let container = try decoder.container(keyedBy: CodingKeys.self) self.id = try container.decodeIfPresent(String.self, forKey: .id) - self.rootOwnerUid = try container.decode(String.self, forKey: .rootOwnerUid) self.caregiverID = try container.decodeIfPresent(String.self, forKey: .caregiverID) ?? "" - self.createdAt = try container.decodeIfPresent(Timestamp.self, forKey: .createdAt)?.dateValue() - self.lastEditedAt = try container.decodeIfPresent(Timestamp.self, forKey: .lastEditedAt)?.dateValue() + self.createdAt = try container.decode(Date.self, forKey: .createdAt) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(self.id, forKey: .id) - try container.encode(self.rootOwnerUid, forKey: .rootOwnerUid) try container.encode(self.caregiverID, forKey: .caregiverID) - try container.encodeIfPresent(self.createdAt.map { Timestamp(date: $0) }, forKey: .createdAt) - try container.encodeIfPresent(self.lastEditedAt.map { Timestamp(date: $0) }, forKey: .lastEditedAt) + try container.encodeIfPresent(self.createdAt, forKey: .createdAt) } } diff --git a/Modules/AccountKit/Sources/Extensions/SavedGamepad+Codable.swift b/Modules/AccountKit/Sources/Extensions/SavedGamepad+Codable.swift index aed5b8db7e..b979b4ac02 100644 --- a/Modules/AccountKit/Sources/Extensions/SavedGamepad+Codable.swift +++ b/Modules/AccountKit/Sources/Extensions/SavedGamepad+Codable.swift @@ -10,19 +10,15 @@ extension SavedGamepad: Codable { let container = try decoder.container(keyedBy: CodingKeys.self) self.id = try container.decodeIfPresent(String.self, forKey: .id) - self.rootOwnerUid = try container.decode(String.self, forKey: .rootOwnerUid) self.caregiverID = try container.decodeIfPresent(String.self, forKey: .caregiverID) ?? "" - self.createdAt = try container.decodeIfPresent(Timestamp.self, forKey: .createdAt)?.dateValue() - self.lastEditedAt = try container.decodeIfPresent(Timestamp.self, forKey: .lastEditedAt)?.dateValue() + self.createdAt = try container.decode(Date.self, forKey: .createdAt) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(self.id, forKey: .id) - try container.encode(self.rootOwnerUid, forKey: .rootOwnerUid) try container.encode(self.caregiverID, forKey: .caregiverID) - try container.encodeIfPresent(self.createdAt.map { Timestamp(date: $0) }, forKey: .createdAt) - try container.encodeIfPresent(self.lastEditedAt.map { Timestamp(date: $0) }, forKey: .lastEditedAt) + try container.encode(self.createdAt, forKey: .createdAt) } } diff --git a/Modules/AccountKit/Sources/Extensions/SavedStory+Codable.swift b/Modules/AccountKit/Sources/Extensions/SavedStory+Codable.swift index 5f93e43545..4ad7ca6d5d 100644 --- a/Modules/AccountKit/Sources/Extensions/SavedStory+Codable.swift +++ b/Modules/AccountKit/Sources/Extensions/SavedStory+Codable.swift @@ -10,19 +10,15 @@ extension SavedStory: Codable { let container = try decoder.container(keyedBy: CodingKeys.self) self.id = try container.decodeIfPresent(String.self, forKey: .id) - self.rootOwnerUid = try container.decode(String.self, forKey: .rootOwnerUid) self.caregiverID = try container.decodeIfPresent(String.self, forKey: .caregiverID) ?? "" - self.createdAt = try container.decodeIfPresent(Timestamp.self, forKey: .createdAt)?.dateValue() - self.lastEditedAt = try container.decodeIfPresent(Timestamp.self, forKey: .lastEditedAt)?.dateValue() + self.createdAt = try container.decode(Date.self, forKey: .createdAt) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(self.id, forKey: .id) - try container.encode(self.rootOwnerUid, forKey: .rootOwnerUid) try container.encode(self.caregiverID, forKey: .caregiverID) - try container.encodeIfPresent(self.createdAt.map { Timestamp(date: $0) }, forKey: .createdAt) - try container.encodeIfPresent(self.lastEditedAt.map { Timestamp(date: $0) }, forKey: .lastEditedAt) + try container.encode(self.createdAt, forKey: .createdAt) } } diff --git a/Modules/AccountKit/Sources/Managers/RootAccounts/RootAccountManager.swift b/Modules/AccountKit/Sources/Managers/RootAccounts/RootAccountManager.swift index 4d1a460e0e..0da6835143 100644 --- a/Modules/AccountKit/Sources/Managers/RootAccounts/RootAccountManager.swift +++ b/Modules/AccountKit/Sources/Managers/RootAccounts/RootAccountManager.swift @@ -65,7 +65,7 @@ public class RootAccountManager { return } - let savedActivity = SavedActivity(id: activityID, rootOwnerUid: rootAccount.rootOwnerUid, caregiverID: caregiverID) + let savedActivity = SavedActivity(id: activityID, caregiverID: caregiverID) guard !rootAccount.library.savedActivities.contains(where: { $0.id == activityID }) else { log.info("\(activityID) is already saved.") @@ -99,7 +99,7 @@ public class RootAccountManager { return } - let savedCurriculum = SavedCurriculum(id: curriculumID, rootOwnerUid: rootAccount.rootOwnerUid, caregiverID: caregiverID) + let savedCurriculum = SavedCurriculum(id: curriculumID, caregiverID: caregiverID) guard !rootAccount.library.savedCurriculums.contains(where: { $0.id == curriculumID }) else { log.info("\(curriculumID) is already saved.") @@ -133,7 +133,7 @@ public class RootAccountManager { return } - let savedStory = SavedStory(id: storyID, rootOwnerUid: rootAccount.rootOwnerUid, caregiverID: caregiverID) + let savedStory = SavedStory(id: storyID, caregiverID: caregiverID) guard !rootAccount.library.savedStories.contains(where: { $0.id == storyID }) else { log.info("\(storyID) is already saved.") @@ -167,7 +167,7 @@ public class RootAccountManager { return } - let savedGamepad = SavedGamepad(id: gamepadID, rootOwnerUid: rootAccount.rootOwnerUid, caregiverID: caregiverID) + let savedGamepad = SavedGamepad(id: gamepadID, caregiverID: caregiverID) guard !rootAccount.library.savedGamepads.contains(where: { $0.id == gamepadID }) else { log.info("\(gamepadID) is already saved.") diff --git a/Modules/AccountKit/Sources/Models/RootAccount/Library/Library+Init.swift b/Modules/AccountKit/Sources/Models/RootAccount/Library/Library+Init.swift deleted file mode 100644 index e48840d0d9..0000000000 --- a/Modules/AccountKit/Sources/Models/RootAccount/Library/Library+Init.swift +++ /dev/null @@ -1,25 +0,0 @@ -// Leka - iOS Monorepo -// Copyright APF France handicap -// SPDX-License-Identifier: Apache-2.0 - -import SwiftUI - -public extension Library { - init( - id: String? = nil, - rootOwnerUid: String = "", - savedActivities: [SavedActivity] = [], - savedCurriculums: [SavedCurriculum] = [], - savedStories: [SavedStory] = [], - savedGamepads: [SavedGamepad] = [] - ) { - self.id = id - self.rootOwnerUid = rootOwnerUid - self.savedActivities = savedActivities - self.savedCurriculums = savedCurriculums - self.savedStories = savedStories - self.savedGamepads = savedGamepads - self.createdAt = nil - self.lastEditedAt = nil - } -} diff --git a/Modules/AccountKit/Sources/Models/RootAccount/Library/Library.swift b/Modules/AccountKit/Sources/Models/RootAccount/Library/Library.swift index 8d42ae7e65..243726132a 100644 --- a/Modules/AccountKit/Sources/Models/RootAccount/Library/Library.swift +++ b/Modules/AccountKit/Sources/Models/RootAccount/Library/Library.swift @@ -7,14 +7,23 @@ import SwiftUI // MARK: - SavedActivity -public struct Library: DatabaseDocument, Hashable { - // MARK: Public +public struct Library: Hashable { + // MARK: Lifecycle + + public init( + savedActivities: [SavedActivity] = [], + savedCurriculums: [SavedCurriculum] = [], + savedStories: [SavedStory] = [], + savedGamepads: [SavedGamepad] = [] + ) { + self.savedActivities = savedActivities + self.savedCurriculums = savedCurriculums + self.savedStories = savedStories + self.savedGamepads = savedGamepads + } - @ServerTimestamp public var createdAt: Date? - @ServerTimestamp public var lastEditedAt: Date? + // MARK: Public - public var id: String? - public var rootOwnerUid: String public var savedActivities: [SavedActivity] public var savedCurriculums: [SavedCurriculum] public var savedStories: [SavedStory] @@ -23,13 +32,9 @@ public struct Library: DatabaseDocument, Hashable { // MARK: Internal enum CodingKeys: String, CodingKey { - case id = "uuid" - case rootOwnerUid = "root_owner_uid" case savedActivities = "saved_activities" case savedCurriculums = "saved_curriculums" case savedStories = "saved_stories" case savedGamepads = "saved_gamepads" - case createdAt = "created_at" - case lastEditedAt = "last_edited_at" } } diff --git a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedActivity/SavedActivity+Init.swift b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedActivity/SavedActivity+Init.swift index 214cc614aa..a74d3d0a65 100644 --- a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedActivity/SavedActivity+Init.swift +++ b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedActivity/SavedActivity+Init.swift @@ -7,13 +7,10 @@ import SwiftUI public extension SavedActivity { init( id: String? = nil, - rootOwnerUid: String = "", caregiverID: String ) { self.id = id - self.rootOwnerUid = rootOwnerUid self.caregiverID = caregiverID - self.createdAt = nil - self.lastEditedAt = nil + self.createdAt = Date() } } diff --git a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedActivity/SavedActivity.swift b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedActivity/SavedActivity.swift index daa1368a3f..a4a48e4234 100644 --- a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedActivity/SavedActivity.swift +++ b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedActivity/SavedActivity.swift @@ -7,23 +7,18 @@ import SwiftUI // MARK: - SavedActivity -public struct SavedActivity: DatabaseDocument, Hashable { +public struct SavedActivity: Hashable { // MARK: Public - @ServerTimestamp public var createdAt: Date? - @ServerTimestamp public var lastEditedAt: Date? - public var id: String? - public var rootOwnerUid: String public var caregiverID: String + public var createdAt: Date // MARK: Internal enum CodingKeys: String, CodingKey { case id = "uuid" - case rootOwnerUid = "root_owner_uid" case caregiverID = "caregiver_id" case createdAt = "created_at" - case lastEditedAt = "last_edited_at" } } diff --git a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedCurriculum/SavedCurriculum+Init.swift b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedCurriculum/SavedCurriculum+Init.swift index 98fb58c8e3..8440660773 100644 --- a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedCurriculum/SavedCurriculum+Init.swift +++ b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedCurriculum/SavedCurriculum+Init.swift @@ -7,13 +7,10 @@ import SwiftUI public extension SavedCurriculum { init( id: String? = nil, - rootOwnerUid: String = "", caregiverID: String ) { self.id = id - self.rootOwnerUid = rootOwnerUid self.caregiverID = caregiverID - self.createdAt = nil - self.lastEditedAt = nil + self.createdAt = Date() } } diff --git a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedCurriculum/SavedCurriculum.swift b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedCurriculum/SavedCurriculum.swift index 70a5bc2838..4fc2a7f7fa 100644 --- a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedCurriculum/SavedCurriculum.swift +++ b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedCurriculum/SavedCurriculum.swift @@ -7,23 +7,18 @@ import SwiftUI // MARK: - SavedCurriculum -public struct SavedCurriculum: DatabaseDocument, Hashable { +public struct SavedCurriculum: Hashable { // MARK: Public - @ServerTimestamp public var createdAt: Date? - @ServerTimestamp public var lastEditedAt: Date? - public var id: String? - public var rootOwnerUid: String public var caregiverID: String + public var createdAt: Date // MARK: Internal enum CodingKeys: String, CodingKey { case id = "uuid" - case rootOwnerUid = "root_owner_uid" case caregiverID = "caregiver_id" case createdAt = "created_at" - case lastEditedAt = "last_edited_at" } } diff --git a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedGamepad/SavedGamepad+Init.swift b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedGamepad/SavedGamepad+Init.swift index 6283d4620a..2a2bb575ba 100644 --- a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedGamepad/SavedGamepad+Init.swift +++ b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedGamepad/SavedGamepad+Init.swift @@ -7,13 +7,10 @@ import SwiftUI public extension SavedGamepad { init( id: String? = nil, - rootOwnerUid: String = "", caregiverID: String ) { self.id = id - self.rootOwnerUid = rootOwnerUid self.caregiverID = caregiverID - self.createdAt = nil - self.lastEditedAt = nil + self.createdAt = Date() } } diff --git a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedGamepad/SavedGamepad.swift b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedGamepad/SavedGamepad.swift index 124371f398..bc5b0cab7e 100644 --- a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedGamepad/SavedGamepad.swift +++ b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedGamepad/SavedGamepad.swift @@ -7,23 +7,18 @@ import SwiftUI // MARK: - SavedGamepad -public struct SavedGamepad: DatabaseDocument, Hashable { +public struct SavedGamepad: Hashable { // MARK: Public - @ServerTimestamp public var createdAt: Date? - @ServerTimestamp public var lastEditedAt: Date? - public var id: String? - public var rootOwnerUid: String public var caregiverID: String + public var createdAt: Date // MARK: Internal enum CodingKeys: String, CodingKey { case id = "uuid" - case rootOwnerUid = "root_owner_uid" case caregiverID = "caregiver_id" case createdAt = "created_at" - case lastEditedAt = "last_edited_at" } } diff --git a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedStory/SavedStory+Init.swift b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedStory/SavedStory+Init.swift index c81705b00a..76c9fbfc6a 100644 --- a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedStory/SavedStory+Init.swift +++ b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedStory/SavedStory+Init.swift @@ -7,13 +7,10 @@ import SwiftUI public extension SavedStory { init( id: String? = nil, - rootOwnerUid: String = "", caregiverID: String ) { self.id = id - self.rootOwnerUid = rootOwnerUid self.caregiverID = caregiverID - self.createdAt = nil - self.lastEditedAt = nil + self.createdAt = Date() } } diff --git a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedStory/SavedStory.swift b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedStory/SavedStory.swift index 6e5d7aa539..d0e2661c32 100644 --- a/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedStory/SavedStory.swift +++ b/Modules/AccountKit/Sources/Models/RootAccount/Library/SavedStory/SavedStory.swift @@ -7,23 +7,18 @@ import SwiftUI // MARK: - SavedStory -public struct SavedStory: DatabaseDocument, Hashable { +public struct SavedStory: Hashable { // MARK: Public - @ServerTimestamp public var createdAt: Date? - @ServerTimestamp public var lastEditedAt: Date? - public var id: String? - public var rootOwnerUid: String public var caregiverID: String + public var createdAt: Date // MARK: Internal enum CodingKeys: String, CodingKey { case id = "uuid" - case rootOwnerUid = "root_owner_uid" case caregiverID = "caregiver_id" case createdAt = "created_at" - case lastEditedAt = "last_edited_at" } } diff --git a/Modules/AccountKit/Sources/Models/RootAccount/RootAccount+Init.swift b/Modules/AccountKit/Sources/Models/RootAccount/RootAccount+Init.swift index 87e8afa00f..ce63e93630 100644 --- a/Modules/AccountKit/Sources/Models/RootAccount/RootAccount+Init.swift +++ b/Modules/AccountKit/Sources/Models/RootAccount/RootAccount+Init.swift @@ -7,11 +7,10 @@ import SwiftUI public extension RootAccount { init( id: String = "", - rootOwnerUid: String = "", - library: Library = Library() + rootOwnerUid: String = "" ) { self.id = id self.rootOwnerUid = rootOwnerUid - self.library = library + self.library = Library() } }