Skip to content

Commit

Permalink
[#39] 현재 학기 CoreData 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJoEun-01 committed Dec 25, 2024
1 parent 5d2bd6a commit f3b799d
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Soomsil-USaint/Rusaint_iOSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public func compareAndFetchCurrentSemester() async {
do {
let existingSemester = SemesterRepository.shared.getSemester(year: 2024, semester: "2 학기")

print("=== 🌟🌟🌟\(String(describing: existingSemester))")
print()
// print("=== 🌟🌟🌟\(String(describing: existingSemester))")
// print()

let userInfo = HomeRepository.shared.getUserLoginInformation()
let session = try await USaintSessionBuilder().withPassword(id: userInfo[0], password: userInfo[1])
Expand All @@ -84,15 +84,14 @@ public func compareAndFetchCurrentSemester() async {

if let existingSemester = existingSemester {
let differences = compareSemesters(existingSemester, currentSemester)
print("=== ❌❌❌ Differences:", differences)
print()
// print("=== ❌❌❌ Differences:", differences)
// print()

if !differences.isEmpty {
for i in 0...differences.count-1 {
LocalNotificationManager.shared.pushLectureNotification(lectureTitle: differences[i])
}
} else {
LocalNotificationManager.shared.pushLectureNotification(lectureTitle: "업데이트 X")
SemesterRepository.shared.updateLecturesForSemester(year: 2024, semester: "2 학기", newLectures: currentClassesData)
}
} else {
print("No existing semester found.")
Expand All @@ -104,18 +103,20 @@ public func compareAndFetchCurrentSemester() async {
}

private func compareSemesters(_ oldSemester: GradeSummaryModel, _ newSemester: GradeSummaryModel) -> [String] {
let oldLectures = oldSemester.lectures.reduce(into: [String: LectureDetailModel]()) { result, lecture in
let oldLectures = oldSemester.lectures?.reduce(into: [String: LectureDetailModel]()) { result, lecture in
result[lecture.code] = lecture
}
let newLectures = newSemester.lectures.reduce(into: [String: LectureDetailModel]()) { result, lecture in
let newLectures = newSemester.lectures?.reduce(into: [String: LectureDetailModel]()) { result, lecture in
result[lecture.code] = lecture
}
var gradeChangedLectures: [String] = []

for (code, newLecture) in newLectures {
if let oldLecture = oldLectures[code],
oldLecture.grade != newLecture.grade {
gradeChangedLectures.append(newLecture.title)
if let newLectures = newLectures { // 먼저 newLectures를 언랩
for (code, newLecture) in newLectures {
if let oldLecture = oldLectures?[code],
oldLecture.grade != newLecture.grade {
gradeChangedLectures.append(newLecture.title)
}
}
}

Expand Down

0 comments on commit f3b799d

Please sign in to comment.