Skip to content

Commit 6ccf202

Browse files
committed
Persist w3w (even though we don't use it yet)
1 parent bee8400 commit 6ccf202

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

Tree Tracker/Models/AirtableTree.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ struct AirtableTree: Decodable {
66
let species: String
77
let notes: String?
88
let coordinates: String?
9+
let what3words: String?
910
let imageMd5: String?
1011
let createDate: Date?
1112
let uploadDate: Date?
@@ -18,19 +19,21 @@ struct AirtableTree: Decodable {
1819
case species = "Species"
1920
case notes = "Notes"
2021
case coordinates = "Coordinates"
22+
case what3words = "What3Words"
2123
case image = "Image"
2224
case imageMd5 = "ImageSignature"
2325
case createDate = "CreatedDate"
2426
case uploadDate = "UploadedDate"
2527
case fields
2628
}
2729

28-
init(id: Int, supervisor: String, species: String, notes: String?, coordinates: String?, imageUrl: String?, thumbnailUrl: String?, imageMd5: String?, uploadDate: Date?, createDate: Date?) {
30+
init(id: Int, supervisor: String, species: String, notes: String?, coordinates: String?, what3words: String?, imageUrl: String?, thumbnailUrl: String?, imageMd5: String?, uploadDate: Date?, createDate: Date?) {
2931
self.id = id
3032
self.supervisor = supervisor
3133
self.species = species
3234
self.notes = notes
3335
self.coordinates = coordinates
36+
self.what3words = what3words
3437
self.imageUrl = imageUrl
3538
self.thumbnailUrl = thumbnailUrl
3639
self.imageMd5 = imageMd5
@@ -47,6 +50,7 @@ struct AirtableTree: Decodable {
4750
species = try container.decode(String.self, forKey: .species)
4851
notes = try container.decodeIfPresent(String.self, forKey: .notes)
4952
coordinates = try container.decodeIfPresent(String.self, forKey: .coordinates)
53+
what3words = try container.decodeIfPresent(String.self, forKey: .what3words)
5054
imageMd5 = try container.decodeIfPresent(String.self, forKey: .imageMd5)
5155
uploadDate = try container.decodeIfPresent(Date.self, forKey: .uploadDate)
5256
createDate = try container.decodeIfPresent(Date.self, forKey: .createDate)
@@ -63,7 +67,7 @@ struct AirtableTree: Decodable {
6367
}
6468

6569
func toRemoteTree() -> RemoteTree {
66-
return RemoteTree(id: id, supervisor: supervisor, species: species, notes: notes, coordinates: coordinates, imageUrl: imageUrl, thumbnailUrl: thumbnailUrl, imageMd5: imageMd5, createDate: createDate, uploadDate: uploadDate)
70+
return RemoteTree(id: id, supervisor: supervisor, species: species, notes: notes, coordinates: coordinates, what3words: what3words, imageUrl: imageUrl, thumbnailUrl: thumbnailUrl, imageMd5: imageMd5, createDate: createDate, uploadDate: uploadDate)
6771
}
6872
}
6973

@@ -131,6 +135,7 @@ struct AirtableTreeEncodable: Encodable {
131135
let species: String
132136
let notes: String?
133137
let coordinates: String?
138+
let what3words: String?
134139
let imageMd5: String?
135140
let createDate: Date?
136141
let uploadDate: Date?
@@ -141,18 +146,20 @@ struct AirtableTreeEncodable: Encodable {
141146
case species = "Species"
142147
case notes = "Notes"
143148
case coordinates = "Coordinates"
149+
case what3words = "What3Words"
144150
case image = "Image"
145151
case imageMd5 = "ImageSignature"
146152
case createDate = "CreatedDate"
147153
case uploadDate = "UploadedDate"
148154
case fields
149155
}
150156

151-
init(supervisor: String, species: String, notes: String?, coordinates: String?, imageUrl: String?, imageMd5: String?, uploadDate: Date?, createDate: Date?) {
157+
init(supervisor: String, species: String, notes: String?, coordinates: String?, what3words: String?, imageUrl: String?, imageMd5: String?, uploadDate: Date?, createDate: Date?) {
152158
self.supervisor = supervisor
153159
self.species = species
154160
self.notes = notes
155161
self.coordinates = coordinates
162+
self.what3words = what3words
156163
self.imageUrl = imageUrl
157164
self.imageMd5 = imageMd5
158165
self.uploadDate = uploadDate
@@ -167,6 +174,7 @@ struct AirtableTreeEncodable: Encodable {
167174
try container.encode(species, forKey: .species)
168175
try container.encode(notes, forKey: .notes)
169176
try container.encode(coordinates, forKey: .coordinates)
177+
try container.encode(what3words, forKey: .what3words)
170178
try container.encode(imageMd5, forKey: .imageMd5)
171179
try container.encode(imageUrl.map { AirtableImage(url: $0, thumbnailUrl: nil) }, forKey: .image)
172180
try container.encode(uploadDate, forKey: .uploadDate)

Tree Tracker/Models/LocalTree.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ struct LocalTree: Codable, FetchableRecord, PersistableRecord, TableRecord {
55
let phImageId: String
66
var createDate: Date?
77
var supervisor: String
8+
var what3words: String?
89
var species: String
910
var notes: String?
1011
var coordinates: String?
@@ -14,13 +15,14 @@ struct LocalTree: Codable, FetchableRecord, PersistableRecord, TableRecord {
1415
case phImageId
1516
case createDate
1617
case supervisor
18+
case what3words
1719
case species
1820
case notes
1921
case coordinates
2022
case imageMd5
2123
}
2224

2325
func toAirtableTree(imageUrl: String) -> AirtableTreeEncodable {
24-
return AirtableTreeEncodable(supervisor: supervisor, species: species, notes: notes, coordinates: coordinates, imageUrl: imageUrl, imageMd5: imageMd5, uploadDate: Date(), createDate: createDate)
26+
return AirtableTreeEncodable(supervisor: supervisor, species: species, notes: notes, coordinates: coordinates, what3words: what3words, imageUrl: imageUrl, imageMd5: imageMd5, uploadDate: Date(), createDate: createDate)
2527
}
2628
}

Tree Tracker/Models/RemoteTree.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct RemoteTree: Codable, FetchableRecord, PersistableRecord, TableRecord {
77
let species: String
88
let notes: String?
99
var coordinates: String?
10+
let what3words: String?
1011
var imageUrl: String?
1112
var thumbnailUrl: String?
1213
let imageMd5: String?
@@ -19,6 +20,7 @@ struct RemoteTree: Codable, FetchableRecord, PersistableRecord, TableRecord {
1920
case species
2021
case notes
2122
case coordinates
23+
case what3words
2224
case imageUrl
2325
case thumbnailUrl
2426
case imageMd5

Tree Tracker/Screens/Details/AddLocalTreeViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ final class AddLocalTreeViewModel: TreeDetailsViewModel {
108108
}
109109

110110
private func save(asset: PHAsset, coordinates: String, species: String, supervisor: String, notes: String) {
111-
let tree = LocalTree(phImageId: asset.localIdentifier, createDate: asset.creationDate, supervisor: supervisor, species: species, notes: notes, coordinates: coordinates, imageMd5: nil)
111+
let tree = LocalTree(phImageId: asset.localIdentifier, createDate: asset.creationDate, supervisor: supervisor, what3words: nil, species: species, notes: notes, coordinates: coordinates, imageMd5: nil)
112112
defaults[.species] = species
113113
defaults[.supervisor] = supervisor
114114
database.save([tree])

Tree Tracker/Services/Database.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ final class Database {
2323
table.column(RemoteTree.CodingKeys.species.stringValue, .text)
2424
table.column(RemoteTree.CodingKeys.notes.stringValue, .text)
2525
table.column(RemoteTree.CodingKeys.coordinates.stringValue, .text)
26+
table.column(RemoteTree.CodingKeys.what3words.stringValue, .text)
2627
table.column(RemoteTree.CodingKeys.imageUrl.stringValue, .text)
2728
table.column(RemoteTree.CodingKeys.thumbnailUrl.stringValue, .text)
2829
table.column(RemoteTree.CodingKeys.imageMd5.stringValue, .text)
@@ -41,6 +42,7 @@ final class Database {
4142
table.column(LocalTree.CodingKeys.species.stringValue, .text)
4243
table.column(LocalTree.CodingKeys.notes.stringValue, .text)
4344
table.column(LocalTree.CodingKeys.coordinates.stringValue, .text)
45+
table.column(LocalTree.CodingKeys.what3words.stringValue, .text)
4446
table.column(LocalTree.CodingKeys.imageMd5.stringValue, .text)
4547

4648
table.primaryKey([LocalTree.CodingKeys.phImageId.stringValue])

0 commit comments

Comments
 (0)