amiibo-service/Sources/Filters/KeyNameFilter.swift
Javier Cicchelli c4a25afad4 [Setup] Documentation (#10)
This PR contains the work done to address the issue #7, related to documenting the source code that would be used for other developers.

To provide further details about the work done:
- [x] restructured the hierarchy of some models that are related to the `Amiibo` model;
- [x] written documentation for the `AmiiboService` service;
- [x] written documentation for the `AmiiboFilter` and `KeyNameFilter` filters;
- [x] written documentation for the `Amiibo`, `KeyName`, `LastUpdated` and children model;
- [x] written documentation for the `AmiiboClientError` error;
- [x] written documentation for the README file.

Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Reviewed-on: #10
2023-04-23 13:16:22 +00:00

69 lines
2.0 KiB
Swift

/// This filter provides all the possible parameters (and combinations) available at the remote API applies when filtering amiibos series (``AmiiboSeriesFilter``), amiibo types (``AmiiboTypeFilter``), characters (``CharacterFilter``), or game series (``GameSeriesFilter``).
public struct KeyNameFilter {
// MARK: Properties
private let key: String?
private let name: String?
// MARK: Initialisers
/// Initialises this filter.
/// - Parameters:
/// - key: A `key` value to match against.
/// - name: A `name` value to match against.
public init(
key: String? = nil,
name: String? = nil
) {
self.key = key
self.name = name
}
}
// MARK: - Type aliases
/// This filter provides all the possible parameters (and combinations) available at the remote API applies when filtering amiibos series.
public typealias AmiiboSeriesFilter = KeyNameFilter
/// This filter provides all the possible parameters (and combinations) available at the remote API applies when filtering amiibo types.
public typealias AmiiboTypeFilter = KeyNameFilter
/// This filter provides all the possible parameters (and combinations) available at the remote API applies when filtering characters.
public typealias CharacterFilter = KeyNameFilter
/// This filter provides all the possible parameters (and combinations) available at the remote API applies when filtering game series.
public typealias GameSeriesFilter = KeyNameFilter
// MARK: - Filter
extension KeyNameFilter: Filter {
// MARK: Functions
func makeParameters() -> [String : String?] {
var parameters: [String : String?] = [:]
if let key {
parameters[.Key.key] = key
}
if let name {
parameters[.Key.name] = name
}
return parameters
}
}
// MARK: - String+Key
private extension String {
enum Key {
static let key = "key"
static let name = "name"
}
}