Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
heyjorgedev committed Jul 15, 2024
1 parent 919984a commit f7b8a18
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Contracts/Resources/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace HeyJorgeDev\QStash\Contracts\Resources;

use HeyJorgeDev\QStash\Responses\MessageCancelResponse;
use HeyJorgeDev\QStash\Responses\MessageEnqueueResponse;
use HeyJorgeDev\QStash\Responses\MessagePublishResponse;
use HeyJorgeDev\QStash\ValueObjects\Message;
Expand All @@ -17,7 +18,7 @@ public function batch();

public function get(string $messageId): Message;

public function cancel(string $messageId);
public function cancel(string $messageId): MessageCancelResponse;

/**
* @param array<string> $messageIds
Expand Down
19 changes: 17 additions & 2 deletions src/Resources/MessageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use HeyJorgeDev\QStash\Contracts\Resources\MessageInterface;
use HeyJorgeDev\QStash\Contracts\TransporterInterface;
use HeyJorgeDev\QStash\Exceptions\NotImplementedException;
use HeyJorgeDev\QStash\Responses\MessageCancelResponse;
use HeyJorgeDev\QStash\Responses\MessageEnqueueResponse;
use HeyJorgeDev\QStash\Responses\MessagePublishResponse;
use HeyJorgeDev\QStash\ValueObjects\Message;
Expand Down Expand Up @@ -75,9 +76,23 @@ public function get(string $messageId): Message
throw NotImplementedException::askForContributions('get single message');
}

public function cancel(string $messageId)
public function cancel(string $messageId): MessageCancelResponse
{
throw NotImplementedException::askForContributions('cancel a message');
$request = Request::DELETE("/messages/{$messageId}");

$response = $this->transporter->send($request);

if (! $response->isSuccessful()) {
return new MessageCancelResponse(
$response->statusCode,
$response->body
);
}

return new MessageCancelResponse(
$response->statusCode,
[]
);
}

public function bulkCancel(array $messageIds)
Expand Down
23 changes: 23 additions & 0 deletions src/Responses/MessageCancelResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace HeyJorgeDev\QStash\Responses;

use HeyJorgeDev\QStash\Contracts\ResponseInterface;

class MessageCancelResponse implements ResponseInterface
{
public function __construct(
protected int $statusCode,
protected array $errors,
) {}

public function isSuccessful(): bool
{
return $this->statusCode === 202;
}

public function getErrors(): array
{
return $this->errors;
}
}

0 comments on commit f7b8a18

Please sign in to comment.