mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
define feeditem models in core data model
This commit is contained in:
parent
0264564a64
commit
a879a68ad8
4 changed files with 125 additions and 83 deletions
|
|
@ -1,4 +1,38 @@
|
|||
<?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="">
|
||||
<elements/>
|
||||
<entity name="PersistedArticleContent" representedClassName="PersistedArticleContent" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="htmlContent" attributeType="String"/>
|
||||
<attribute name="slug" attributeType="String"/>
|
||||
</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="PersistedFeedItemLabel"/>
|
||||
</entity>
|
||||
<entity name="PersistedFeedItemLabel" representedClassName="PersistedFeedItemLabel" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="color" attributeType="String"/>
|
||||
<attribute name="createdAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="id" attributeType="String"/>
|
||||
<attribute name="labelDescription" optional="YES" attributeType="String"/>
|
||||
<attribute name="name" attributeType="String"/>
|
||||
</entity>
|
||||
<elements>
|
||||
<element name="PersistedFeedItemLabel" positionX="-36" positionY="18" width="128" height="104"/>
|
||||
<element name="PersistedFeedItem" positionX="-18" positionY="63" width="128" height="14"/>
|
||||
<element name="PersistedArticleContent" positionX="9" positionY="108" width="128" height="59"/>
|
||||
</elements>
|
||||
</model>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import CoreData
|
||||
// import CoreData
|
||||
import Foundation
|
||||
|
||||
public struct HomeFeedData {
|
||||
|
|
@ -11,28 +11,32 @@ public struct HomeFeedData {
|
|||
}
|
||||
}
|
||||
|
||||
public class FeedItemManagedObject: NSManagedObject {
|
||||
static let entityName = "FeedItemManagedObject"
|
||||
|
||||
@NSManaged public var id: String
|
||||
@NSManaged public var title: String
|
||||
@NSManaged public var createdAt: Date
|
||||
@NSManaged public var savedAt: Date
|
||||
@NSManaged public var readingProgress: Double
|
||||
@NSManaged public var readingProgressAnchor: Int
|
||||
@NSManaged public var imageURLString: String?
|
||||
@NSManaged public var onDeviceImageURLString: String?
|
||||
@NSManaged public var documentDirectoryPath: String?
|
||||
@NSManaged public var pageURLString: String
|
||||
@NSManaged public var descriptionText: String?
|
||||
@NSManaged public var publisherURLString: String?
|
||||
@NSManaged public var author: String?
|
||||
@NSManaged public var publishDate: Date?
|
||||
@NSManaged public var slug: String
|
||||
@NSManaged public var isArchived: Bool
|
||||
@NSManaged public var contentReader: String?
|
||||
@NSManaged public var labels: Set<FeedItemLabelManagedObject>
|
||||
}
|
||||
// public class FeedItemManagedObject: NSManagedObject {
|
||||
// static let entityName = "FeedItemManagedObject"
|
||||
//
|
||||
// @nonobjc public class func fetchRequest() -> NSFetchRequest<FeedItemManagedObject> {
|
||||
// NSFetchRequest<FeedItemManagedObject>(entityName: entityName)
|
||||
// }
|
||||
//
|
||||
// @NSManaged public var id: String
|
||||
// @NSManaged public var title: String
|
||||
// @NSManaged public var createdAt: Date
|
||||
// @NSManaged public var savedAt: Date
|
||||
// @NSManaged public var readingProgress: Double
|
||||
// @NSManaged public var readingProgressAnchor: Int
|
||||
// @NSManaged public var imageURLString: String?
|
||||
// @NSManaged public var onDeviceImageURLString: String?
|
||||
// @NSManaged public var documentDirectoryPath: String?
|
||||
// @NSManaged public var pageURLString: String
|
||||
// @NSManaged public var descriptionText: String?
|
||||
// @NSManaged public var publisherURLString: String?
|
||||
// @NSManaged public var author: String?
|
||||
// @NSManaged public var publishDate: Date?
|
||||
// @NSManaged public var slug: String
|
||||
// @NSManaged public var isArchived: Bool
|
||||
// @NSManaged public var contentReader: String?
|
||||
// @NSManaged public var labels: Set<FeedItemLabelManagedObject>
|
||||
// }
|
||||
|
||||
public struct FeedItem: Identifiable, Hashable {
|
||||
public let id: String
|
||||
|
|
@ -94,39 +98,40 @@ public struct FeedItem: Identifiable, Hashable {
|
|||
self.labels = labels
|
||||
}
|
||||
|
||||
func toManagedObject(inContext context: NSManagedObjectContext) -> FeedItemManagedObject? {
|
||||
guard let entityDescription = NSEntityDescription.entity(forEntityName: FeedItemManagedObject.entityName, in: context) else {
|
||||
print("Failed to create \(FeedItemManagedObject.entityName)")
|
||||
return nil
|
||||
}
|
||||
|
||||
let object = FeedItemManagedObject(entity: entityDescription, insertInto: context)
|
||||
object.id = id
|
||||
object.title = title
|
||||
object.createdAt = createdAt
|
||||
object.savedAt = savedAt
|
||||
object.readingProgress = readingProgress
|
||||
object.readingProgressAnchor = readingProgressAnchor
|
||||
object.imageURLString = imageURLString
|
||||
object.onDeviceImageURLString = onDeviceImageURLString
|
||||
object.documentDirectoryPath = documentDirectoryPath
|
||||
object.pageURLString = pageURLString
|
||||
object.descriptionText = descriptionText
|
||||
object.publisherURLString = publisherURLString
|
||||
object.author = author
|
||||
object.publishDate = publishDate
|
||||
object.slug = slug
|
||||
object.isArchived = isArchived
|
||||
object.contentReader = contentReader
|
||||
|
||||
for label in labels {
|
||||
if let managedLabel = label.toManagedObject(inContext: context) {
|
||||
object.labels.insert(managedLabel)
|
||||
}
|
||||
}
|
||||
|
||||
return object
|
||||
}
|
||||
// func toManagedObject(inContext context: NSManagedObjectContext) -> FeedItemManagedObject? {
|
||||
// let entityName = FeedItemManagedObject.entityName
|
||||
// guard let entityDescription = NSEntityDescription.entity(forEntityName: entityName, in: context) else {
|
||||
// print("Failed to create \(entityName)")
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// let object = FeedItemManagedObject(entity: entityDescription, insertInto: context)
|
||||
// object.id = id
|
||||
// object.title = title
|
||||
// object.createdAt = createdAt
|
||||
// object.savedAt = savedAt
|
||||
// object.readingProgress = readingProgress
|
||||
// object.readingProgressAnchor = readingProgressAnchor
|
||||
// object.imageURLString = imageURLString
|
||||
// object.onDeviceImageURLString = onDeviceImageURLString
|
||||
// object.documentDirectoryPath = documentDirectoryPath
|
||||
// object.pageURLString = pageURLString
|
||||
// object.descriptionText = descriptionText
|
||||
// object.publisherURLString = publisherURLString
|
||||
// object.author = author
|
||||
// object.publishDate = publishDate
|
||||
// object.slug = slug
|
||||
// object.isArchived = isArchived
|
||||
// object.contentReader = contentReader
|
||||
//
|
||||
// for label in labels {
|
||||
// if let managedLabel = label.toManagedObject(inContext: context) {
|
||||
// object.labels.insert(managedLabel)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return object
|
||||
// }
|
||||
|
||||
public static func fromJsonArticle(linkData: Data) -> FeedItem? {
|
||||
try? JSONDecoder().decode(JSONArticle.self, from: linkData).feedItem
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import CoreData
|
||||
// import CoreData
|
||||
import Foundation
|
||||
|
||||
public struct FeedItemLabel: Decodable, Hashable {
|
||||
|
|
@ -22,29 +22,33 @@ public struct FeedItemLabel: Decodable, Hashable {
|
|||
self.labelDescription = labelDescription
|
||||
}
|
||||
|
||||
func toManagedObject(inContext context: NSManagedObjectContext) -> FeedItemLabelManagedObject? {
|
||||
let entityName = FeedItemLabelManagedObject.entityName
|
||||
guard let entityDescription = NSEntityDescription.entity(forEntityName: entityName, in: context) else {
|
||||
print("Failed to create \(entityName)")
|
||||
return nil
|
||||
}
|
||||
|
||||
let object = FeedItemLabelManagedObject(entity: entityDescription, insertInto: context)
|
||||
object.id = id
|
||||
object.name = name
|
||||
object.color = color
|
||||
object.createdAt = createdAt
|
||||
object.labelDescription = labelDescription
|
||||
return object
|
||||
}
|
||||
// func toManagedObject(inContext context: NSManagedObjectContext) -> FeedItemLabelManagedObject? {
|
||||
// let entityName = FeedItemLabelManagedObject.entityName
|
||||
// guard let entityDescription = NSEntityDescription.entity(forEntityName: entityName, in: context) else {
|
||||
// print("Failed to create \(entityName)")
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// let object = FeedItemLabelManagedObject(entity: entityDescription, insertInto: context)
|
||||
// object.id = id
|
||||
// object.name = name
|
||||
// object.color = color
|
||||
// object.createdAt = createdAt
|
||||
// object.labelDescription = labelDescription
|
||||
// return object
|
||||
// }
|
||||
}
|
||||
|
||||
public class FeedItemLabelManagedObject: NSManagedObject {
|
||||
static let entityName = "FeedItemLabelManagedObject"
|
||||
|
||||
@NSManaged public var id: String
|
||||
@NSManaged public var name: String
|
||||
@NSManaged public var color: String
|
||||
@NSManaged public var createdAt: Date?
|
||||
@NSManaged public var labelDescription: String?
|
||||
}
|
||||
// public class FeedItemLabelManagedObject: NSManagedObject {
|
||||
// static let entityName = "FeedItemLabelManagedObject"
|
||||
//
|
||||
// @nonobjc public class func fetchRequest() -> NSFetchRequest<FeedItemLabelManagedObject> {
|
||||
// NSFetchRequest<FeedItemLabelManagedObject>(entityName: entityName)
|
||||
// }
|
||||
//
|
||||
// @NSManaged public var id: String
|
||||
// @NSManaged public var name: String
|
||||
// @NSManaged public var color: String
|
||||
// @NSManaged public var createdAt: Date?
|
||||
// @NSManaged public var labelDescription: String?
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import Combine
|
||||
import CoreData
|
||||
import Foundation
|
||||
import Models
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue