Skip to content

Commit 9978a1f

Browse files
Merge pull request #53 from raccoongang/develop
Develop to main. Release v1.2.2
2 parents c924735 + 79f4f38 commit 9978a1f

File tree

47 files changed

+3872
-539
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3872
-539
lines changed

Authorization/AuthorizationTests/AuthorizationMock.generated.swift

Lines changed: 397 additions & 0 deletions
Large diffs are not rendered by default.

Core/Core/Data/Persistence/CoreDataModel.xcdatamodeld/CoreDataModel.xcdatamodel/contents

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21513" systemVersion="21G115" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
2+
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21754" systemVersion="22F82" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
33
<entity name="CDDownloadData" representedClassName="CDDownloadData" syncable="YES" codeGenerationType="class">
4+
<attribute name="courseId" optional="YES" attributeType="String"/>
45
<attribute name="fileName" optional="YES" attributeType="String"/>
56
<attribute name="id" optional="YES" attributeType="String"/>
67
<attribute name="progress" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>

Core/Core/Data/Persistence/CorePersistence.swift

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import Combine
1111
public protocol CorePersistenceProtocol {
1212
func publisher() -> AnyPublisher<Int, Never>
1313
func addToDownloadQueue(blocks: [CourseBlock])
14-
func getBlocksForDownloading() -> [DownloadData]
15-
func getAllDownloads() -> [DownloadData]
14+
func getNextBlockForDownloading() -> DownloadData?
15+
func getDownloadsForCourse(_ courseId: String) -> [DownloadData]
1616
func downloadData(by blockId: String) -> DownloadData?
1717
func updateDownloadState(id: String, state: DownloadState, resumeData: Data?)
1818
func deleteDownloadData(id: String) throws
@@ -67,6 +67,7 @@ public class CorePersistence: CorePersistenceProtocol {
6767
let newDownloadData = CDDownloadData(context: context)
6868
context.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump
6969
newDownloadData.id = block.id
70+
newDownloadData.courseId = block.courseId
7071
newDownloadData.url = url
7172
newDownloadData.fileName = fileName
7273
newDownloadData.progress = .zero
@@ -77,47 +78,55 @@ public class CorePersistence: CorePersistenceProtocol {
7778
}
7879
}
7980

80-
public func getBlocksForDownloading() -> [DownloadData] {
81+
public func getNextBlockForDownloading() -> DownloadData? {
8182
let request = CDDownloadData.fetchRequest()
8283
request.predicate = NSPredicate(format: "state != %@", DownloadState.finished.rawValue)
83-
guard let downloadData = try? context.fetch(request) else { return [] }
84-
return downloadData.map {
85-
DownloadData(id: $0.id ?? "",
86-
url: $0.url ?? "",
87-
fileName: $0.fileName ?? "",
88-
progress: $0.progress,
89-
resumeData: $0.resumeData,
90-
state: DownloadState(rawValue: $0.state ?? "") ?? .waiting,
91-
type: DownloadType(rawValue: $0.type ?? "") ?? .video)
92-
}
84+
request.fetchLimit = 1
85+
guard let data = try? context.fetch(request).first else { return nil }
86+
return DownloadData(
87+
id: data.id ?? "",
88+
courseId: data.courseId ?? "",
89+
url: data.url ?? "",
90+
fileName: data.fileName ?? "",
91+
progress: data.progress,
92+
resumeData: data.resumeData,
93+
state: DownloadState(rawValue: data.state ?? "") ?? .waiting,
94+
type: DownloadType(rawValue: data.type ?? "" ) ?? .video
95+
)
9396
}
9497

95-
public func getAllDownloads() -> [DownloadData] {
98+
public func getDownloadsForCourse(_ courseId: String) -> [DownloadData] {
9699
let request = CDDownloadData.fetchRequest()
100+
request.predicate = NSPredicate(format: "courseId = %@", courseId)
97101
guard let downloadData = try? context.fetch(request) else { return [] }
98102
return downloadData.map {
99-
DownloadData(id: $0.id ?? "",
100-
url: $0.url ?? "",
101-
fileName: $0.fileName ?? "",
102-
progress: $0.progress,
103-
resumeData: $0.resumeData,
104-
state: DownloadState(rawValue: $0.state ?? "") ?? .waiting,
105-
type: DownloadType(rawValue: $0.type ?? "") ?? .video)
103+
DownloadData(
104+
id: $0.id ?? "",
105+
courseId: $0.courseId ?? "",
106+
url: $0.url ?? "",
107+
fileName: $0.fileName ?? "",
108+
progress: $0.progress,
109+
resumeData: $0.resumeData,
110+
state: DownloadState(rawValue: $0.state ?? "") ?? .waiting,
111+
type: DownloadType(rawValue: $0.type ?? "") ?? .video
112+
)
106113
}
107114
}
108115

109116
public func downloadData(by blockId: String) -> DownloadData? {
110117
let request = CDDownloadData.fetchRequest()
111118
request.predicate = NSPredicate(format: "id = %@", blockId)
112119
guard let downloadData = try? context.fetch(request).first else { return nil }
113-
return DownloadData(id: downloadData.id ?? "",
114-
url: downloadData.url ?? "",
115-
fileName: downloadData.fileName ?? "",
116-
progress: downloadData.progress,
117-
resumeData: downloadData.resumeData,
118-
state: DownloadState(rawValue: downloadData.state ?? "") ?? .paused,
119-
type: DownloadType(rawValue: downloadData.type ?? "" ) ?? .video)
120-
120+
return DownloadData(
121+
id: downloadData.id ?? "",
122+
courseId: downloadData.courseId ?? "",
123+
url: downloadData.url ?? "",
124+
fileName: downloadData.fileName ?? "",
125+
progress: downloadData.progress,
126+
resumeData: downloadData.resumeData,
127+
state: DownloadState(rawValue: downloadData.state ?? "") ?? .paused,
128+
type: DownloadType(rawValue: downloadData.type ?? "" ) ?? .video
129+
)
121130
}
122131

123132
public func updateDownloadState(id: String, state: DownloadState, resumeData: Data?) {
@@ -155,6 +164,7 @@ public class CorePersistence: CorePersistenceProtocol {
155164
let newDownloadData = CDDownloadData(context: context)
156165
context.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump
157166
newDownloadData.id = data.id
167+
newDownloadData.courseId = data.courseId
158168
newDownloadData.url = data.url
159169
newDownloadData.progress = data.progress
160170
newDownloadData.fileName = data.fileName

Core/Core/Domain/Model/CourseBlockModel.swift

Lines changed: 72 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import Foundation
99

1010
public struct CourseStructure: Equatable {
11-
12-
public let courseID: String
1311
public let id: String
1412
public let graded: Bool
1513
public let completion: Double
@@ -18,21 +16,21 @@ public struct CourseStructure: Equatable {
1816
public let displayName: String
1917
public let topicID: String?
2018
public let childs: [CourseChapter]
21-
public let media: DataLayer.CourseMedia
19+
public let media: DataLayer.CourseMedia //FIXME Domain model
2220
public let certificate: Certificate?
2321

24-
public init(courseID: String,
25-
id: String,
26-
graded: Bool,
27-
completion: Double,
28-
viewYouTubeUrl: String,
29-
encodedVideo: String,
30-
displayName: String,
31-
topicID: String? = nil,
32-
childs: [CourseChapter],
33-
media: DataLayer.CourseMedia,
34-
certificate: Certificate?) {
35-
self.courseID = courseID
22+
public init(
23+
id: String,
24+
graded: Bool,
25+
completion: Double,
26+
viewYouTubeUrl: String,
27+
encodedVideo: String,
28+
displayName: String,
29+
topicID: String? = nil,
30+
childs: [CourseChapter],
31+
media: DataLayer.CourseMedia,
32+
certificate: Certificate?
33+
) {
3634
self.id = id
3735
self.graded = graded
3836
self.completion = completion
@@ -52,39 +50,29 @@ public struct CourseStructure: Equatable {
5250
}
5351

5452
public struct CourseChapter {
55-
public init(blockId: String,
56-
id: String,
57-
displayName: String,
58-
type: BlockType,
59-
childs: [CourseSequential]) {
60-
self.blockId = blockId
61-
self.id = id
62-
self.displayName = displayName
63-
self.type = type
64-
self.childs = childs
65-
}
6653

6754
public let blockId: String
6855
public let id: String
6956
public let displayName: String
7057
public let type: BlockType
7158
public let childs: [CourseSequential]
72-
}
73-
74-
public struct CourseSequential {
75-
public init(blockId: String,
76-
id: String,
77-
displayName: String,
78-
type: BlockType,
79-
completion: Double,
80-
childs: [CourseVertical]) {
59+
60+
public init(
61+
blockId: String,
62+
id: String,
63+
displayName: String,
64+
type: BlockType,
65+
childs: [CourseSequential]
66+
) {
8167
self.blockId = blockId
8268
self.id = id
8369
self.displayName = displayName
8470
self.type = type
85-
self.completion = completion
8671
self.childs = childs
8772
}
73+
}
74+
75+
public struct CourseSequential {
8876

8977
public let blockId: String
9078
public let id: String
@@ -96,25 +84,28 @@ public struct CourseSequential {
9684
public var isDownloadable: Bool {
9785
return childs.first(where: { $0.isDownloadable }) != nil
9886
}
99-
}
100-
101-
public struct CourseVertical {
102-
public init(blockId: String,
103-
id: String,
104-
displayName: String,
105-
type: BlockType,
106-
completion: Double,
107-
childs: [CourseBlock]) {
87+
88+
public init(
89+
blockId: String,
90+
id: String,
91+
displayName: String,
92+
type: BlockType,
93+
completion: Double,
94+
childs: [CourseVertical]
95+
) {
10896
self.blockId = blockId
10997
self.id = id
11098
self.displayName = displayName
11199
self.type = type
112100
self.completion = completion
113101
self.childs = childs
114102
}
115-
103+
}
104+
105+
public struct CourseVertical {
116106
public let blockId: String
117107
public let id: String
108+
public let courseId: String
118109
public let displayName: String
119110
public let type: BlockType
120111
public let completion: Double
@@ -123,6 +114,24 @@ public struct CourseVertical {
123114
public var isDownloadable: Bool {
124115
return childs.first(where: { $0.isDownloadable }) != nil
125116
}
117+
118+
public init(
119+
blockId: String,
120+
id: String,
121+
courseId: String,
122+
displayName: String,
123+
type: BlockType,
124+
completion: Double,
125+
childs: [CourseBlock]
126+
) {
127+
self.blockId = blockId
128+
self.id = id
129+
self.courseId = courseId
130+
self.displayName = displayName
131+
self.type = type
132+
self.completion = completion
133+
self.childs = childs
134+
}
126135
}
127136

128137
public struct SubtitleUrl: Equatable {
@@ -138,6 +147,7 @@ public struct SubtitleUrl: Equatable {
138147
public struct CourseBlock: Equatable {
139148
public let blockId: String
140149
public let id: String
150+
public let courseId: String
141151
public let topicId: String?
142152
public let graded: Bool
143153
public let completion: Double
@@ -147,23 +157,28 @@ public struct CourseBlock: Equatable {
147157
public let subtitles: [SubtitleUrl]?
148158
public let videoUrl: String?
149159
public let youTubeUrl: String?
160+
150161
public var isDownloadable: Bool {
151162
return videoUrl != nil
152163
}
153164

154-
public init(blockId: String,
155-
id: String,
156-
topicId: String? = nil,
157-
graded: Bool,
158-
completion: Double,
159-
type: BlockType,
160-
displayName: String,
161-
studentUrl: String,
162-
subtitles: [SubtitleUrl]? = nil,
163-
videoUrl: String? = nil,
164-
youTubeUrl: String? = nil) {
165+
public init(
166+
blockId: String,
167+
id: String,
168+
courseId: String,
169+
topicId: String? = nil,
170+
graded: Bool,
171+
completion: Double,
172+
type: BlockType,
173+
displayName: String,
174+
studentUrl: String,
175+
subtitles: [SubtitleUrl]? = nil,
176+
videoUrl: String? = nil,
177+
youTubeUrl: String? = nil
178+
) {
165179
self.blockId = blockId
166180
self.id = id
181+
self.courseId = courseId
167182
self.topicId = topicId
168183
self.graded = graded
169184
self.completion = completion

0 commit comments

Comments
 (0)