Skip to content

Commit cff33b7

Browse files
committed
Use Types instead of Strings for Task Queries
1 parent cdbe966 commit cff33b7

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

Sources/MeiliSearch/QueryParameters/CancelTasksQuery.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import Foundation
55
*/
66
public class CancelTasksQuery: Queryable {
77
/// List of strings with all the types the response should contain.
8-
public let types: [String]
8+
public let types: [TaskType]
99
/// List of strings with all the statuses the response should contain.
10-
public let statuses: [String]
10+
public let statuses: [Task.Status]
1111
/// Filter tasks response by a particular list of index Uids strings
1212
public let indexUids: [String]
1313
/// Filter tasks based on a list of task's uids.
@@ -22,7 +22,7 @@ public class CancelTasksQuery: Queryable {
2222
public let afterStartedAt: Date?
2323

2424
init(
25-
types: [String]? = nil, statuses: [String]? = nil,
25+
types: [TaskType]? = nil, statuses: [Task.Status]? = nil,
2626
indexUids: [String]? = nil, uids: [Int]? = nil,
2727
beforeEnqueuedAt: Date? = nil, afterEnqueuedAt: Date? = nil,
2828
beforeStartedAt: Date? = nil, afterStartedAt: Date? = nil
@@ -40,8 +40,8 @@ public class CancelTasksQuery: Queryable {
4040
internal func buildQuery() -> [String: Codable?] {
4141
[
4242
"uids": uids.isEmpty ? nil : uids.map(String.init).joined(separator: ","),
43-
"types": types.isEmpty ? nil : types.joined(separator: ","),
44-
"statuses": statuses.isEmpty ? nil : statuses.joined(separator: ","),
43+
"types": types.isEmpty ? nil : types.map({ $0.description }).joined(separator: ","),
44+
"statuses": statuses.isEmpty ? nil : statuses.map({ $0.rawValue }).joined(separator: ","),
4545
"indexUids": indexUids.isEmpty ? nil : indexUids.joined(separator: ","),
4646
"beforeEnqueuedAt": Formatter.formatOptionalDate(date: beforeEnqueuedAt),
4747
"afterEnqueuedAt": Formatter.formatOptionalDate(date: afterEnqueuedAt),

Sources/MeiliSearch/QueryParameters/DeleteTasksQuery.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import Foundation
55
*/
66
public class DeleteTasksQuery: Queryable {
77
/// List of strings with all the types the response should contain.
8-
public let types: [String]
8+
public let types: [TaskType]
99
/// List of strings with all the statuses the response should contain.
10-
public let statuses: [String]
10+
public let statuses: [Task.Status]
1111
/// Filter tasks response by a particular list of index Uids strings
1212
public let indexUids: [String]
1313
/// Filter tasks based on a list of task's uids.
@@ -28,7 +28,7 @@ public class DeleteTasksQuery: Queryable {
2828
public let afterFinishedAt: Date?
2929

3030
init(
31-
statuses: [String]? = nil, types: [String]? = nil,
31+
statuses: [Task.Status]? = nil, types: [TaskType]? = nil,
3232
indexUids: [String]? = nil, uids: [Int]? = nil, canceledBy: [Int]? = nil,
3333
beforeEnqueuedAt: Date? = nil, afterEnqueuedAt: Date? = nil,
3434
beforeStartedAt: Date? = nil, afterStartedAt: Date? = nil,
@@ -50,8 +50,8 @@ public class DeleteTasksQuery: Queryable {
5050
internal func buildQuery() -> [String: Codable?] {
5151
[
5252
"uids": uids.isEmpty ? nil : uids.map(String.init).joined(separator: ","),
53-
"types": types.isEmpty ? nil : types.joined(separator: ","),
54-
"statuses": statuses.isEmpty ? nil : statuses.joined(separator: ","),
53+
"types": types.isEmpty ? nil : types.map({ $0.description }).joined(separator: ","),
54+
"statuses": statuses.isEmpty ? nil : statuses.map({ $0.rawValue }).joined(separator: ","),
5555
"indexUids": indexUids.isEmpty ? nil : indexUids.joined(separator: ","),
5656
"canceledBy": canceledBy.isEmpty ? nil : canceledBy.map(String.init).joined(separator: ","),
5757
"beforeEnqueuedAt": Formatter.formatOptionalDate(date: beforeEnqueuedAt),

Sources/MeiliSearch/QueryParameters/TasksQuery.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public class TasksQuery: Queryable {
1313
/// Integer value used to retrieve the next batch of tasks.
1414
private var next: Int?
1515
/// List of strings with all the types the response should contain.
16-
private var types: [String]
16+
private var types: [TaskType]
1717
/// List of strings with all the statuses the response should contain.
18-
private var statuses: [String]
18+
private var statuses: [Task.Status]
1919
/// Filter tasks response by a particular list of index Uids strings
2020
var indexUids: [String]
2121
/// Filter tasks based on a list of task's uids.
@@ -37,7 +37,7 @@ public class TasksQuery: Queryable {
3737

3838
init(
3939
limit: Int? = nil, from: Int? = nil, next: Int? = nil,
40-
statuses: [String]? = nil, types: [String]? = nil,
40+
statuses: [Task.Status]? = nil, types: [TaskType]? = nil,
4141
indexUids: [String]? = nil, uids: [Int]? = nil, canceledBy: [Int]? = nil,
4242
beforeEnqueuedAt: Date? = nil, afterEnqueuedAt: Date? = nil,
4343
afterFinishedAt: Date? = nil, beforeStartedAt: Date? = nil,
@@ -65,8 +65,8 @@ public class TasksQuery: Queryable {
6565
"from": from,
6666
"next": next,
6767
"uids": uids.isEmpty ? nil : uids.map(String.init).joined(separator: ","),
68-
"types": types.isEmpty ? nil : types.joined(separator: ","),
69-
"statuses": statuses.isEmpty ? nil : statuses.joined(separator: ","),
68+
"types": types.isEmpty ? nil : types.map({ $0.description }).joined(separator: ","),
69+
"statuses": statuses.isEmpty ? nil : statuses.map({ $0.rawValue }).joined(separator: ","),
7070
"indexUids": indexUids.isEmpty ? nil : indexUids.joined(separator: ","),
7171
"canceledBy": canceledBy.isEmpty ? nil : canceledBy.map(String.init).joined(separator: ","),
7272
"beforeEnqueuedAt": Formatter.formatOptionalDate(date: beforeEnqueuedAt),

Tests/MeiliSearchUnitTests/IndexesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class IndexesTests: XCTestCase {
250250
// Start the test with the mocked server
251251
let expectation = XCTestExpectation(description: "Get keys with parameters")
252252

253-
self.index.getTasks(params: TasksQuery(limit: 20, from: 5, next: 98, types: ["indexCreation"])) { result in
253+
self.index.getTasks(params: TasksQuery(limit: 20, from: 5, next: 98, types: [.indexCreation])) { result in
254254
switch result {
255255
case .success:
256256
let requestQuery = self.session.nextDataTask.request?.url?.query

Tests/MeiliSearchUnitTests/QueryParameters/TasksQueryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class TasksQueryTests: XCTestCase {
88
func testRenderedQuery() {
99
let data: [[String: TasksQuery]] = [
1010
["?limit=2": TasksQuery(limit: 2)],
11-
["?from=99&limit=2&types=name,title": TasksQuery(limit: 2, from: 99, types: ["name", "title"])],
11+
["?from=99&limit=2&types=indexSwap,dumpCreation": TasksQuery(limit: 2, from: 99, types: [.indexSwap, .dumpCreation])],
1212
["?limit=2": TasksQuery(limit: 2, next: nil)],
1313
["?from=2": TasksQuery(from: 2)],
1414
["?indexUids=my-index,123": TasksQuery(indexUids: ["my-index", "123"])],

Tests/MeiliSearchUnitTests/TasksTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class TasksTests: XCTestCase {
3030
// Start the test with the mocked server
3131
let expectation = XCTestExpectation(description: "Get keys with parameters")
3232

33-
self.client.getTasks(params: TasksQuery(limit: 20, from: 5, next: 98, types: ["indexCreation"])) { result in
33+
self.client.getTasks(params: TasksQuery(limit: 20, from: 5, next: 98, types: [.indexCreation])) { result in
3434
switch result {
3535
case .success:
3636
let requestQuery = self.session.nextDataTask.request?.url?.query

0 commit comments

Comments
 (0)