52 lines
1.4 KiB
Swift
52 lines
1.4 KiB
Swift
import Foundation
|
|
import RealmSwift
|
|
import CoreLocation
|
|
|
|
public final class VehicleEvent: Object {
|
|
|
|
@Persisted public var id: String = UUID().uuidString
|
|
@Persisted public var date: TimeInterval = Date().timeIntervalSince1970
|
|
@Persisted public var latitude: Double = 0
|
|
@Persisted public var longitude: Double = 0
|
|
@Persisted public var address: String? = nil
|
|
@Persisted public var addedBy: String? = nil
|
|
|
|
public var number: String?
|
|
public var coordinate: CLLocationCoordinate2D {
|
|
return CLLocationCoordinate2D(latitude: self.latitude, longitude: self.longitude)
|
|
}
|
|
|
|
public override static func primaryKey() -> String? {
|
|
return "id"
|
|
}
|
|
|
|
public override static func ignoredProperties() -> [String] {
|
|
return ["plateNumber"]
|
|
}
|
|
}
|
|
|
|
extension VehicleEvent: DtoConvertible {
|
|
|
|
public var dto: VehicleEventDto {
|
|
|
|
var dto = VehicleEventDto(lat: latitude, lon: longitude, addedBy: addedBy)
|
|
dto.id = id
|
|
dto.date = date
|
|
dto.address = address
|
|
return dto
|
|
}
|
|
|
|
public convenience init(dto: VehicleEventDto) {
|
|
|
|
self.init()
|
|
|
|
self.id = dto.id
|
|
self.date = dto.date
|
|
self.address = dto.address
|
|
self.number = dto.number
|
|
self.addedBy = dto.addedBy
|
|
self.latitude = dto.latitude
|
|
self.longitude = dto.longitude
|
|
}
|
|
}
|