rename cordata entities

This commit is contained in:
Satindar Dhillon 2022-04-18 20:14:16 -07:00
parent 0fc7ff0a43
commit 70c9080766
4 changed files with 80 additions and 80 deletions

View file

@ -1,5 +1,48 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="20086" systemVersion="21A559" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Highlight" representedClassName="Highlight" syncable="YES" codeGenerationType="class">
<attribute name="annotation" optional="YES" attributeType="String"/>
<attribute name="associatedItemId" attributeType="String"/>
<attribute name="createdAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="createdByMe" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="id" attributeType="String"/>
<attribute name="markedForDeletion" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="patch" attributeType="String"/>
<attribute name="prefix" optional="YES" attributeType="String"/>
<attribute name="quote" attributeType="String"/>
<attribute name="shortId" attributeType="String"/>
<attribute name="suffix" optional="YES" attributeType="String"/>
<attribute name="updatedAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="id"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="LinkedItem" representedClassName="LinkedItem" syncable="YES" codeGenerationType="class">
<attribute name="author" optional="YES" attributeType="String"/>
<attribute name="contentReader" optional="YES" attributeType="String"/>
<attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="descriptionText" optional="YES" attributeType="String"/>
<attribute name="id" attributeType="String"/>
<attribute name="imageURLString" optional="YES" attributeType="String"/>
<attribute name="isArchived" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="onDeviceImageURLString" optional="YES" attributeType="String"/>
<attribute name="pageURLString" attributeType="String"/>
<attribute name="publishDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="publisherURLString" optional="YES" attributeType="String"/>
<attribute name="readingProgress" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="readingProgressAnchor" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="savedAt" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="slug" attributeType="String"/>
<attribute name="title" attributeType="String"/>
<relationship name="labels" toMany="YES" deletionRule="Nullify" destinationEntity="LinkedItemLabel"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="id"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="LinkedItemLabel" representedClassName="LinkedItemLabel" syncable="YES" codeGenerationType="class">
<attribute name="color" attributeType="String"/>
<attribute name="createdAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
@ -31,49 +74,6 @@
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="PersistedFeedItem" representedClassName="PersistedFeedItem" syncable="YES" codeGenerationType="class">
<attribute name="author" optional="YES" attributeType="String"/>
<attribute name="contentReader" optional="YES" attributeType="String"/>
<attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="descriptionText" optional="YES" attributeType="String"/>
<attribute name="id" attributeType="String"/>
<attribute name="imageURLString" optional="YES" attributeType="String"/>
<attribute name="isArchived" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="onDeviceImageURLString" optional="YES" attributeType="String"/>
<attribute name="pageURLString" attributeType="String"/>
<attribute name="publishDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="publisherURLString" optional="YES" attributeType="String"/>
<attribute name="readingProgress" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="readingProgressAnchor" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="savedAt" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="slug" attributeType="String"/>
<attribute name="title" attributeType="String"/>
<relationship name="labels" toMany="YES" deletionRule="Nullify" destinationEntity="LinkedItemLabel"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="id"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="PersistedHighlight" representedClassName="PersistedHighlight" syncable="YES" codeGenerationType="class">
<attribute name="annotation" optional="YES" attributeType="String"/>
<attribute name="associatedItemId" attributeType="String"/>
<attribute name="createdAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="createdByMe" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="id" attributeType="String"/>
<attribute name="markedForDeletion" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="patch" attributeType="String"/>
<attribute name="prefix" optional="YES" attributeType="String"/>
<attribute name="quote" attributeType="String"/>
<attribute name="shortId" attributeType="String"/>
<attribute name="suffix" optional="YES" attributeType="String"/>
<attribute name="updatedAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="id"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="Viewer" representedClassName="Viewer" syncable="YES" codeGenerationType="class">
<attribute name="name" attributeType="String"/>
<attribute name="profileImageURL" optional="YES" attributeType="String"/>
@ -86,11 +86,11 @@
</uniquenessConstraints>
</entity>
<elements>
<element name="PersistedArticleContent" positionX="9" positionY="108" width="128" height="59"/>
<element name="PersistedFeedItem" positionX="-18" positionY="63" width="128" height="284"/>
<element name="LinkedItemLabel" positionX="-36" positionY="18" width="128" height="104"/>
<element name="PersistedHighlight" positionX="27" positionY="225" width="128" height="209"/>
<element name="Viewer" positionX="45" positionY="234" width="128" height="89"/>
<element name="NewsletterEmail" positionX="0" positionY="180" width="128" height="74"/>
<element name="PersistedArticleContent" positionX="9" positionY="108" width="128" height="59"/>
<element name="LinkedItem" positionX="-18" positionY="63" width="128" height="284"/>
<element name="Highlight" positionX="27" positionY="225" width="128" height="209"/>
<element name="Viewer" positionX="45" positionY="234" width="128" height="89"/>
</elements>
</model>

View file

@ -37,35 +37,35 @@ public struct HighlightDep: Identifiable, Hashable, Codable {
self.createdByMe = createdByMe
}
public func toManagedObject(context: NSManagedObjectContext, associatedItemID: String) -> PersistedHighlight {
let persistedHighlight = PersistedHighlight(context: context)
persistedHighlight.associatedItemId = associatedItemID
persistedHighlight.markedForDeletion = false
persistedHighlight.id = id
persistedHighlight.shortId = shortId
persistedHighlight.quote = quote
persistedHighlight.prefix = prefix
persistedHighlight.suffix = suffix
persistedHighlight.patch = patch
persistedHighlight.annotation = annotation
persistedHighlight.createdAt = createdAt
persistedHighlight.updatedAt = updatedAt
persistedHighlight.createdByMe = createdByMe
return persistedHighlight
public func toManagedObject(context: NSManagedObjectContext, associatedItemID: String) -> Highlight {
let highlight = Highlight(context: context)
highlight.associatedItemId = associatedItemID
highlight.markedForDeletion = false
highlight.id = id
highlight.shortId = shortId
highlight.quote = quote
highlight.prefix = prefix
highlight.suffix = suffix
highlight.patch = patch
highlight.annotation = annotation
highlight.createdAt = createdAt
highlight.updatedAt = updatedAt
highlight.createdByMe = createdByMe
return highlight
}
public static func make(from persistedHighlight: PersistedHighlight) -> HighlightDep {
public static func make(from highlight: Highlight) -> HighlightDep {
HighlightDep(
id: persistedHighlight.id ?? "",
shortId: persistedHighlight.shortId ?? "",
quote: persistedHighlight.quote ?? "",
prefix: persistedHighlight.prefix,
suffix: persistedHighlight.suffix,
patch: persistedHighlight.patch ?? "",
annotation: persistedHighlight.annotation,
createdByMe: persistedHighlight.createdByMe,
createdAt: persistedHighlight.createdAt,
updatedAt: persistedHighlight.updatedAt
id: highlight.id ?? "",
shortId: highlight.shortId ?? "",
quote: highlight.quote ?? "",
prefix: highlight.prefix,
suffix: highlight.suffix,
patch: highlight.patch ?? "",
annotation: highlight.annotation,
createdByMe: highlight.createdByMe,
createdAt: highlight.createdAt,
updatedAt: highlight.updatedAt
)
}
}

View file

@ -37,7 +37,7 @@ public final class DataService: ObservableObject {
public func clearHighlights() {
deletedHighlightsIDs.removeAll()
let fetchRequest: NSFetchRequest<Models.PersistedHighlight> = PersistedHighlight.fetchRequest()
let fetchRequest: NSFetchRequest<Models.Highlight> = Highlight.fetchRequest()
let highlights = (try? persistentContainer.viewContext.fetch(fetchRequest)) ?? []

View file

@ -5,7 +5,7 @@ import Models
public extension DataService {
func cachedHighlights(pdfID: String) -> [HighlightDep] {
let fetchRequest: NSFetchRequest<Models.PersistedHighlight> = PersistedHighlight.fetchRequest()
let fetchRequest: NSFetchRequest<Models.Highlight> = Highlight.fetchRequest()
fetchRequest.predicate = NSPredicate(
format: "associatedItemId = %@ AND markedForDeletion = %@", pdfID, false
)
@ -22,10 +22,10 @@ public extension DataService {
do {
try persistentContainer.viewContext.save()
print("PersistedHighlight saved succesfully")
print("Highlight saved succesfully")
} catch {
persistentContainer.viewContext.rollback()
print("Failed to save PersistedHighlight: \(error)")
print("Failed to save Highlight: \(error)")
}
}
@ -34,7 +34,7 @@ public extension DataService {
deletedHighlightsIDs.insert(highlightID)
}
let fetchRequest: NSFetchRequest<Models.PersistedHighlight> = PersistedHighlight.fetchRequest()
let fetchRequest: NSFetchRequest<Models.Highlight> = Highlight.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "id IN %@", highlightIds)
guard let highlights = try? persistentContainer.viewContext.fetch(fetchRequest) else { return }
@ -44,10 +44,10 @@ public extension DataService {
do {
try persistentContainer.viewContext.save()
print("PersistedHighlight(s) updated succesfully")
print("Highlight(s) updated succesfully")
} catch {
persistentContainer.viewContext.rollback()
print("Failed to update PersistedHighlight(s): \(error)")
print("Failed to update Highlight(s): \(error)")
}
}
}