Commit ceb47a47 authored by Eyad Hasan's avatar Eyad Hasan
Browse files

Added an object for our special schedules

parent fbe27cce
......@@ -15,6 +15,7 @@ class Facility: Object {
dynamic var category = Categories()
let facilityTags = List<FacilityTags>()
dynamic var mainSchedule = MainSchedule()
dynamic var specialSchedule = SpecialSchedule()
......@@ -56,6 +57,18 @@ class MainSchedule: Object {
}
class SpecialSchedule: Object {
dynamic var id = 0
let openTimes = List<OpenTimes>()
dynamic var lastModified = ""
dynamic var name = ""
dynamic var validStart = ""
dynamic var validEnd = ""
dynamic var twentyFourHours = false
}
class OpenTimes: Object {
dynamic var schedule = 0
dynamic var lastModified = ""
......@@ -66,6 +79,8 @@ class OpenTimes: Object {
}
/**struct OpenTimes: CreatableFromJSON { // TODO: Rename this struct
let endDay: Int
let endTime: Date
......
......@@ -8,11 +8,14 @@
import UIKit
import Foundation
import RealmSwift
class SRCTNetworkController: NSObject {
//Use this for testing with the new API, might make it possible to get stuff moving pre official release
//https://api.srct.gmu.edu/whatsopen/v2/facilities/?format=json
public static func performDownload(completion: @escaping (_ result: Array<Facility>) -> Void) {
let realm = try! Realm()
let requestURL: NSURL = NSURL(string: "https://api.srct.gmu.edu/whatsopen/v2/facilities/?format=json")!
let urlRequest: NSMutableURLRequest = NSMutableURLRequest(url: requestURL as URL)
let session = URLSession.shared
......@@ -27,15 +30,13 @@ class SRCTNetworkController: NSObject {
//var schedules = Array
//Finish this, and fix the function
try! realm.write{
let json = try? JSONSerialization.jsonObject(with: dataN, options: [])
if let schedule = json as? [String: Any]{
if let currentSchedule = schedule["main_schedule"] as? Array{
schedule.append(currentSchedule)
}
realm.create(Facility.self, value: json!, update: true)
}
}
......@@ -45,7 +46,7 @@ class SRCTNetworkController: NSObject {
}
print(schedules)
print(Facility.self)
task.resume()
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment