-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge branch 'mathieu/feature/Finalise-Caregivers-Data-Model'
- Loading branch information
Showing
7 changed files
with
167 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
Modules/AccountKit/Sources/Extensions/ColorScheme+Codable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Leka - iOS Monorepo | ||
// Copyright APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import SwiftUI | ||
|
||
// MARK: - ColorScheme + Codable, RawRepresentabl | ||
|
||
extension ColorScheme: Codable { | ||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
let rawValue = try container.decode(String.self) | ||
switch rawValue { | ||
case "light": self = .light | ||
case "dark": self = .dark | ||
default: fatalError("Invalid ColorScheme") | ||
} | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
try container.encode(self.rawValue) | ||
} | ||
|
||
public var rawValue: String { | ||
switch self { | ||
case .light: return "light" | ||
case .dark: return "dark" | ||
@unknown default: return "light" | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Modules/AccountKit/Sources/Models/CaregiverModel/Caregiver+Init.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Leka - iOS Monorepo | ||
// Copyright APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import SwiftUI | ||
|
||
public extension Caregiver { | ||
init(rootOwnerUid: String = "", | ||
firstName: String = "", | ||
lastName: String = "", | ||
email: String = "", | ||
avatar: String = "", | ||
professions: [String] = [], | ||
colorScheme: ColorScheme = .light, | ||
colorTheme: ColorTheme = .darkBlue) | ||
{ | ||
self.rootOwnerUid = rootOwnerUid | ||
self.firstName = firstName | ||
self.lastName = lastName | ||
self.email = email | ||
self.avatar = avatar | ||
self.professions = professions | ||
self.colorScheme = colorScheme | ||
self.colorTheme = colorTheme | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
Modules/AccountKit/Sources/Models/CaregiverModel/Caregiver.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Leka - iOS Monorepo | ||
// Copyright APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import DesignKit | ||
import FirebaseFirestore | ||
import SwiftUI | ||
|
||
// MARK: - Caregiver | ||
|
||
public struct Caregiver: AccountDocument { | ||
// MARK: Lifecycle | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
self.rootOwnerUid = try container.decode(String.self, forKey: .rootOwnerUid) | ||
self.firstName = try container.decode(String.self, forKey: .firstName) | ||
self.lastName = try container.decode(String.self, forKey: .lastName) | ||
self.email = try container.decode(String.self, forKey: .email) | ||
self.avatar = try container.decode(String.self, forKey: .avatar) | ||
self.professions = try container.decode([String].self, forKey: .professions) | ||
self.colorScheme = try container.decode(ColorScheme.self, forKey: .colorScheme) | ||
self.colorTheme = try container.decode(ColorTheme.self, forKey: .colorTheme) | ||
} | ||
|
||
// MARK: Public | ||
|
||
@DocumentID public var id: String? | ||
@ServerTimestamp public var createdAt: Date? | ||
@ServerTimestamp public var lastEditedAt: Date? | ||
|
||
public var rootOwnerUid: String | ||
public var firstName: String | ||
public var lastName: String | ||
public var email: String | ||
public var avatar: String | ||
public var professions: [String] | ||
public var colorScheme: ColorScheme | ||
public var colorTheme: ColorTheme | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(self.id, forKey: .id) | ||
try container.encode(self.rootOwnerUid, forKey: .rootOwnerUid) | ||
try container.encode(self.createdAt, forKey: .createdAt) | ||
try container.encode(self.lastEditedAt, forKey: .lastEditedAt) | ||
try container.encode(self.firstName, forKey: .firstName) | ||
try container.encode(self.lastName, forKey: .lastName) | ||
try container.encode(self.email, forKey: .email) | ||
try container.encode(self.avatar, forKey: .avatar) | ||
try container.encode(self.professions, forKey: .professions) | ||
try container.encode(self.colorScheme, forKey: .colorScheme) | ||
try container.encode(self.colorTheme, forKey: .colorTheme) | ||
} | ||
|
||
// MARK: Internal | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case id | ||
case rootOwnerUid = "root_owner_uid" | ||
case createdAt = "created_at" | ||
case lastEditedAt = "last_edited_at" | ||
case firstName = "first_name" | ||
case lastName = "last_name" | ||
case email | ||
case avatar | ||
case professions | ||
case colorScheme = "color_scheme" | ||
case colorTheme = "color_theme" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Leka - iOS Monorepo | ||
// Copyright APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import DesignKit | ||
import SwiftUI | ||
|
||
public enum ColorTheme: String, Codable { | ||
case darkBlue | ||
case blue | ||
case purple | ||
case red | ||
case orange | ||
case yellow | ||
case green | ||
case gray | ||
|
||
// MARK: Public | ||
|
||
public var color: Color { | ||
switch self { | ||
case .darkBlue: DesignKitAsset.Colors.lekaDarkBlue.swiftUIColor | ||
case .blue: .blue | ||
case .purple: .purple | ||
case .red: .red | ||
case .orange: .orange | ||
case .yellow: .yellow | ||
case .green: .green | ||
case .gray: .gray | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters