Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: api migration #213

Merged
merged 15 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Core/Core.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
027BD3BD2909478B00392132 /* UIView+EnclosingScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027BD3BA2909478B00392132 /* UIView+EnclosingScrollView.swift */; };
027BD3BE2909478B00392132 /* UIResponder+CurrentResponder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027BD3BB2909478B00392132 /* UIResponder+CurrentResponder.swift */; };
027BD3C52909707700392132 /* Shake.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027BD3C42909707700392132 /* Shake.swift */; };
027DB33528D8C8FE002B6862 /* Data_MyCourse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 027DB33428D8C8FE002B6862 /* Data_MyCourse.swift */; };
0282DA7328F98CC9003C3F07 /* WebUnitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0282DA7228F98CC9003C3F07 /* WebUnitView.swift */; };
0283347D28D4D3DE00C828FC /* Data_Discovery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0283347C28D4D3DE00C828FC /* Data_Discovery.swift */; };
0283348028D4DCD200C828FC /* ViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0283347F28D4DCD200C828FC /* ViewExtension.swift */; };
Expand Down Expand Up @@ -118,6 +117,7 @@
0770DE5F28D0B22C006D8A5D /* Strings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0770DE5E28D0B22C006D8A5D /* Strings.swift */; };
0770DE6128D0B2CB006D8A5D /* Assets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0770DE6028D0B2CB006D8A5D /* Assets.swift */; };
07DDFCBD29A780BB00572595 /* UINavigationController+Animation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07DDFCBC29A780BB00572595 /* UINavigationController+Animation.swift */; };
07E0939F2B308D2800F1E4B2 /* Data_Certificate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07E0939E2B308D2800F1E4B2 /* Data_Certificate.swift */; };
BA30427F2B20B320009B64B7 /* SocialAuthError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA30427D2B20B299009B64B7 /* SocialAuthError.swift */; };
BA76135C2B21BC7300B599B7 /* SocialAuthResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA76135B2B21BC7300B599B7 /* SocialAuthResponse.swift */; };
BA8B3A2F2AD546A700D25EF5 /* DebugLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA8B3A2E2AD546A700D25EF5 /* DebugLog.swift */; };
Expand Down Expand Up @@ -217,7 +217,6 @@
027BD3BA2909478B00392132 /* UIView+EnclosingScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+EnclosingScrollView.swift"; sourceTree = "<group>"; };
027BD3BB2909478B00392132 /* UIResponder+CurrentResponder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIResponder+CurrentResponder.swift"; sourceTree = "<group>"; };
027BD3C42909707700392132 /* Shake.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shake.swift; sourceTree = "<group>"; };
027DB33428D8C8FE002B6862 /* Data_MyCourse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data_MyCourse.swift; sourceTree = "<group>"; };
0282DA7228F98CC9003C3F07 /* WebUnitView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebUnitView.swift; sourceTree = "<group>"; };
0283347C28D4D3DE00C828FC /* Data_Discovery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data_Discovery.swift; sourceTree = "<group>"; };
0283347F28D4DCD200C828FC /* ViewExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -283,6 +282,7 @@
0770DE5E28D0B22C006D8A5D /* Strings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Strings.swift; sourceTree = "<group>"; };
0770DE6028D0B2CB006D8A5D /* Assets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Assets.swift; sourceTree = "<group>"; };
07DDFCBC29A780BB00572595 /* UINavigationController+Animation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationController+Animation.swift"; sourceTree = "<group>"; };
07E0939E2B308D2800F1E4B2 /* Data_Certificate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data_Certificate.swift; sourceTree = "<group>"; };
0E13E9173C9C4CFC19F8B6F2 /* Pods-App-Core.debugstage.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.debugstage.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.debugstage.xcconfig"; sourceTree = "<group>"; };
1A154A95AF4EE85A4A1C083B /* Pods-App-Core.releasedev.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.releasedev.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.releasedev.xcconfig"; sourceTree = "<group>"; };
2B7E6FE7843FC4CF2BFA712D /* Pods-App-Core.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.debug.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -491,13 +491,13 @@
0727878428D31657002E9142 /* Data_User.swift */,
0283347C28D4D3DE00C828FC /* Data_Discovery.swift */,
02C917EF29CDA99E00DBB8BD /* Data_Dashboard.swift */,
027DB33428D8C8FE002B6862 /* Data_MyCourse.swift */,
021D924728DC860C00ACC565 /* Data_UserProfile.swift */,
0259104929C4A5B6004B5A55 /* UserSettings.swift */,
070019A428F6F17900D5FC78 /* Data_Media.swift */,
0236961C28F9A2D200EEF206 /* Data_AuthResponse.swift */,
027BD3912907D88F00392132 /* Data_RegistrationFields.swift */,
028F9F36293A44C700DE65D0 /* Data_ResetPassword.swift */,
07E0939E2B308D2800F1E4B2 /* Data_Certificate.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -996,7 +996,6 @@
0233D5712AF13EC800BAC8BD /* SelectMailClientView.swift in Sources */,
BAFB99842B0E282E007D09F9 /* MicrosoftConfig.swift in Sources */,
02B2B594295C5C7A00914876 /* Thread.swift in Sources */,
027DB33528D8C8FE002B6862 /* Data_MyCourse.swift in Sources */,
027BD3BD2909478B00392132 /* UIView+EnclosingScrollView.swift in Sources */,
BA8FA6682AD59A5700EA029A /* SocialAuthButton.swift in Sources */,
02D400612B0678190029D168 /* SKStoreReviewControllerExtension.swift in Sources */,
Expand Down Expand Up @@ -1035,6 +1034,7 @@
027BD3B82909476200392132 /* DismissKeyboardTapViewModifier.swift in Sources */,
024BE3DF29B2615500BCDEE2 /* CGColorExtension.swift in Sources */,
0770DE6128D0B2CB006D8A5D /* Assets.swift in Sources */,
07E0939F2B308D2800F1E4B2 /* Data_Certificate.swift in Sources */,
0727878928D31734002E9142 /* User.swift in Sources */,
02280F5B294B4E6F0032823A /* Connectivity.swift in Sources */,
02066B482906F73400F4307E /* PickerMenu.swift in Sources */,
Expand Down
24 changes: 24 additions & 0 deletions Core/Core/Data/Model/Data_Certificate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Data_Certificate.swift
// Core
//
// Created by Vladimir Chekyrta on 18.12.2023.
//

import Foundation

public extension DataLayer {
struct Certificate: Codable {
public let url: String?

public init(url: String?) {
self.url = url
}
}
}

public extension DataLayer.Certificate {
var domain: Certificate {
return Certificate(url: url ?? "")
}
}
257 changes: 219 additions & 38 deletions Core/Core/Data/Model/Data_Dashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,29 @@
import Foundation

public extension DataLayer {
// MARK: - CourseEnrollments
struct CourseEnrollments: Codable {
public let enrollments: Enrollments

enum CodingKeys: String, CodingKey {
case enrollments
}

public init(enrollments: Enrollments) {
self.enrollments = enrollments
}
}

// MARK: - Enrollments
struct Enrollments: Codable {
public let next: String?
public let previous: String?
public let count: Int
public let numPages: Int
public let currentPage: Int
public let start: Int
public let count: Int?
public let numPages: Int?
public let currentPage: Int?
public let start: Int?
public let results: [Result]

enum CodingKeys: String, CodingKey {
case next = "next"
case previous = "previous"
Expand All @@ -26,14 +40,16 @@ public extension DataLayer {
case start = "start"
case results = "results"
}

public init(next: String?,
previous: String?,
count: Int,
numPages: Int,
currentPage: Int,
start: Int,
results: [Result]) {

public init(
next: String?,
previous: String?,
count: Int?,
numPages: Int?,
currentPage: Int?,
start: Int?,
results: [Result]
) {
self.next = next
self.previous = previous
self.count = count
Expand All @@ -43,57 +59,222 @@ public extension DataLayer {
self.results = results
}
}

// MARK: - Result
struct Result: Codable {
public let auditAccessExpires: String?
public let created: String
public let mode: Mode
public let isActive: Bool
public let course: Course
public let certificate: Certificate
public let course: DashboardCourse
public let courseModes: [CourseMode]

enum CodingKeys: String, CodingKey {
case auditAccessExpires = "audit_access_expires"
case created = "created"
case mode = "mode"
case isActive = "is_active"
case course = "course"
case certificate = "certificate"
case courseModes = "course_modes"
}

public init(auditAccessExpires: String?, created: String,// mode: Mode,
isActive: Bool, course: Course, certificate: Certificate) {

public init(
auditAccessExpires: String?,
created: String,
mode: Mode,
isActive: Bool,
course: DashboardCourse,
courseModes: [CourseMode]
) {
self.auditAccessExpires = auditAccessExpires
self.created = created
self.mode = mode
self.isActive = isActive
self.course = course
self.certificate = certificate
self.courseModes = courseModes
}
}

// MARK: - Course
struct DashboardCourse: Codable {
public let id: String
public let name: String
public let number: String
public let org: String
public let start: String?
public let startDisplay: String
public let startType: StartType
public let end: String?
public let dynamicUpgradeDeadline: String?
public let subscriptionID: String
public let coursewareAccess: CoursewareAccess
public let media: Media
public let courseImage: String
public let courseAbout: String
public let courseSharingUtmParameters: CourseSharingUtmParameters
public let courseUpdates: String
public let courseHandouts: String
public let discussionURL: String
public let videoOutline: String?
public let isSelfPaced: Bool

enum CodingKeys: String, CodingKey {
case id = "id"
volodymyr-chekyrta marked this conversation as resolved.
Show resolved Hide resolved
case name = "name"
case number = "number"
case org = "org"
case start = "start"
case startDisplay = "start_display"
case startType = "start_type"
case end = "end"
case dynamicUpgradeDeadline = "dynamic_upgrade_deadline"
case subscriptionID = "subscription_id"
case coursewareAccess = "courseware_access"
case media = "media"
case courseImage = "course_image"
case courseAbout = "course_about"
case courseSharingUtmParameters = "course_sharing_utm_parameters"
case courseUpdates = "course_updates"
case courseHandouts = "course_handouts"
case discussionURL = "discussion_url"
case videoOutline = "video_outline"
case isSelfPaced = "is_self_paced"
}

public init(
id: String,
name: String,
number: String,
org: String,
start: String?,
startDisplay: String,
startType: StartType,
end: String?,
dynamicUpgradeDeadline: String?,
subscriptionID: String,
coursewareAccess: CoursewareAccess,
media: Media,
courseImage: String,
courseAbout: String,
courseSharingUtmParameters: CourseSharingUtmParameters,
courseUpdates: String,
courseHandouts: String,
discussionURL: String,
videoOutline: String?,
isSelfPaced: Bool
) {
self.id = id
self.name = name
self.number = number
self.org = org
self.start = start
self.startDisplay = startDisplay
self.startType = startType
self.end = end
self.dynamicUpgradeDeadline = dynamicUpgradeDeadline
self.subscriptionID = subscriptionID
self.coursewareAccess = coursewareAccess
self.media = media
self.courseImage = courseImage
self.courseAbout = courseAbout
self.courseSharingUtmParameters = courseSharingUtmParameters
self.courseUpdates = courseUpdates
self.courseHandouts = courseHandouts
self.discussionURL = discussionURL
self.videoOutline = videoOutline
self.isSelfPaced = isSelfPaced
}
}

enum Name: String, Codable {
case courseImage = "Course Image"
}

enum Org: String, Codable {
case organization = "Organization"
case univerity = "Univerity"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[curious] is this a typo that got missed? or is this a known edge case being handled this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, need to check 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact, this enum is not used.
I don't know how it ended up there, but I've removed it from the code.

case university = "University"
}

// MARK: - CourseMode
struct CourseMode: Codable {
public let slug: Mode?
public let sku: Mode?
public let androidSku: Mode?
public let iosSku: Mode?

enum CodingKeys: String, CodingKey {
case slug = "slug"
volodymyr-chekyrta marked this conversation as resolved.
Show resolved Hide resolved
case sku = "sku"
case androidSku = "android_sku"
case iosSku = "ios_sku"
}

public init(slug: Mode?, sku: Mode?, androidSku: Mode?, iosSku: Mode?) {
self.slug = slug
self.sku = sku
self.androidSku = androidSku
self.iosSku = iosSku
}
}

enum Mode: String, Codable {
case audit
case honor
}

// MARK: - CourseSharingUtmParameters
struct CourseSharingUtmParameters: Codable {
public let facebook: String
public let twitter: String
}

// MARK: - CoursewareAccess
struct CoursewareAccess: Codable {
public let hasAccess: Bool
public let errorCode: String?
public let developerMessage: String?
public let userMessage: String?
public let additionalContextUserMessage: String?
public let userFragment: String?

enum CodingKeys: String, CodingKey {
case hasAccess = "has_access"
case errorCode = "error_code"
case developerMessage = "developer_message"
case userMessage = "user_message"
case additionalContextUserMessage = "additional_context_user_message"
case userFragment = "user_fragment"
}
}
}

public extension DataLayer.CourseEnrollments {
func domain(baseURL: String) -> [CourseItem] {

return results.map { course in
let imageURL = baseURL + (course.course.media.courseImage?.url?.addingPercentEncoding(
withAllowedCharacters: .urlQueryAllowed) ?? "")
return enrollments.results.map { result in
let course = result.course

let imageUrl = course.media.courseImage?.url ?? ""
let encodedUrl = imageUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
let fullImageURL = baseURL + encodedUrl

return CourseItem(
name: course.course.name,
org: course.course.org,
name: course.name,
org: course.org,
shortDescription: "",
imageURL: imageURL,
imageURL: fullImageURL,
isActive: true,
courseStart: course.course.start != nil ? Date(iso8601: course.course.start!) : nil,
courseEnd: course.course.end != nil ? Date(iso8601: course.course.end!) : nil,
enrollmentStart: course.course.enrollmentStart != nil
? Date(iso8601: course.course.enrollmentStart!)
courseStart: course.start != nil ? Date(iso8601: course.start!) : nil,
courseEnd: course.end != nil ? Date(iso8601: course.end!) : nil,
enrollmentStart: course.start != nil
? Date(iso8601: course.start!)
: nil,
enrollmentEnd: course.course.enrollmentEnd != nil
? Date(iso8601: course.course.enrollmentEnd!)
enrollmentEnd: course.end != nil
? Date(iso8601: course.end!)
: nil,
courseID: course.course.id,
numPages: numPages,
coursesCount: count
courseID: course.id,
numPages: enrollments.numPages ?? 1,
coursesCount: enrollments.count ?? 0
)
}
}
Expand Down
Loading
Loading