Skip to content

Commit

Permalink
Update pagination params (#36)
Browse files Browse the repository at this point in the history
* Update pagination params initializers

* Move socket events to corresponding enum
  • Loading branch information
mederic-p committed Apr 25, 2018
1 parent 3c91a70 commit 4aa45ad
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
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

0 comments on commit 4aa45ad

Please sign in to comment.