Skip to content

Commit

Permalink
Fix decoding of ParseCareKit entities when they come from the server (#…
Browse files Browse the repository at this point in the history
…56)

* testing bug

* add encodeIfPresent in Contact

* add entityId into ParseCareKit codingKeys for decoding. It previously wasn't decoding the key from the cloud

* Fix optional encoding for properties that aren't required
  • Loading branch information
cbaker6 authored Nov 3, 2020
1 parent c9e1792 commit 63c74ee
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions Sources/ParseCareKit/Objects/CarePlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public final class CarePlan: PCKVersionable, PCKSynchronizable {

enum CodingKeys: String, CodingKey {
case objectId, createdAt, updatedAt
case uuid, schemaVersion, createdDate, updatedDate, deletedDate, timezone, userInfo, groupIdentifier, tags, source, asset, remoteID, notes, logicalClock
case uuid, entityId, schemaVersion, createdDate, updatedDate, deletedDate, timezone, userInfo, groupIdentifier, tags, source, asset, remoteID, notes, logicalClock
case previousVersionUUID, nextVersionUUID, effectiveDate
case title, patient, patientUUID
}
Expand Down Expand Up @@ -328,10 +328,10 @@ extension CarePlan {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
if encodingForParse {
try container.encode(patient, forKey: .patient)
try container.encodeIfPresent(patient, forKey: .patient)
}
try container.encode(title, forKey: .title)
try container.encode(patientUUID, forKey: .patientUUID)
try container.encodeIfPresent(patientUUID, forKey: .patientUUID)
try encodeVersionable(to: encoder)
encodingForParse = true
}
Expand Down
24 changes: 12 additions & 12 deletions Sources/ParseCareKit/Objects/Contact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public final class Contact: PCKVersionable, PCKSynchronizable {

enum CodingKeys: String, CodingKey {
case objectId, createdAt, updatedAt
case uuid, schemaVersion, createdDate, updatedDate, deletedDate, timezone, userInfo, groupIdentifier, tags, source, asset, remoteID, notes, logicalClock
case uuid, entityId, schemaVersion, createdDate, updatedDate, deletedDate, timezone, userInfo, groupIdentifier, tags, source, asset, remoteID, notes, logicalClock
case previousVersionUUID, nextVersionUUID, effectiveDate
case carePlan, title, carePlanUUID, address, category, name, organization, role
case emailAddresses, messagingNumbers, phoneNumbers, otherContactInfo
Expand Down Expand Up @@ -349,20 +349,20 @@ extension Contact {
var container = encoder.container(keyedBy: CodingKeys.self)

if encodingForParse {
try container.encode(carePlan, forKey: .carePlan)
try container.encodeIfPresent(carePlan, forKey: .carePlan)
}

try container.encode(title, forKey: .title)
try container.encode(carePlanUUID, forKey: .carePlanUUID)
try container.encode(address, forKey: .address)
try container.encode(category, forKey: .category)
try container.encodeIfPresent(title, forKey: .title)
try container.encodeIfPresent(carePlanUUID, forKey: .carePlanUUID)
try container.encodeIfPresent(address, forKey: .address)
try container.encodeIfPresent(category, forKey: .category)
try container.encode(name, forKey: .name)
try container.encode(organization, forKey: .organization)
try container.encode(role, forKey: .role)
try container.encode(emailAddresses, forKey: .emailAddresses)
try container.encode(messagingNumbers, forKey: .messagingNumbers)
try container.encode(phoneNumbers, forKey: .phoneNumbers)
try container.encode(otherContactInfo, forKey: .otherContactInfo)
try container.encodeIfPresent(organization, forKey: .organization)
try container.encodeIfPresent(role, forKey: .role)
try container.encodeIfPresent(emailAddresses, forKey: .emailAddresses)
try container.encodeIfPresent(messagingNumbers, forKey: .messagingNumbers)
try container.encodeIfPresent(phoneNumbers, forKey: .phoneNumbers)
try container.encodeIfPresent(otherContactInfo, forKey: .otherContactInfo)
try encodeVersionable(to: encoder)
encodingForParse = true
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/ParseCareKit/Objects/Outcome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ extension Outcome {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
if encodingForParse {
try container.encode(task, forKey: .task)
try container.encode(date, forKey: .date)
try container.encodeIfPresent(task, forKey: .task)
try container.encodeIfPresent(date, forKey: .date)
}
try container.encode(taskUUID, forKey: .taskUUID)
try container.encode(taskOccurrenceIndex, forKey: .taskOccurrenceIndex)
Expand Down
8 changes: 4 additions & 4 deletions Sources/ParseCareKit/Objects/Patient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@ public final class Patient: PCKVersionable, PCKSynchronizable {

enum CodingKeys: String, CodingKey {
case objectId, createdAt, updatedAt
case uuid, schemaVersion, createdDate, updatedDate, deletedDate, timezone, userInfo, groupIdentifier, tags, source, asset, remoteID, notes, logicalClock
case uuid, entityId, schemaVersion, createdDate, updatedDate, deletedDate, timezone, userInfo, groupIdentifier, tags, source, asset, remoteID, notes, logicalClock
case previousVersionUUID, nextVersionUUID, effectiveDate
case allergies, birthday, name, sex
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(allergies, forKey: .allergies)
try container.encode(birthday, forKey: .birthday)
try container.encodeIfPresent(allergies, forKey: .allergies)
try container.encodeIfPresent(birthday, forKey: .birthday)
try container.encode(name, forKey: .name)
try container.encode(sex, forKey: .sex)
try container.encodeIfPresent(sex, forKey: .sex)
try encodeVersionable(to: encoder)
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/ParseCareKit/Objects/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public final class Task: PCKVersionable, PCKSynchronizable {

enum CodingKeys: String, CodingKey {
case objectId, createdAt, updatedAt
case uuid, schemaVersion, createdDate, updatedDate, deletedDate, timezone, userInfo, groupIdentifier, tags, source, asset, remoteID, notes, logicalClock
case uuid, entityId, schemaVersion, createdDate, updatedDate, deletedDate, timezone, userInfo, groupIdentifier, tags, source, asset, remoteID, notes, logicalClock
case previousVersionUUID, nextVersionUUID, effectiveDate
case title, carePlan, carePlanUUID, impactsAdherence, instructions, schedule
}
Expand Down Expand Up @@ -352,10 +352,10 @@ extension Task {
if encodingForParse {
try container.encode(carePlan, forKey: .carePlan)
}
try container.encode(title, forKey: .title)
try container.encode(carePlanUUID, forKey: .carePlanUUID)
try container.encodeIfPresent(title, forKey: .title)
try container.encodeIfPresent(carePlanUUID, forKey: .carePlanUUID)
try container.encode(impactsAdherence, forKey: .impactsAdherence)
try container.encode(instructions, forKey: .instructions)
try container.encodeIfPresent(instructions, forKey: .instructions)
try container.encode(schedule, forKey: .schedule)
try encodeVersionable(to: encoder)
encodingForParse = true
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseCareKit/Protocols/PCKObjectable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ extension PCKObjectable {
var container = encoder.container(keyedBy: PCKCodingKeys.self)

if encodingForParse {
if !(self is Note) {
if !(self is Note) || !(self is OutcomeValue) {
try container.encodeIfPresent(entityId, forKey: .entityId)
}
try container.encodeIfPresent(ACL, forKey: .ACL)
Expand Down

0 comments on commit 63c74ee

Please sign in to comment.