2021-02-03 06:43:57 +01:00
|
|
|
//
|
|
|
|
// Application.swift
|
|
|
|
// CoreDataStack
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/2/3.
|
|
|
|
//
|
|
|
|
|
|
|
|
import CoreData
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
public final class Application: NSManagedObject {
|
|
|
|
public typealias ID = UUID
|
|
|
|
@NSManaged public private(set) var identifier: ID
|
|
|
|
@NSManaged public private(set) var createAt: Date
|
|
|
|
|
|
|
|
@NSManaged public private(set) var name: String
|
|
|
|
@NSManaged public private(set) var website: String?
|
|
|
|
@NSManaged public private(set) var vapidKey: String?
|
|
|
|
|
2021-04-01 08:39:15 +02:00
|
|
|
// one-to-one relationship
|
|
|
|
@NSManaged public private(set) var status: Status
|
2021-02-03 06:43:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public extension Application {
|
|
|
|
override func awakeFromInsert() {
|
|
|
|
super.awakeFromInsert()
|
2021-03-06 06:04:30 +01:00
|
|
|
setPrimitiveValue(UUID(), forKey: #keyPath(Application.identifier))
|
2021-02-03 06:43:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@discardableResult
|
|
|
|
static func insert(
|
|
|
|
into context: NSManagedObjectContext,
|
|
|
|
property: Property
|
|
|
|
) -> Application {
|
|
|
|
let app: Application = context.insertObject()
|
|
|
|
app.name = property.name
|
|
|
|
app.website = property.website
|
|
|
|
app.vapidKey = property.vapidKey
|
|
|
|
return app
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public extension Application {
|
|
|
|
struct Property {
|
|
|
|
public let name: String
|
|
|
|
public let website: String?
|
|
|
|
public let vapidKey: String?
|
|
|
|
|
|
|
|
public init(name: String, website: String?, vapidKey: String?) {
|
|
|
|
self.name = name
|
|
|
|
self.website = website
|
|
|
|
self.vapidKey = vapidKey
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Application: Managed {
|
|
|
|
public static var defaultSortDescriptors: [NSSortDescriptor] {
|
|
|
|
return [NSSortDescriptor(keyPath: \Application.createAt, ascending: false)]
|
|
|
|
}
|
|
|
|
}
|