Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor collection listing and add get wallets for user
- Loading branch information
mederic
committed
Sep 17, 2018
1 parent
2c5d966
commit 917dbec
Showing
26 changed files
with
638 additions
and
189 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// WalletGetForUserParams.swift | ||
// OmiseGO | ||
// | ||
// Created by Mederic Petit on 17/9/18. | ||
// Copyright © 2017-2018 Omise Go Pte. Ltd. All rights reserved. | ||
// | ||
|
||
/// Represents a structure used to retrieve wallets for a specific user | ||
public struct WalletListForUserParams { | ||
public let paginatedListParams: PaginatedListParams<Wallet> | ||
public let userId: String? | ||
public let providerUserId: String? | ||
|
||
/// Initialize the params used to query a paginated list of wallets belonging to a user from its userId | ||
/// | ||
/// - Parameters: | ||
/// - paginatedListParams: The params to use for the pagination | ||
/// - userId: The id of the user | ||
public init(paginatedListParams: PaginatedListParams<Wallet>, | ||
userId: String) { | ||
self.paginatedListParams = paginatedListParams | ||
self.userId = userId | ||
self.providerUserId = nil | ||
} | ||
|
||
/// Initialize the params used to query a paginated list of wallets belonging to a user from its providerUserId | ||
/// | ||
/// - Parameters: | ||
/// - paginatedListParams: The params to use for the pagination | ||
/// - providerUserId: The id of the user | ||
public init(paginatedListParams: PaginatedListParams<Wallet>, | ||
providerUserId: String) { | ||
self.paginatedListParams = paginatedListParams | ||
self.providerUserId = providerUserId | ||
self.userId = nil | ||
} | ||
} | ||
|
||
extension WalletListForUserParams: APIParameters { | ||
private enum CodingKeys: String, CodingKey { | ||
case paginatedListParams | ||
case userId = "id" | ||
case providerUserId = "provider_user_id" | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try paginatedListParams.encode(to: encoder) | ||
try container.encodeIfPresent(userId, forKey: .userId) | ||
try container.encodeIfPresent(providerUserId, forKey: .providerUserId) | ||
} | ||
} |
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
75 changes: 75 additions & 0 deletions
75
Source/Core/Models/CollectionParams/PaginatedListParams.swift
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,75 @@ | ||
// | ||
// PaginatedListParams.swift | ||
// OmiseGO | ||
// | ||
// Created by Mederic Petit on 17/9/18. | ||
// Copyright © 2017-2018 Omise Go Pte. Ltd. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
public struct PaginatedListParams<T: PaginatedListable> { | ||
let sortParams: SortParams<T> | ||
let searchParams: SearchParams<T>? | ||
let paginationParams: PaginationParams | ||
|
||
/// 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 | ||
/// - sortBy: The field to sort by | ||
/// - sortDirection: The sort direction (ascending or descending) | ||
public init(page: Int, | ||
perPage: Int, | ||
sortBy: T.SortableFields, | ||
sortDirection: SortDirection) { | ||
self.sortParams = SortParams<T>(sortBy: sortBy, sortDirection: sortDirection) | ||
self.paginationParams = PaginationParams(page: page, perPage: perPage) | ||
self.searchParams = nil | ||
} | ||
|
||
/// 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 | ||
/// - 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.sortParams = SortParams<T>(sortBy: sortBy, sortDirection: sortDirection) | ||
self.searchParams = SearchParams<T>(searchTerm: searchTerm) | ||
self.paginationParams = PaginationParams(page: page, perPage: perPage) | ||
} | ||
|
||
/// 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.sortParams = SortParams<T>(sortBy: sortBy, sortDirection: sortDirection) | ||
self.searchParams = SearchParams<T>(searchTerms: searchTerms) | ||
self.paginationParams = PaginationParams(page: page, perPage: perPage) | ||
} | ||
} | ||
|
||
extension PaginatedListParams: APIParameters { | ||
public func encode(to encoder: Encoder) throws { | ||
try self.sortParams.encode(to: encoder) | ||
try self.searchParams?.encode(to: encoder) | ||
try self.paginationParams.encode(to: encoder) | ||
} | ||
} |
Oops, something went wrong.