Skip to content

Commit

Permalink
Merge pull request #53 from raccoongang/develop
Browse files Browse the repository at this point in the history
Develop to main. Release v1.2.2
  • Loading branch information
volodymyr-chekyrta authored Jul 17, 2023
2 parents c924735 + 79f4f38 commit 9978a1f
Show file tree
Hide file tree
Showing 47 changed files with 3,872 additions and 539 deletions.
397 changes: 397 additions & 0 deletions Authorization/AuthorizationTests/AuthorizationMock.generated.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21513" systemVersion="21G115" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21754" systemVersion="22F82" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="CDDownloadData" representedClassName="CDDownloadData" syncable="YES" codeGenerationType="class">
<attribute name="courseId" optional="YES" attributeType="String"/>
<attribute name="fileName" optional="YES" attributeType="String"/>
<attribute name="id" optional="YES" attributeType="String"/>
<attribute name="progress" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
Expand Down
68 changes: 39 additions & 29 deletions Core/Core/Data/Persistence/CorePersistence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import Combine
public protocol CorePersistenceProtocol {
func publisher() -> AnyPublisher<Int, Never>
func addToDownloadQueue(blocks: [CourseBlock])
func getBlocksForDownloading() -> [DownloadData]
func getAllDownloads() -> [DownloadData]
func getNextBlockForDownloading() -> DownloadData?
func getDownloadsForCourse(_ courseId: String) -> [DownloadData]
func downloadData(by blockId: String) -> DownloadData?
func updateDownloadState(id: String, state: DownloadState, resumeData: Data?)
func deleteDownloadData(id: String) throws
Expand Down Expand Up @@ -67,6 +67,7 @@ public class CorePersistence: CorePersistenceProtocol {
let newDownloadData = CDDownloadData(context: context)
context.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump
newDownloadData.id = block.id
newDownloadData.courseId = block.courseId
newDownloadData.url = url
newDownloadData.fileName = fileName
newDownloadData.progress = .zero
Expand All @@ -77,47 +78,55 @@ public class CorePersistence: CorePersistenceProtocol {
}
}

public func getBlocksForDownloading() -> [DownloadData] {
public func getNextBlockForDownloading() -> DownloadData? {
let request = CDDownloadData.fetchRequest()
request.predicate = NSPredicate(format: "state != %@", DownloadState.finished.rawValue)
guard let downloadData = try? context.fetch(request) else { return [] }
return downloadData.map {
DownloadData(id: $0.id ?? "",
url: $0.url ?? "",
fileName: $0.fileName ?? "",
progress: $0.progress,
resumeData: $0.resumeData,
state: DownloadState(rawValue: $0.state ?? "") ?? .waiting,
type: DownloadType(rawValue: $0.type ?? "") ?? .video)
}
request.fetchLimit = 1
guard let data = try? context.fetch(request).first else { return nil }
return DownloadData(
id: data.id ?? "",
courseId: data.courseId ?? "",
url: data.url ?? "",
fileName: data.fileName ?? "",
progress: data.progress,
resumeData: data.resumeData,
state: DownloadState(rawValue: data.state ?? "") ?? .waiting,
type: DownloadType(rawValue: data.type ?? "" ) ?? .video
)
}

public func getAllDownloads() -> [DownloadData] {
public func getDownloadsForCourse(_ courseId: String) -> [DownloadData] {
let request = CDDownloadData.fetchRequest()
request.predicate = NSPredicate(format: "courseId = %@", courseId)
guard let downloadData = try? context.fetch(request) else { return [] }
return downloadData.map {
DownloadData(id: $0.id ?? "",
url: $0.url ?? "",
fileName: $0.fileName ?? "",
progress: $0.progress,
resumeData: $0.resumeData,
state: DownloadState(rawValue: $0.state ?? "") ?? .waiting,
type: DownloadType(rawValue: $0.type ?? "") ?? .video)
DownloadData(
id: $0.id ?? "",
courseId: $0.courseId ?? "",
url: $0.url ?? "",
fileName: $0.fileName ?? "",
progress: $0.progress,
resumeData: $0.resumeData,
state: DownloadState(rawValue: $0.state ?? "") ?? .waiting,
type: DownloadType(rawValue: $0.type ?? "") ?? .video
)
}
}

public func downloadData(by blockId: String) -> DownloadData? {
let request = CDDownloadData.fetchRequest()
request.predicate = NSPredicate(format: "id = %@", blockId)
guard let downloadData = try? context.fetch(request).first else { return nil }
return DownloadData(id: downloadData.id ?? "",
url: downloadData.url ?? "",
fileName: downloadData.fileName ?? "",
progress: downloadData.progress,
resumeData: downloadData.resumeData,
state: DownloadState(rawValue: downloadData.state ?? "") ?? .paused,
type: DownloadType(rawValue: downloadData.type ?? "" ) ?? .video)

return DownloadData(
id: downloadData.id ?? "",
courseId: downloadData.courseId ?? "",
url: downloadData.url ?? "",
fileName: downloadData.fileName ?? "",
progress: downloadData.progress,
resumeData: downloadData.resumeData,
state: DownloadState(rawValue: downloadData.state ?? "") ?? .paused,
type: DownloadType(rawValue: downloadData.type ?? "" ) ?? .video
)
}

public func updateDownloadState(id: String, state: DownloadState, resumeData: Data?) {
Expand Down Expand Up @@ -155,6 +164,7 @@ public class CorePersistence: CorePersistenceProtocol {
let newDownloadData = CDDownloadData(context: context)
context.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump
newDownloadData.id = data.id
newDownloadData.courseId = data.courseId
newDownloadData.url = data.url
newDownloadData.progress = data.progress
newDownloadData.fileName = data.fileName
Expand Down
129 changes: 72 additions & 57 deletions Core/Core/Domain/Model/CourseBlockModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import Foundation

public struct CourseStructure: Equatable {

public let courseID: String
public let id: String
public let graded: Bool
public let completion: Double
Expand All @@ -18,21 +16,21 @@ public struct CourseStructure: Equatable {
public let displayName: String
public let topicID: String?
public let childs: [CourseChapter]
public let media: DataLayer.CourseMedia
public let media: DataLayer.CourseMedia //FIXME Domain model
public let certificate: Certificate?

public init(courseID: String,
id: String,
graded: Bool,
completion: Double,
viewYouTubeUrl: String,
encodedVideo: String,
displayName: String,
topicID: String? = nil,
childs: [CourseChapter],
media: DataLayer.CourseMedia,
certificate: Certificate?) {
self.courseID = courseID
public init(
id: String,
graded: Bool,
completion: Double,
viewYouTubeUrl: String,
encodedVideo: String,
displayName: String,
topicID: String? = nil,
childs: [CourseChapter],
media: DataLayer.CourseMedia,
certificate: Certificate?
) {
self.id = id
self.graded = graded
self.completion = completion
Expand All @@ -52,39 +50,29 @@ public struct CourseStructure: Equatable {
}

public struct CourseChapter {
public init(blockId: String,
id: String,
displayName: String,
type: BlockType,
childs: [CourseSequential]) {
self.blockId = blockId
self.id = id
self.displayName = displayName
self.type = type
self.childs = childs
}

public let blockId: String
public let id: String
public let displayName: String
public let type: BlockType
public let childs: [CourseSequential]
}

public struct CourseSequential {
public init(blockId: String,
id: String,
displayName: String,
type: BlockType,
completion: Double,
childs: [CourseVertical]) {

public init(
blockId: String,
id: String,
displayName: String,
type: BlockType,
childs: [CourseSequential]
) {
self.blockId = blockId
self.id = id
self.displayName = displayName
self.type = type
self.completion = completion
self.childs = childs
}
}

public struct CourseSequential {

public let blockId: String
public let id: String
Expand All @@ -96,25 +84,28 @@ public struct CourseSequential {
public var isDownloadable: Bool {
return childs.first(where: { $0.isDownloadable }) != nil
}
}

public struct CourseVertical {
public init(blockId: String,
id: String,
displayName: String,
type: BlockType,
completion: Double,
childs: [CourseBlock]) {
public init(
blockId: String,
id: String,
displayName: String,
type: BlockType,
completion: Double,
childs: [CourseVertical]
) {
self.blockId = blockId
self.id = id
self.displayName = displayName
self.type = type
self.completion = completion
self.childs = childs
}

}

public struct CourseVertical {
public let blockId: String
public let id: String
public let courseId: String
public let displayName: String
public let type: BlockType
public let completion: Double
Expand All @@ -123,6 +114,24 @@ public struct CourseVertical {
public var isDownloadable: Bool {
return childs.first(where: { $0.isDownloadable }) != nil
}

public init(
blockId: String,
id: String,
courseId: String,
displayName: String,
type: BlockType,
completion: Double,
childs: [CourseBlock]
) {
self.blockId = blockId
self.id = id
self.courseId = courseId
self.displayName = displayName
self.type = type
self.completion = completion
self.childs = childs
}
}

public struct SubtitleUrl: Equatable {
Expand All @@ -138,6 +147,7 @@ public struct SubtitleUrl: Equatable {
public struct CourseBlock: Equatable {
public let blockId: String
public let id: String
public let courseId: String
public let topicId: String?
public let graded: Bool
public let completion: Double
Expand All @@ -147,23 +157,28 @@ public struct CourseBlock: Equatable {
public let subtitles: [SubtitleUrl]?
public let videoUrl: String?
public let youTubeUrl: String?

public var isDownloadable: Bool {
return videoUrl != nil
}

public init(blockId: String,
id: String,
topicId: String? = nil,
graded: Bool,
completion: Double,
type: BlockType,
displayName: String,
studentUrl: String,
subtitles: [SubtitleUrl]? = nil,
videoUrl: String? = nil,
youTubeUrl: String? = nil) {
public init(
blockId: String,
id: String,
courseId: String,
topicId: String? = nil,
graded: Bool,
completion: Double,
type: BlockType,
displayName: String,
studentUrl: String,
subtitles: [SubtitleUrl]? = nil,
videoUrl: String? = nil,
youTubeUrl: String? = nil
) {
self.blockId = blockId
self.id = id
self.courseId = courseId
self.topicId = topicId
self.graded = graded
self.completion = completion
Expand Down
Loading

0 comments on commit 9978a1f

Please sign in to comment.