-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update launch screen * Create lessons service * Display lessons * Handle lesson selection * Create CourseService * Create EnrollmentService * Join courses * Support cache in LessonsService
- Loading branch information
1 parent
18aabdc
commit be21f90
Showing
43 changed files
with
854 additions
and
113 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
ExamEGERussian/Resources/Assets/Assets.xcassets/logo.imageset/Contents.json
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,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "logo.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Binary file added
BIN
+18.9 KB
ExamEGERussian/Resources/Assets/Assets.xcassets/logo.imageset/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
23 changes: 23 additions & 0 deletions
23
ExamEGERussian/Sources/BusinessLogicLayer/Services/CourseService/CourseService.swift
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,23 @@ | ||
// | ||
// CourseService.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 26/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import PromiseKit | ||
|
||
protocol CourseService: class { | ||
/// Method is used to fetch Course objects from Stepik API | ||
/// | ||
/// - Parameter ids: Ids Course objects | ||
/// - Returns: Promise with a result of an array of Course objects from API. | ||
func fetchCourses(with ids: [Int]) -> Promise<[Course]> | ||
/// Method is used to obtain Course objects from cache with ids | ||
/// | ||
/// - Parameter ids: Ids Course objects | ||
/// - Returns: Promise with a result of an array of Course objects from cache. | ||
func obtainCourses(with ids: [Int]) -> Promise<[Course]> | ||
} |
28 changes: 28 additions & 0 deletions
28
ExamEGERussian/Sources/BusinessLogicLayer/Services/CourseService/CourseServiceImpl.swift
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,28 @@ | ||
// | ||
// CourseServiceImpl.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 26/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import PromiseKit | ||
|
||
final class CourseServiceImpl: CourseService { | ||
private let coursesAPI: CoursesAPI | ||
|
||
init(coursesAPI: CoursesAPI) { | ||
self.coursesAPI = coursesAPI | ||
} | ||
|
||
func fetchCourses(with ids: [Int]) -> Promise<[Course]> { | ||
return obtainCourses(with: ids).then { courses in | ||
self.coursesAPI.retrieve(ids: ids, existing: courses) | ||
} | ||
} | ||
|
||
func obtainCourses(with ids: [Int]) -> Promise<[Course]> { | ||
return Course.fetchAsync(ids) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
ExamEGERussian/Sources/BusinessLogicLayer/Services/EnrollmentService/EnrollmentService.swift
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,18 @@ | ||
// | ||
// EnrollmentService.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 26/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import PromiseKit | ||
|
||
protocol EnrollmentService: class { | ||
/// Method is used to joining Course object with specified id. | ||
/// | ||
/// - Parameter course: Course to join. | ||
/// - Returns: Promise when fullfilled. | ||
func joinCourse(_ course: Course) -> Promise<Course> | ||
} |
24 changes: 24 additions & 0 deletions
24
...Russian/Sources/BusinessLogicLayer/Services/EnrollmentService/EnrollmentServiceImpl.swift
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,24 @@ | ||
// | ||
// EnrollmentServiceImpl.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 26/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import PromiseKit | ||
|
||
final class EnrollmentServiceImpl: EnrollmentService { | ||
private let enrollmentsAPI: EnrollmentsAPI | ||
|
||
init(enrollmentsAPI: EnrollmentsAPI) { | ||
self.enrollmentsAPI = enrollmentsAPI | ||
} | ||
|
||
func joinCourse(_ course: Course) -> Promise<Course> { | ||
return enrollmentsAPI.joinCourse(course).then { _ -> Promise<Course> in | ||
.value(course) | ||
} | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
ExamEGERussian/Sources/BusinessLogicLayer/Services/LessonsService/LessonsService.swift
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,23 @@ | ||
// | ||
// LessonsService.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 24/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import PromiseKit | ||
|
||
protocol LessonsService: class { | ||
/// Method is used to fetch lessons from Stepik API. | ||
/// | ||
/// - Parameter ids: Lessons ids. | ||
/// - Returns: Promise with an array of LessonPlainObjects. | ||
func fetchLessons(with ids: [Int]) -> Promise<[LessonPlainObject]> | ||
/// Method is used to obtain lessons from cache. | ||
/// | ||
/// - Parameter ids: Lessons ids. | ||
/// - Returns: Promise with an array of cached LessonPlainObjects. | ||
func obtainLessons(with ids: [Int]) -> Promise<[LessonPlainObject]> | ||
} |
56 changes: 56 additions & 0 deletions
56
ExamEGERussian/Sources/BusinessLogicLayer/Services/LessonsService/LessonsServiceImpl.swift
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,56 @@ | ||
// | ||
// LessonsServiceImpl.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 24/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import CoreData | ||
import PromiseKit | ||
|
||
final class LessonsServiceImpl: LessonsService { | ||
private let lessonsAPI: LessonsAPI | ||
|
||
init(lessonsAPI: LessonsAPI) { | ||
self.lessonsAPI = lessonsAPI | ||
} | ||
|
||
func fetchLessons(with ids: [Int]) -> Promise<[LessonPlainObject]> { | ||
return executeFetchRequest(ids: ids) | ||
.then { self.lessonsAPI.retrieve(ids: ids, existing: $0) } | ||
.mapValues { self.toPlainObject($0) } | ||
} | ||
|
||
func obtainLessons(with ids: [Int]) -> Promise<[LessonPlainObject]> { | ||
return executeFetchRequest(ids: ids).mapValues { self.toPlainObject($0) } | ||
} | ||
|
||
// MARK: - Private API | ||
|
||
private func executeFetchRequest(ids: [Int]) -> Promise<[Lesson]> { | ||
let request = NSFetchRequest<NSFetchRequestResult>(entityName: String(describing: Lesson.self)) | ||
let descriptor = NSSortDescriptor(key: "managedId", ascending: true) | ||
|
||
let idPredicates = ids.map { NSPredicate(format: "managedId == %@", $0 as NSNumber) } | ||
let predicate = NSCompoundPredicate(type: NSCompoundPredicate.LogicalType.or, subpredicates: idPredicates) | ||
request.predicate = predicate | ||
request.sortDescriptors = [descriptor] | ||
|
||
return Promise<[Lesson]> { seal in | ||
let asyncRequest = NSAsynchronousFetchRequest(fetchRequest: request, completionBlock: { results in | ||
guard let lessons = results.finalResult as? [Lesson] else { | ||
seal.fulfill([]) | ||
return | ||
} | ||
seal.fulfill(lessons) | ||
}) | ||
_ = try? CoreDataHelper.instance.context.execute(asyncRequest) | ||
} | ||
} | ||
|
||
private func toPlainObject(_ lesson: Lesson) -> LessonPlainObject { | ||
return LessonPlainObject(id: lesson.id, steps: lesson.steps.map { $0.id }, title: lesson.title) | ||
} | ||
} |
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
Oops, something went wrong.