Skip to content

Commit

Permalink
Use Types instead of Strings for Task Queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Sherlouk committed Sep 23, 2023
1 parent cdbe966 commit cff33b7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions Sources/MeiliSearch/QueryParameters/CancelTasksQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import Foundation
*/
public class CancelTasksQuery: Queryable {
/// List of strings with all the types the response should contain.
public let types: [String]
public let types: [TaskType]
/// List of strings with all the statuses the response should contain.
public let statuses: [String]
public let statuses: [Task.Status]
/// Filter tasks response by a particular list of index Uids strings
public let indexUids: [String]
/// Filter tasks based on a list of task's uids.
Expand All @@ -22,7 +22,7 @@ public class CancelTasksQuery: Queryable {
public let afterStartedAt: Date?

init(
types: [String]? = nil, statuses: [String]? = nil,
types: [TaskType]? = nil, statuses: [Task.Status]? = nil,
indexUids: [String]? = nil, uids: [Int]? = nil,
beforeEnqueuedAt: Date? = nil, afterEnqueuedAt: Date? = nil,
beforeStartedAt: Date? = nil, afterStartedAt: Date? = nil
Expand All @@ -40,8 +40,8 @@ public class CancelTasksQuery: Queryable {
internal func buildQuery() -> [String: Codable?] {
[
"uids": uids.isEmpty ? nil : uids.map(String.init).joined(separator: ","),
"types": types.isEmpty ? nil : types.joined(separator: ","),
"statuses": statuses.isEmpty ? nil : statuses.joined(separator: ","),
"types": types.isEmpty ? nil : types.map({ $0.description }).joined(separator: ","),
"statuses": statuses.isEmpty ? nil : statuses.map({ $0.rawValue }).joined(separator: ","),
"indexUids": indexUids.isEmpty ? nil : indexUids.joined(separator: ","),
"beforeEnqueuedAt": Formatter.formatOptionalDate(date: beforeEnqueuedAt),
"afterEnqueuedAt": Formatter.formatOptionalDate(date: afterEnqueuedAt),
Expand Down
10 changes: 5 additions & 5 deletions Sources/MeiliSearch/QueryParameters/DeleteTasksQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import Foundation
*/
public class DeleteTasksQuery: Queryable {
/// List of strings with all the types the response should contain.
public let types: [String]
public let types: [TaskType]
/// List of strings with all the statuses the response should contain.
public let statuses: [String]
public let statuses: [Task.Status]
/// Filter tasks response by a particular list of index Uids strings
public let indexUids: [String]
/// Filter tasks based on a list of task's uids.
Expand All @@ -28,7 +28,7 @@ public class DeleteTasksQuery: Queryable {
public let afterFinishedAt: Date?

init(
statuses: [String]? = nil, types: [String]? = nil,
statuses: [Task.Status]? = nil, types: [TaskType]? = nil,
indexUids: [String]? = nil, uids: [Int]? = nil, canceledBy: [Int]? = nil,
beforeEnqueuedAt: Date? = nil, afterEnqueuedAt: Date? = nil,
beforeStartedAt: Date? = nil, afterStartedAt: Date? = nil,
Expand All @@ -50,8 +50,8 @@ public class DeleteTasksQuery: Queryable {
internal func buildQuery() -> [String: Codable?] {
[
"uids": uids.isEmpty ? nil : uids.map(String.init).joined(separator: ","),
"types": types.isEmpty ? nil : types.joined(separator: ","),
"statuses": statuses.isEmpty ? nil : statuses.joined(separator: ","),
"types": types.isEmpty ? nil : types.map({ $0.description }).joined(separator: ","),
"statuses": statuses.isEmpty ? nil : statuses.map({ $0.rawValue }).joined(separator: ","),
"indexUids": indexUids.isEmpty ? nil : indexUids.joined(separator: ","),
"canceledBy": canceledBy.isEmpty ? nil : canceledBy.map(String.init).joined(separator: ","),
"beforeEnqueuedAt": Formatter.formatOptionalDate(date: beforeEnqueuedAt),
Expand Down
10 changes: 5 additions & 5 deletions Sources/MeiliSearch/QueryParameters/TasksQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class TasksQuery: Queryable {
/// Integer value used to retrieve the next batch of tasks.
private var next: Int?
/// List of strings with all the types the response should contain.
private var types: [String]
private var types: [TaskType]
/// List of strings with all the statuses the response should contain.
private var statuses: [String]
private var statuses: [Task.Status]
/// Filter tasks response by a particular list of index Uids strings
var indexUids: [String]
/// Filter tasks based on a list of task's uids.
Expand All @@ -37,7 +37,7 @@ public class TasksQuery: Queryable {

init(
limit: Int? = nil, from: Int? = nil, next: Int? = nil,
statuses: [String]? = nil, types: [String]? = nil,
statuses: [Task.Status]? = nil, types: [TaskType]? = nil,
indexUids: [String]? = nil, uids: [Int]? = nil, canceledBy: [Int]? = nil,
beforeEnqueuedAt: Date? = nil, afterEnqueuedAt: Date? = nil,
afterFinishedAt: Date? = nil, beforeStartedAt: Date? = nil,
Expand Down Expand Up @@ -65,8 +65,8 @@ public class TasksQuery: Queryable {
"from": from,
"next": next,
"uids": uids.isEmpty ? nil : uids.map(String.init).joined(separator: ","),
"types": types.isEmpty ? nil : types.joined(separator: ","),
"statuses": statuses.isEmpty ? nil : statuses.joined(separator: ","),
"types": types.isEmpty ? nil : types.map({ $0.description }).joined(separator: ","),
"statuses": statuses.isEmpty ? nil : statuses.map({ $0.rawValue }).joined(separator: ","),
"indexUids": indexUids.isEmpty ? nil : indexUids.joined(separator: ","),
"canceledBy": canceledBy.isEmpty ? nil : canceledBy.map(String.init).joined(separator: ","),
"beforeEnqueuedAt": Formatter.formatOptionalDate(date: beforeEnqueuedAt),
Expand Down
2 changes: 1 addition & 1 deletion Tests/MeiliSearchUnitTests/IndexesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class IndexesTests: XCTestCase {
// Start the test with the mocked server
let expectation = XCTestExpectation(description: "Get keys with parameters")

self.index.getTasks(params: TasksQuery(limit: 20, from: 5, next: 98, types: ["indexCreation"])) { result in
self.index.getTasks(params: TasksQuery(limit: 20, from: 5, next: 98, types: [.indexCreation])) { result in
switch result {
case .success:
let requestQuery = self.session.nextDataTask.request?.url?.query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TasksQueryTests: XCTestCase {
func testRenderedQuery() {
let data: [[String: TasksQuery]] = [
["?limit=2": TasksQuery(limit: 2)],
["?from=99&limit=2&types=name,title": TasksQuery(limit: 2, from: 99, types: ["name", "title"])],
["?from=99&limit=2&types=indexSwap,dumpCreation": TasksQuery(limit: 2, from: 99, types: [.indexSwap, .dumpCreation])],
["?limit=2": TasksQuery(limit: 2, next: nil)],
["?from=2": TasksQuery(from: 2)],
["?indexUids=my-index,123": TasksQuery(indexUids: ["my-index", "123"])],
Expand Down
2 changes: 1 addition & 1 deletion Tests/MeiliSearchUnitTests/TasksTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TasksTests: XCTestCase {
// Start the test with the mocked server
let expectation = XCTestExpectation(description: "Get keys with parameters")

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

0 comments on commit cff33b7

Please sign in to comment.