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

T160 update pagination params #36

Merged
merged 2 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion OmiseGOTests/FixtureTests/TransactionFixtureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class TransactionFixtureTests: FixtureTestCase {
let paginationParams = PaginationParams<Transaction>(page: 1,
perPage: 10,
searchTerm: nil,
searchTerms: nil,
sortBy: .to,
sortDirection: .ascending)
let params = TransactionListParams(paginationParams: paginationParams, address: nil)
Expand Down
1 change: 0 additions & 1 deletion OmiseGOTests/LiveTests/TransactionLiveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class TransactionLiveTests: LiveTestCase {
page: 1,
perPage: 10,
searchTerm: nil,
searchTerms: nil,
sortBy: .createdAt,
sortDirection: .descending)
let params = TransactionListParams(paginationParams: paginationParams, address: nil)
Expand Down
37 changes: 30 additions & 7 deletions Source/Models/PaginationParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,50 @@ public struct PaginationParams<T: Paginable> {
/// The sort direction (ascending or descending)
public let sortDirection: SortDirection

init(page: Int,
perPage: Int,
searchTerm: String?,
searchTerms: [T.SearchableFields: Any]?,
sortBy: T.SortableFields,
sortDirection: SortDirection) {
self.page = page
self.perPage = perPage
self.searchTerm = searchTerm
self.searchTerms = searchTerms
self.sortBy = sortBy
self.sortDirection = sortDirection
}

/// Initialize the params used to query a paginated collection
///
/// - Parameters:
/// - page: The page requested (0 and 1 are the same)
/// - perPage: The number of result expected per page
/// - searchTerm: The global search term used to search in any of the SearchableFields
/// - searchTerms: A dictionary where each key is a Searchable field that and each value is a search term
/// - sortBy: The field to sort by
/// - sortDirection: The sort direction (ascending or descending)
public init(page: Int,
perPage: Int,
searchTerm: String?,
sortBy: T.SortableFields,
sortDirection: SortDirection) {
self.init(page: page, perPage: perPage, searchTerm: searchTerm, searchTerms: nil, sortBy: sortBy, sortDirection: sortDirection)
}

/// Initialize the params used to query a paginated collection
///
/// - Parameters:
/// - page: The page requested (0 and 1 are the same)
/// - perPage: The number of result expected per page
/// - searchTerms: A dictionary where each key is a Searchable field that and each value is a search term
/// - sortBy: The field to sort by
/// - sortDirection: The sort direction (ascending or descending)
public init(page: Int,
perPage: Int,
searchTerms: [T.SearchableFields: Any]?,
sortBy: T.SortableFields,
sortDirection: SortDirection) {
self.page = page
self.perPage = perPage
self.searchTerm = searchTerm
self.searchTerms = searchTerms
self.sortBy = sortBy
self.sortDirection = sortDirection
self.init(page: page, perPage: perPage, searchTerm: nil, searchTerms: searchTerms, sortBy: sortBy, sortDirection: sortDirection)
}

}
Expand Down
8 changes: 6 additions & 2 deletions Source/Websocket/SocketEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ enum SocketEventSend: String, Encodable {
case heartbeat = "heartbeat"
case join = "phx_join"
case leave = "phx_leave"
case error = "phx_error"
case close = "phx_close"
}

public enum SocketEvent: Decodable {
case reply
case error
case close
case transactionConsumptionRequest
case transactionConsumptionFinalized
case other(event: String)
Expand All @@ -37,6 +37,8 @@ extension SocketEvent: RawRepresentable {

public init?(rawValue: String) {
switch rawValue {
case "phx_error": self = .error
case "phx_close": self = .close
case "phx_reply": self = .reply
case "transaction_consumption_request": self = .transactionConsumptionRequest
case "transaction_consumption_finalized": self = .transactionConsumptionFinalized
Expand All @@ -46,6 +48,8 @@ extension SocketEvent: RawRepresentable {

public var rawValue: String {
switch self {
case .error: return "phx_error"
case .close: return "phx_close"
case .reply: return "phx_reply"
case .transactionConsumptionRequest: return "transaction_consumption_request"
case .transactionConsumptionFinalized: return "transaction_consumption_finalized"
Expand Down