diff --git a/Modules/AccountKit/Sources/Extensions/ConsentInfo+Codable.swift b/Modules/AccountKit/Sources/Extensions/ConsentInfo+Codable.swift new file mode 100644 index 0000000000..10a0c34e22 --- /dev/null +++ b/Modules/AccountKit/Sources/Extensions/ConsentInfo+Codable.swift @@ -0,0 +1,21 @@ +// Leka - iOS Monorepo +// Copyright APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +import SwiftUI + +extension ConsentInfo: Codable { + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.policyVersion = try container.decode(String.self, forKey: .policyVersion) + self.acceptedAt = try container.decode(Date.self, forKey: .acceptedAt) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(self.policyVersion, forKey: .policyVersion) + try container.encode(self.acceptedAt, forKey: .acceptedAt) + } +} diff --git a/Modules/AccountKit/Sources/Extensions/RootAccount+Codable.swift b/Modules/AccountKit/Sources/Extensions/RootAccount+Codable.swift index c877c6d222..5078c6a806 100644 --- a/Modules/AccountKit/Sources/Extensions/RootAccount+Codable.swift +++ b/Modules/AccountKit/Sources/Extensions/RootAccount+Codable.swift @@ -7,9 +7,11 @@ import SwiftUI public extension RootAccount { 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.library = try container.decodeIfPresent(Library.self, forKey: .library) ?? Library() + self.consentInfo = try container.decode([ConsentInfo].self, forKey: .consentInfo) self.createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt) self.lastEditedAt = try container.decodeIfPresent(Date.self, forKey: .lastEditedAt) } diff --git a/Modules/AccountKit/Sources/Models/RootAccount/ConsentInfo/ConsentInfo+Init.swift b/Modules/AccountKit/Sources/Models/RootAccount/ConsentInfo/ConsentInfo+Init.swift new file mode 100644 index 0000000000..53d88b68b3 --- /dev/null +++ b/Modules/AccountKit/Sources/Models/RootAccount/ConsentInfo/ConsentInfo+Init.swift @@ -0,0 +1,14 @@ +// Leka - iOS Monorepo +// Copyright APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +import SwiftUI + +public extension ConsentInfo { + init( + policyVersion: String + ) { + self.policyVersion = policyVersion + self.acceptedAt = Date() + } +} diff --git a/Modules/AccountKit/Sources/Models/RootAccount/ConsentInfo/ConsentInfo.swift b/Modules/AccountKit/Sources/Models/RootAccount/ConsentInfo/ConsentInfo.swift new file mode 100644 index 0000000000..54f575138a --- /dev/null +++ b/Modules/AccountKit/Sources/Models/RootAccount/ConsentInfo/ConsentInfo.swift @@ -0,0 +1,19 @@ +// Leka - iOS Monorepo +// Copyright APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +import SwiftUI + +public struct ConsentInfo: Codable { + // MARK: Public + + public var policyVersion: String + public var acceptedAt: Date + + // MARK: Internal + + enum CodingKeys: String, CodingKey { + case policyVersion = "policy_version" + case acceptedAt = "accepted_at" + } +} diff --git a/Modules/AccountKit/Sources/Models/RootAccount/RootAccount+Init.swift b/Modules/AccountKit/Sources/Models/RootAccount/RootAccount+Init.swift index 87e8afa00f..fcc514214a 100644 --- a/Modules/AccountKit/Sources/Models/RootAccount/RootAccount+Init.swift +++ b/Modules/AccountKit/Sources/Models/RootAccount/RootAccount+Init.swift @@ -8,10 +8,12 @@ public extension RootAccount { init( id: String = "", rootOwnerUid: String = "", - library: Library = Library() + library: Library = Library(), + consentInfo: [ConsentInfo] = [] ) { self.id = id self.rootOwnerUid = rootOwnerUid self.library = library + self.consentInfo = consentInfo } } diff --git a/Modules/AccountKit/Sources/Models/RootAccount/RootAccount.swift b/Modules/AccountKit/Sources/Models/RootAccount/RootAccount.swift index 0b78d4488d..5f2a937bf9 100644 --- a/Modules/AccountKit/Sources/Models/RootAccount/RootAccount.swift +++ b/Modules/AccountKit/Sources/Models/RootAccount/RootAccount.swift @@ -13,6 +13,7 @@ public struct RootAccount: AccountDocument { @ServerTimestamp public var lastEditedAt: Date? public var rootOwnerUid: String public var library: Library + public var consentInfo: [ConsentInfo] // MARK: Internal @@ -20,6 +21,7 @@ public struct RootAccount: AccountDocument { case id = "uuid" case rootOwnerUid = "root_owner_uid" case library + case consentInfo = "consent_info" case createdAt = "created_at" case lastEditedAt = "last_edited_at" }