-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add caching next lessons for ios widget
- Loading branch information
1 parent
2b5aacb
commit 50bdce9
Showing
7 changed files
with
257 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// LessonRepository.swift | ||
// Runner | ||
// | ||
// Created by Oleg on 12.01.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol ILessonRepository { | ||
func fetchData(groupId: Int, completion: @escaping (Lesson?) -> Void) | ||
} | ||
|
||
class LessonRepository : ILessonRepository { | ||
let remoteDataProvider: DataProvider | ||
let localDataProvider: ILocalLessonDataProvider | ||
|
||
init(remoteDataProvider: DataProvider, localDataProvider: ILocalLessonDataProvider) { | ||
self.remoteDataProvider = remoteDataProvider | ||
self.localDataProvider = localDataProvider | ||
} | ||
|
||
func fetchData(groupId: Int, completion: @escaping (Lesson?) -> Void) { | ||
self.remoteDataProvider.fetchData(groupId: groupId) { lessons in | ||
if (lessons == nil) { | ||
let lessonsRecord = self.localDataProvider.fetchData(groupId: groupId) | ||
|
||
if (lessonsRecord == nil) { | ||
completion(nil) | ||
return | ||
} | ||
|
||
let lessons = lessonsRecord?.lessons | ||
|
||
if (lessons == nil || lessons?.isEmpty ?? true) { | ||
completion(nil) | ||
return | ||
} | ||
|
||
completion(lessons?.first) | ||
return | ||
} | ||
|
||
if let lessons = lessons { | ||
let lessonsRecord = LessonsRecord( | ||
lessons: lessons, savedDate: Date(), groupId: groupId | ||
) | ||
|
||
self.localDataProvider.saveData(lessonsRecord: lessonsRecord) | ||
|
||
completion(lessons.first) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ Future<Dependencies> $initializeDependencies({ | |
); | ||
} | ||
} | ||
|
||
return dependencies; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters