Skip to content

Commit

Permalink
Merge pull request #819 from StepicOrg/release/1.148
Browse files Browse the repository at this point in the history
Release 1.148
  • Loading branch information
ivan-magda authored Nov 5, 2020
2 parents 76f99b7 + 77ff23f commit cf8c9d4
Show file tree
Hide file tree
Showing 66 changed files with 1,960 additions and 134 deletions.
96 changes: 84 additions & 12 deletions Stepic.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Stepic/Images.xcassets/CourseListFilter/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "course-list-filter-slider.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
4 changes: 2 additions & 2 deletions Stepic/Info-Develop.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.147-develop</string>
<string>1.148-develop</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down Expand Up @@ -62,7 +62,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>257</string>
<string>259</string>
<key>FacebookAppID</key>
<string>171127739724012</string>
<key>FacebookDisplayName</key>
Expand Down
4 changes: 2 additions & 2 deletions Stepic/Info-Production.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.147</string>
<string>1.148</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down Expand Up @@ -62,7 +62,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>257</string>
<string>259</string>
<key>FacebookAppID</key>
<string>171127739724012</string>
<key>FacebookDisplayName</key>
Expand Down
4 changes: 2 additions & 2 deletions Stepic/Info-Release.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.147-release</string>
<string>1.148-release</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down Expand Up @@ -62,7 +62,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>257</string>
<string>259</string>
<key>FacebookAppID</key>
<string>171127739724012</string>
<key>FacebookDisplayName</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ final class SearchResultsPresenter: SearchResultsModuleInputProtocol {
private var resultsVC: UIViewController?

var query: String = ""
private var currentCourseListFilterQuery: CourseListFilterQuery?

init(view: SearchResultsView) {
self.view = view
Expand All @@ -41,13 +42,27 @@ final class SearchResultsPresenter: SearchResultsModuleInputProtocol {
resultsVC = nil
}

func filterQueryChanged(to query: CourseListFilterQuery?) {
if self.currentCourseListFilterQuery == query {
return
}

self.currentCourseListFilterQuery = query

if self.resultsVC != nil {
self.resultsVC = nil
self.search(query: self.query)
}
}

func search(query: String) {
self.query = query
if resultsVC == nil {
let resultsVC = FullscreenCourseListAssembly(
presentationDescription: nil,
courseListType: SearchResultCourseListType(
query: query,
filterQuery: self.currentCourseListFilterQuery,
language: ContentLanguageService().globalContentLanguage
),
courseViewSource: .search(query: query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit

protocol SearchResultsModuleInputProtocol: AnyObject {
func queryChanged(to query: String)
func filterQueryChanged(to query: CourseListFilterQuery?)
func search(query: String)
func searchStarted()
func searchCancelled()
Expand Down
42 changes: 42 additions & 0 deletions Stepic/Legacy/Model/Network/CourseListFilterQuery.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Foundation

struct CourseListFilterQuery: Equatable {
let language: String?
let isPaid: Bool?
let withCertificate: Bool?

var dictValue: JSONDictionary {
var result: JSONDictionary = [:]

if let language = self.language {
result[JSONKey.language.rawValue] = language
}
if let isPaid = self.isPaid {
result[JSONKey.isPaid.rawValue] = isPaid
}
if let withCertificate = self.withCertificate {
result[JSONKey.withCertificate.rawValue] = withCertificate
}

return result
}

enum JSONKey: String {
case language
case isPaid = "is_paid"
case withCertificate = "with_certificate"
}
}

extension CourseListFilterQuery {
init(courseListFilters: [CourseListFilter.Filter]) {
let flattenedDictionaries = courseListFilters.compactMap { $0.dictValue }.flatMap { $0 }
let result = Dictionary(uniqueKeysWithValues: flattenedDictionaries)

self.init(
language: result[JSONKey.language.rawValue] as? String,
isPaid: result[JSONKey.isPaid.rawValue] as? Bool,
withCertificate: result[JSONKey.withCertificate.rawValue] as? Bool
)
}
}
13 changes: 12 additions & 1 deletion Stepic/Legacy/Model/Network/Endpoints/CoursesAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ final class CoursesAPI: APIEndpoint {
isCataloged: Bool? = nil,
order: Order? = nil,
language: String? = nil,
page: Int = 1
page: Int = 1,
courseListFilterQuery: CourseListFilterQuery? = nil
) -> Promise<([Course], Meta)> {
var params = Parameters()

Expand Down Expand Up @@ -104,6 +105,16 @@ final class CoursesAPI: APIEndpoint {
params["teacher"] = teacher
}

if let courseListFilterQuery = courseListFilterQuery {
courseListFilterQuery.dictValue.forEach { key, value in
params[key] = String(describing: value)
}

if courseListFilterQuery.language == nil {
params["language"] = nil
}
}

params["page"] = page

return self.retrieve.requestWithFetching(
Expand Down
13 changes: 13 additions & 0 deletions Stepic/Legacy/Model/Network/Endpoints/SearchResultsAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class SearchResultsAPI: APIEndpoint {
type: String?,
language: ContentLanguage,
page: Int?,
filterQuery: CourseListFilterQuery? = nil,
headers: HTTPHeaders = AuthInfo.shared.initialHTTPHeaders,
success: @escaping ([SearchResult], Meta) -> Void,
error errorHandler: @escaping (Error) -> Void
Expand All @@ -40,6 +41,16 @@ final class SearchResultsAPI: APIEndpoint {
params["type"] = type
}

if let filterQuery = filterQuery {
filterQuery.dictValue.forEach { key, value in
params[key] = String(describing: value)
}

if filterQuery.language == nil {
params["language"] = nil
}
}

return self.manager.request(
"\(StepikApplicationsInfo.apiURL)/search-results",
method: .get,
Expand All @@ -64,6 +75,7 @@ final class SearchResultsAPI: APIEndpoint {
query: String,
language: ContentLanguage,
page: Int,
filterQuery: CourseListFilterQuery? = nil,
headers: HTTPHeaders = AuthInfo.shared.initialHTTPHeaders
) -> Promise<([SearchResult], Meta)> {
Promise<([SearchResult], Meta)> { seal in
Expand All @@ -72,6 +84,7 @@ final class SearchResultsAPI: APIEndpoint {
type: "course",
language: language,
page: page,
filterQuery: filterQuery,
headers: headers,
success: { searchResults, meta in
seal.fulfill((searchResults, meta))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ final class StoryTemplatesAPI: APIEndpoint {
var params: Parameters = [
"page": page,
"language": language.languageString,
"max_version": maxVersion
"max_version": maxVersion,
"platform": "mobile,ios"
]

if let isPublished = isPublished {
Expand Down
Loading

0 comments on commit cf8c9d4

Please sign in to comment.