-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added ability to handle course errors
- Loading branch information
Showing
23 changed files
with
886 additions
and
112 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
26 changes: 26 additions & 0 deletions
26
core/src/main/java/org/openedx/core/data/model/CourseAccessDetails.kt
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,26 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import org.openedx.core.domain.model.CourseAccessDetails | ||
import org.openedx.core.utils.TimeUtils | ||
|
||
data class CourseAccessDetails( | ||
@SerializedName("has_unmet_prerequisites") | ||
val hasUnmetPrerequisites: Boolean, | ||
@SerializedName("is_too_early") | ||
val isTooEarly: Boolean, | ||
@SerializedName("is_staff") | ||
val isStaff: Boolean, | ||
@SerializedName("audit_access_expires") | ||
val auditAccessExpires: String?, | ||
@SerializedName("courseware_access") | ||
val coursewareAccess: CoursewareAccess?, | ||
) { | ||
fun mapToDomain() = CourseAccessDetails( | ||
hasUnmetPrerequisites = hasUnmetPrerequisites, | ||
isTooEarly = isTooEarly, | ||
isStaff = isStaff, | ||
auditAccessExpires = TimeUtils.iso8601ToDate(auditAccessExpires ?: ""), | ||
coursewareAccess = coursewareAccess?.mapToDomain(), | ||
) | ||
} |
36 changes: 36 additions & 0 deletions
36
core/src/main/java/org/openedx/core/data/model/CourseEnrollmentDetails.kt
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,36 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import org.openedx.core.domain.model.CourseEnrollmentDetails | ||
|
||
data class CourseEnrollmentDetails( | ||
@SerializedName("id") | ||
val id: String, | ||
@SerializedName("course_updates") | ||
val courseUpdates: String, | ||
@SerializedName("course_handouts") | ||
val courseHandouts: String, | ||
@SerializedName("discussion_url") | ||
val discussionUrl: String, | ||
@SerializedName("course_access_details") | ||
val courseAccessDetails: CourseAccessDetails, | ||
@SerializedName("certificate") | ||
val certificate: Certificate?, | ||
@SerializedName("enrollment_details") | ||
val enrollmentDetails: EnrollmentDetails, | ||
@SerializedName("course_info_overview") | ||
val courseInfoOverview: CourseInfoOverview, | ||
) { | ||
fun mapToDomain(): CourseEnrollmentDetails { | ||
return CourseEnrollmentDetails( | ||
id = id, | ||
courseUpdates = courseUpdates, | ||
courseHandouts = courseHandouts, | ||
discussionUrl = discussionUrl, | ||
courseAccessDetails = courseAccessDetails.mapToDomain(), | ||
certificate = certificate?.mapToDomain(), | ||
enrollmentDetails = enrollmentDetails.mapToDomain(), | ||
courseInfoOverview = courseInfoOverview.mapToDomain(), | ||
) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
core/src/main/java/org/openedx/core/data/model/CourseInfoOverview.kt
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,47 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import org.openedx.core.domain.model.CourseInfoOverview | ||
import org.openedx.core.utils.TimeUtils | ||
|
||
data class CourseInfoOverview( | ||
@SerializedName("name") | ||
val name: String, | ||
@SerializedName("number") | ||
val number: String, | ||
@SerializedName("org") | ||
val org: String, | ||
@SerializedName("start") | ||
val start: String?, | ||
@SerializedName("start_display") | ||
val startDisplay: String, | ||
@SerializedName("start_type") | ||
val startType: String, | ||
@SerializedName("end") | ||
val end: String?, | ||
@SerializedName("is_self_paced") | ||
val isSelfPaced: Boolean, | ||
@SerializedName("media") | ||
var media: Media?, | ||
@SerializedName("course_sharing_utm_parameters") | ||
val courseSharingUtmParameters: CourseSharingUtmParameters, | ||
@SerializedName("course_about") | ||
val courseAbout: String, | ||
@SerializedName("course_modes") | ||
val courseModes: List<CourseMode>, | ||
) { | ||
fun mapToDomain() = CourseInfoOverview( | ||
name = name, | ||
number = number, | ||
org = org, | ||
start = TimeUtils.iso8601ToDate(start ?: ""), | ||
startDisplay = startDisplay, | ||
startType = startType, | ||
end = TimeUtils.iso8601ToDate(end ?: ""), | ||
isSelfPaced = isSelfPaced, | ||
media = media?.mapToDomain(), | ||
courseSharingUtmParameters = courseSharingUtmParameters.mapToDomain(), | ||
courseAbout = courseAbout, | ||
courseModes = courseModes.map { it.mapToDomain() }, | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
core/src/main/java/org/openedx/core/data/model/CourseMode.kt
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,25 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import org.openedx.core.domain.model.CourseMode as CourseMode | ||
|
||
data class CourseMode( | ||
@SerializedName("slug") | ||
val slug: String, | ||
@SerializedName("sku") | ||
val sku: String?, | ||
@SerializedName("android_sku") | ||
val androidSku: String?, | ||
@SerializedName("ios_sku") | ||
val iosSku: String?, | ||
@SerializedName("min_price") | ||
val minPrice: Int, | ||
) { | ||
fun mapToDomain() = CourseMode( | ||
slug = slug, | ||
sku = sku, | ||
androidSku = androidSku, | ||
iosSku = iosSku, | ||
minPrice = minPrice, | ||
) | ||
} |
23 changes: 23 additions & 0 deletions
23
core/src/main/java/org/openedx/core/data/model/EnrollmentDetails.kt
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 @@ | ||
package org.openedx.core.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import org.openedx.core.domain.model.EnrollmentDetails | ||
import org.openedx.core.utils.TimeUtils | ||
|
||
data class EnrollmentDetails( | ||
@SerializedName("date") | ||
val date: String?, | ||
@SerializedName("mode") | ||
val mode: String, | ||
@SerializedName("is_active") | ||
val isActive: Boolean, | ||
@SerializedName("upgrade_deadline") | ||
val upgradeDeadline: String?, | ||
) { | ||
fun mapToDomain() = EnrollmentDetails( | ||
created = TimeUtils.iso8601ToDate(date ?: ""), | ||
mode = mode, | ||
isActive = isActive, | ||
upgradeDeadline = TimeUtils.iso8601ToDate(upgradeDeadline ?: ""), | ||
) | ||
} |
14 changes: 14 additions & 0 deletions
14
core/src/main/java/org/openedx/core/domain/model/CourseAccessDetails.kt
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,14 @@ | ||
package org.openedx.core.domain.model | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
import java.util.Date | ||
|
||
@Parcelize | ||
data class CourseAccessDetails( | ||
val hasUnmetPrerequisites: Boolean, | ||
val isTooEarly: Boolean, | ||
val isStaff: Boolean, | ||
val auditAccessExpires: Date?, | ||
val coursewareAccess: CoursewareAccess? | ||
) : Parcelable |
30 changes: 30 additions & 0 deletions
30
core/src/main/java/org/openedx/core/domain/model/CourseEnrollmentDetails.kt
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,30 @@ | ||
package org.openedx.core.domain.model | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
import java.util.Date | ||
|
||
@Parcelize | ||
data class CourseEnrollmentDetails( | ||
val id: String, | ||
val courseUpdates: String, | ||
val courseHandouts: String, | ||
val discussionUrl: String, | ||
val courseAccessDetails: CourseAccessDetails, | ||
val certificate: Certificate?, | ||
val enrollmentDetails: EnrollmentDetails, | ||
val courseInfoOverview: CourseInfoOverview, | ||
) : Parcelable { | ||
fun isUpgradable(): Boolean { | ||
val start = courseInfoOverview.start ?: return false | ||
val upgradeDeadline = enrollmentDetails.upgradeDeadline ?: return false | ||
if (enrollmentDetails.mode != "audit") return false | ||
|
||
return start < Date() && getCourseMode() != null && upgradeDeadline > Date() | ||
} | ||
|
||
fun getCourseMode(): CourseMode? { | ||
return courseInfoOverview.courseModes | ||
.firstOrNull { it.slug == "verified" && !it.androidSku.isNullOrEmpty() } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
core/src/main/java/org/openedx/core/domain/model/CourseInfoOverview.kt
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 @@ | ||
package org.openedx.core.domain.model | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
import java.util.Date | ||
|
||
@Parcelize | ||
data class CourseInfoOverview( | ||
val name: String, | ||
val number: String, | ||
val org: String, | ||
val start: Date?, | ||
val startDisplay: String, | ||
val startType: String, | ||
val end: Date?, | ||
val isSelfPaced: Boolean, | ||
var media: Media?, | ||
val courseSharingUtmParameters: CourseSharingUtmParameters, | ||
val courseAbout: String, | ||
val courseModes: List<CourseMode>, | ||
) : Parcelable |
13 changes: 13 additions & 0 deletions
13
core/src/main/java/org/openedx/core/domain/model/CourseMode.kt
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,13 @@ | ||
package org.openedx.core.domain.model | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
data class CourseMode( | ||
val slug: String?, | ||
val sku: String?, | ||
val androidSku: String?, | ||
val iosSku: String?, | ||
val minPrice: Int, | ||
) : Parcelable |
13 changes: 13 additions & 0 deletions
13
core/src/main/java/org/openedx/core/domain/model/EnrollmentDetails.kt
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,13 @@ | ||
package org.openedx.core.domain.model | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
import java.util.Date | ||
|
||
@Parcelize | ||
data class EnrollmentDetails( | ||
val created: Date?, | ||
val mode: String, | ||
val isActive: Boolean, | ||
val upgradeDeadline: Date? | ||
) : Parcelable |
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
Oops, something went wrong.