Skip to content

Commit 15a875c

Browse files
committed
Added adresses and capabilites
1 parent cbc5b2e commit 15a875c

File tree

5 files changed

+164
-19
lines changed

5 files changed

+164
-19
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Address.swift
3+
//
4+
//
5+
// Created by Sascha Müllner on 11.03.20.
6+
//
7+
8+
import Foundation
9+
import CoreLocation
10+
11+
public struct Address : Codable {
12+
13+
public var label: String?
14+
public var street: String?
15+
public var city: String?
16+
public var postcode: String?
17+
public var country: String?
18+
public var latitude: CLLocationDegrees?
19+
public var longitude: CLLocationDegrees?
20+
21+
22+
public init(from decoder: Decoder) throws {
23+
let values = try decoder.container(keyedBy: CodingKeys.self)
24+
self.label = try values.decodeIfPresent(String.self, forKey: .label)
25+
self.street = try values.decodeIfPresent(String.self, forKey: .street)
26+
self.city = try values.decodeIfPresent(String.self, forKey: .city)
27+
self.postcode = try values.decodeIfPresent(String.self, forKey: .postcode)
28+
self.country = try values.decodeIfPresent(String.self, forKey: .country)
29+
self.latitude = try values.decodeIfPresent(CLLocationDegrees.self, forKey: .latitude)
30+
self.longitude = try values.decodeIfPresent(CLLocationDegrees.self, forKey: .longitude)
31+
}
32+
33+
public func encode(to encoder: Encoder) throws {
34+
var container = encoder.container(keyedBy: CodingKeys.self)
35+
try container.encodeIfPresent(self.label, forKey: .label)
36+
try container.encodeIfPresent(self.street, forKey: .street)
37+
try container.encodeIfPresent(self.city, forKey: .city)
38+
try container.encodeIfPresent(self.postcode, forKey: .postcode)
39+
try container.encodeIfPresent(self.country, forKey: .country)
40+
try container.encodeIfPresent(self.latitude, forKey: .latitude)
41+
try container.encodeIfPresent(self.longitude, forKey: .longitude)
42+
}
43+
44+
private enum CodingKeys: String, CodingKey {
45+
case label, street, city, postcode, country, latitude, longitude
46+
}
47+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Capabilities.swift
3+
//
4+
//
5+
// Created by Sascha Müllner on 11.03.20.
6+
//
7+
8+
import Foundation
9+
10+
public struct Capabilities : Codable {
11+
12+
public var nativeLanguage: String?
13+
public var languages: [String]?
14+
15+
public init(from decoder: Decoder) throws {
16+
let values = try decoder.container(keyedBy: CodingKeys.self)
17+
self.nativeLanguage = try values.decodeIfPresent(String.self, forKey: .nativeLanguage)
18+
self.languages = try values.decodeIfPresent([String].self, forKey: .languages)
19+
}
20+
21+
public func encode(to encoder: Encoder) throws {
22+
var container = encoder.container(keyedBy: CodingKeys.self)
23+
try container.encodeIfPresent(self.nativeLanguage, forKey: .nativeLanguage)
24+
try container.encodeIfPresent(self.languages, forKey: .languages)
25+
}
26+
27+
private enum CodingKeys: String, CodingKey {
28+
case nativeLanguage, languages
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// EMail.swift
3+
//
4+
//
5+
// Created by Sascha Müllner on 11.03.20.
6+
//
7+
8+
import Foundation
9+
10+
public struct EMail : Codable {
11+
12+
public var label: String?
13+
public var email: String?
14+
15+
public init(from decoder: Decoder) throws {
16+
let values = try decoder.container(keyedBy: CodingKeys.self)
17+
self.label = try values.decodeIfPresent(String.self, forKey: .label)
18+
self.email = try values.decodeIfPresent(String.self, forKey: .email)
19+
}
20+
21+
public func encode(to encoder: Encoder) throws {
22+
var container = encoder.container(keyedBy: CodingKeys.self)
23+
try container.encodeIfPresent(self.label, forKey: .label)
24+
try container.encodeIfPresent(self.email, forKey: .email)
25+
}
26+
27+
private enum CodingKeys: String, CodingKey {
28+
case label, email
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Phone.swift
3+
//
4+
//
5+
// Created by Sascha Müllner on 11.03.20.
6+
//
7+
8+
import Foundation
9+
10+
public struct Phone : Codable {
11+
12+
public var label: String?
13+
public var phone: String?
14+
15+
public init(from decoder: Decoder) throws {
16+
let values = try decoder.container(keyedBy: CodingKeys.self)
17+
self.label = try values.decodeIfPresent(String.self, forKey: .label)
18+
self.phone = try values.decodeIfPresent(String.self, forKey: .phone)
19+
}
20+
21+
public func encode(to encoder: Encoder) throws {
22+
var container = encoder.container(keyedBy: CodingKeys.self)
23+
try container.encodeIfPresent(self.label, forKey: .label)
24+
try container.encodeIfPresent(self.phone, forKey: .phone)
25+
}
26+
27+
private enum CodingKeys: String, CodingKey {
28+
case label, phone
29+
}
30+
}

Sources/MultiUser/Model/User.swift

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
//
77

88
import Foundation
9+
import CoreImage
910

1011
public struct User : Codable {
11-
private var uuid:UUID
12+
private var uuid: UUID
1213

1314
public var username: String?
1415
public var firstname: String?
1516
public var lastname: String?
1617
public var birthday: Date?
17-
public var emails: [String]?
18+
public var emails: [EMail]?
19+
public var phones: [Phone]?
20+
public var addresses: [Address]?
21+
public var capabilities: Capabilities?
1822
public var attributes: [String: String]?
1923
public var icon: Data?
2024
public var data: [Data]?
@@ -26,27 +30,31 @@ public struct User : Codable {
2630
public init(from decoder: Decoder) throws {
2731
let values = try decoder.container(keyedBy: CodingKeys.self)
2832
self.uuid = try values.decode(UUID.self, forKey: .uuid)
29-
self.username = try values.decode(String.self, forKey: .username)
30-
self.firstname = try values.decode(String.self, forKey: .firstname)
31-
self.lastname = try values.decode(String.self, forKey: .lastname)
32-
self.birthday = try values.decode(Date.self, forKey: .birthday)
33-
self.emails = try values.decode([String].self, forKey: .emails)
34-
self.attributes = try values.decode([String: String].self, forKey: .attributes)
35-
self.icon = try values.decode(Data.self, forKey: .icon)
36-
self.data = try values.decode([Data].self, forKey: .data)
33+
self.username = try values.decodeIfPresent(String.self, forKey: .username)
34+
self.firstname = try values.decodeIfPresent(String.self, forKey: .firstname)
35+
self.lastname = try values.decodeIfPresent(String.self, forKey: .lastname)
36+
self.birthday = try values.decodeIfPresent(Date.self, forKey: .birthday)
37+
self.emails = try values.decodeIfPresent([EMail].self, forKey: .emails)
38+
self.phones = try values.decodeIfPresent([Phone].self, forKey: .phones)
39+
self.addresses = try values.decodeIfPresent([Address].self, forKey: .addresses)
40+
self.attributes = try values.decodeIfPresent([String: String].self, forKey: .attributes)
41+
self.icon = try values.decodeIfPresent(Data.self, forKey: .icon)
42+
self.data = try values.decodeIfPresent([Data].self, forKey: .data)
3743
}
3844

3945
public func encode(to encoder: Encoder) throws {
4046
var container = encoder.container(keyedBy: CodingKeys.self)
4147
try container.encode(self.uuid, forKey: .uuid)
42-
try container.encode(self.username, forKey: .username)
43-
try container.encode(self.firstname, forKey: .firstname)
44-
try container.encode(self.lastname, forKey: .lastname)
45-
try container.encode(self.birthday, forKey: .birthday)
46-
try container.encode(self.emails, forKey: .emails)
47-
try container.encode(self.attributes, forKey: .attributes)
48-
try container.encode(self.icon, forKey: .icon)
49-
try container.encode(self.data, forKey: .data)
48+
try container.encodeIfPresent(self.username, forKey: .username)
49+
try container.encodeIfPresent(self.firstname, forKey: .firstname)
50+
try container.encodeIfPresent(self.lastname, forKey: .lastname)
51+
try container.encodeIfPresent(self.birthday, forKey: .birthday)
52+
try container.encodeIfPresent(self.emails, forKey: .emails)
53+
try container.encodeIfPresent(self.phones, forKey: .phones)
54+
try container.encodeIfPresent(self.addresses, forKey: .addresses)
55+
try container.encodeIfPresent(self.attributes, forKey: .attributes)
56+
try container.encodeIfPresent(self.icon, forKey: .icon)
57+
try container.encodeIfPresent(self.data, forKey: .data)
5058
}
5159

5260
public var id: UUID {
@@ -56,6 +64,6 @@ public struct User : Codable {
5664
}
5765

5866
private enum CodingKeys: String, CodingKey {
59-
case uuid, username, firstname, lastname, birthday, emails, attributes, icon, data
67+
case uuid, username, firstname, lastname, birthday, emails, phones, addresses, attributes, icon, data
6068
}
6169
}

0 commit comments

Comments
 (0)