From ba0d4da6576f38bec11b860efe49b24b2578ed0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Mu=CC=88ller?= Date: Wed, 10 Feb 2021 21:27:26 +0100 Subject: [PATCH] :sparkles: Adding lecturer to lecture plan item detail view --- .../CoreData/Models/Lecturer+CoreDataClass.swift | 10 ++++++++++ .../CoreData/Models/RaPlaEvent+CoreDataClass.swift | 10 ++++++++++ DHBW-Service/Views/ContentView.swift | 2 +- DHBW-Service/Views/Tabs/LecturePlanItem.swift | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/DHBW-Service/CoreData/Models/Lecturer+CoreDataClass.swift b/DHBW-Service/CoreData/Models/Lecturer+CoreDataClass.swift index ea7ba96..942230e 100644 --- a/DHBW-Service/CoreData/Models/Lecturer+CoreDataClass.swift +++ b/DHBW-Service/CoreData/Models/Lecturer+CoreDataClass.swift @@ -11,6 +11,7 @@ import CoreData @objc(Lecturer) public class Lecturer: NSManagedObject { + // MARK: Access methods @nonobjc public class func getAll() -> [Lecturer] { let managedContext = PersistenceController.shared.context @@ -41,4 +42,13 @@ public class Lecturer: NSManagedObject { return [] } } + + // MARK: Wrappers + public var wrappedName: String { + name ?? "" + } + + public var wrappedEmail: String { + email ?? "" + } } diff --git a/DHBW-Service/CoreData/Models/RaPlaEvent+CoreDataClass.swift b/DHBW-Service/CoreData/Models/RaPlaEvent+CoreDataClass.swift index c553290..e197dfa 100644 --- a/DHBW-Service/CoreData/Models/RaPlaEvent+CoreDataClass.swift +++ b/DHBW-Service/CoreData/Models/RaPlaEvent+CoreDataClass.swift @@ -11,6 +11,8 @@ import CoreData @objc(RaPlaEvent) public class RaPlaEvent: NSManagedObject { + + // MARK: Access methods @nonobjc public class func getAll() -> [RaPlaEvent] { let managedContext = PersistenceController.shared.context @@ -41,4 +43,12 @@ public class RaPlaEvent: NSManagedObject { return [] } } + + // MARK: Wrappers + public var lecturerList: [Lecturer] { + let set = lecturers as? Set ?? [] + return set.sorted { + $0.wrappedName < $1.wrappedName + } + } } diff --git a/DHBW-Service/Views/ContentView.swift b/DHBW-Service/Views/ContentView.swift index cfa4abb..7c2908a 100644 --- a/DHBW-Service/Views/ContentView.swift +++ b/DHBW-Service/Views/ContentView.swift @@ -47,7 +47,7 @@ struct ContentView: View { } .onAppear{ // Called upon the opening of the app - RaPlaFetcher.getRaplaFileAndSaveToCoreData(from: "https://rapla.dhbw-karlsruhe.de/rapla?page=ical&user=eisenbiegler&file=TINF20B4") + RaPlaFetcher.getRaplaFileAndSaveToCoreData(from: "https://rapla.dhbw-karlsruhe.de/rapla?page=ical&user=eisenbiegler&file=TINF19B4") } } } diff --git a/DHBW-Service/Views/Tabs/LecturePlanItem.swift b/DHBW-Service/Views/Tabs/LecturePlanItem.swift index 4feb7e4..6541bef 100644 --- a/DHBW-Service/Views/Tabs/LecturePlanItem.swift +++ b/DHBW-Service/Views/Tabs/LecturePlanItem.swift @@ -37,7 +37,7 @@ struct LecturePlanItem: View { .bold() Text(event.location!) .bold() - Text("WIP") + Text(!event.lecturerList.isEmpty ? event.lecturerList[0].wrappedName : "") .bold() }.frame(maxWidth: .infinity, alignment: .leading) }