Skip to content

Commit

Permalink
Add deleteTasks method to Client
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoocasali committed Nov 26, 2022
1 parent 3e56de2 commit 029ac51
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Endpoints/Delegates/HandlesTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MeiliSearch\Endpoints\Delegates;

use MeiliSearch\Contracts\CancelTasksQuery;
use MeiliSearch\Contracts\DeleteTasksQuery;
use MeiliSearch\Contracts\TasksQuery;
use MeiliSearch\Contracts\TasksResults;

Expand All @@ -24,6 +25,11 @@ public function getTasks(TasksQuery $options = null): TasksResults
return new TasksResults($response);
}

public function deleteTasks(DeleteTasksQuery $options = null): array
{
return $this->tasks->deleteTasks($options);
}

public function cancelTasks(CancelTasksQuery $options = null): array
{
return $this->tasks->cancelTasks($options);
Expand Down
9 changes: 9 additions & 0 deletions src/Endpoints/Tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MeiliSearch\Endpoints;

use MeiliSearch\Contracts\CancelTasksQuery;
use MeiliSearch\Contracts\DeleteTasksQuery;
use MeiliSearch\Contracts\Endpoint;
use MeiliSearch\Exceptions\TimeOutException;

Expand All @@ -30,6 +31,14 @@ public function cancelTasks(?CancelTasksQuery $options): array
return $response;
}

public function deleteTasks(?DeleteTasksQuery $options): array
{
$options = $options ?? new DeleteTasksQuery();
$response = $this->http->delete(self::PATH, $options->toArray());

return $response;
}

/**
* @throws TimeOutException
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/Endpoints/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\Endpoints;

use MeiliSearch\Contracts\DeleteTasksQuery;
use MeiliSearch\Contracts\TasksQuery;
use MeiliSearch\Endpoints\Indexes;
use MeiliSearch\Exceptions\TimeOutException;
Expand Down Expand Up @@ -276,6 +277,15 @@ public function testSwapIndexes(): void
$this->assertSame($response['details']['swaps'], [['indexes' => ['indexA', 'indexB']], ['indexes' => ['indexC', 'indexD']]]);
}

public function testDeleteTasks(): void
{
$promise = $this->client->deleteTasks((new DeleteTasksQuery())->setUids([1, 2]));
$response = $this->client->waitForTask($promise['taskUid']);

$this->assertSame($response['details']['originalFilter'], '?uids=1%2C2');
$this->assertIsNumeric($response['details']['matchedTasks']);
}

public function testParseDate(): void
{
$date = '2021-01-01T01:23:45.123456Z';
Expand Down

0 comments on commit 029ac51

Please sign in to comment.