Skip to content

Commit

Permalink
Fix handle do main course action APPS-3609
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-magda committed Mar 10, 2022
1 parent 21baf11 commit 593862c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class PersonalDeadlinesService: PersonalDeadlinesServiceProtocol {
}

func canAddDeadlines(in course: Course) -> Bool {
course.sectionDeadlines == nil && course.scheduleType == "self_paced"
course.sectionDeadlines == nil && course.scheduleType == .selfPaced
}

func hasDeadlines(in course: Course) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ extension Course {
}
}

var scheduleType: String? {
set(value) {
self.managedScheduleType = value
}
var scheduleTypeString: String? {
get {
managedScheduleType
self.managedScheduleType
}
set {
self.managedScheduleType = newValue
}
}

Expand Down
19 changes: 16 additions & 3 deletions Stepic/Legacy/Model/Entities/Course/Course.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import SwiftyJSON
final class Course: NSManagedObject, ManagedObject, IDFetchable {
typealias IdType = Int

var scheduleType: ScheduleType? {
if let scheduleTypeString = self.scheduleTypeString {
return ScheduleType(rawValue: scheduleTypeString)
}
return nil
}

var sectionDeadlines: [SectionDeadline]? {
(PersonalDeadlineLocalStorageManager().getRecord(for: self)?.data as? DeadlineStorageRecordData)?.deadlines
}
Expand Down Expand Up @@ -56,8 +63,8 @@ final class Course: NSManagedObject, ManagedObject, IDFetchable {

var canContinue: Bool {
self.totalUnits > 0
&& self.scheduleType != "upcoming"
&& self.scheduleType != "ended"
&& self.scheduleType != .upcoming
&& self.scheduleType != .ended
&& (self.isEnabled || !self.canEditCourse)
}

Expand Down Expand Up @@ -125,7 +132,7 @@ final class Course: NSManagedObject, ManagedObject, IDFetchable {
self.slug = json[JSONKey.slug.rawValue].string
self.progressID = json[JSONKey.progress.rawValue].string
self.lastStepID = json[JSONKey.lastStep.rawValue].string
self.scheduleType = json[JSONKey.scheduleType.rawValue].string
self.scheduleTypeString = json[JSONKey.scheduleType.rawValue].string
self.learnersCount = json[JSONKey.learnersCount.rawValue].int
self.totalUnits = json[JSONKey.totalUnits.rawValue].intValue
self.reviewSummaryID = json[JSONKey.reviewSummary.rawValue].int
Expand Down Expand Up @@ -199,6 +206,12 @@ final class Course: NSManagedObject, ManagedObject, IDFetchable {

// MARK: Inner Types

enum ScheduleType: String {
case ended
case upcoming
case selfPaced = "self_paced"
}

enum JSONKey: String {
case id
case title
Expand Down
6 changes: 5 additions & 1 deletion Stepic/Sources/Modules/CourseInfo/CourseInfoInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,13 @@ final class CourseInfoInteractor: CourseInfoInteractorProtocol {
)
)
} else {
if course.scheduleType == .ended {
return self.doWishlistMainAction(request: .init())
}

// Paid course -> buy course or wishlist main action
if course.isPaid && !course.isPurchased {
if self.shouldCheckIAPPurchaseSupport && !self.isSupportedIAPPurchase {
if !course.canBeBought || (self.shouldCheckIAPPurchaseSupport && !self.isSupportedIAPPurchase) {
return self.doWishlistMainAction(request: .init())
}

Expand Down
4 changes: 2 additions & 2 deletions Stepic/Sources/Modules/CourseInfo/CourseInfoPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ final class CourseInfoPresenter: CourseInfoPresenterProtocol {
return nil
}

if course.scheduleType == "ended" {
if course.scheduleType == .ended {
if let endDate = course.endDate {
let formattedDate = FormatterHelper.dateStringWithDayMonthAndYear(endDate)
return String(
Expand Down Expand Up @@ -401,7 +401,7 @@ final class CourseInfoPresenter: CourseInfoPresenterProtocol {
return NSLocalizedString("WidgetButtonLearn", comment: "")
}

if course.scheduleType == "ended" {
if course.scheduleType == .ended {
isWishlist = true
return course.isInWishlist
? NSLocalizedString("CourseInfoPurchaseModalWishlistButtonInWishlistTitle", comment: "")
Expand Down

0 comments on commit 593862c

Please sign in to comment.