Skip to content

Commit

Permalink
Merge pull request #12 from decole/bugfix/updates
Browse files Browse the repository at this point in the history
fix card updates
  • Loading branch information
decole authored Jun 20, 2023
2 parents 177d665 + f033330 commit e90e973
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 7 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

Wrapper over the rest api of the Planka (https://github.com/plankanban/planka)

Tested on Planka version **1.10.3**
Tested on Planka version:
- 1.10.3
- 1.11

Implemented all entrypoints for the bar version **1.10.3** and later.

Expand Down Expand Up @@ -40,7 +42,8 @@ $result = $client->project->list();
var_dump($result);
```

You can test this bundle for Rest API with a test script, in the folder/tests/index.php
You can test this bundle for Rest API with a test script, in the folder `/tests/index.php`.
There you will find the main examples of using the script.

Copy [config.example.php](tests/config.example.php) for `config.php` and customize to your
planka credentials.
Expand All @@ -54,6 +57,13 @@ in the `src/Controllers/` folder.
Result data output is strongly typed and returned in Dto objects


## Found problems:

Using Symfony\Component\HttpClient\NativeHttpClient - as an internal client, you can send passwords with special characters `()\|/"'`
but if you use Symfony\Component\HttpClient\CurlHttpClient - tricky passwords cannot be used. inside there is escaping for url encoding, which is why Planck
the password cannot be intact. Because of this, it is impossible to log in with an account.


## For develop

### RTFM
Expand All @@ -65,4 +75,4 @@ Result data output is strongly typed and returned in Dto objects
### Static analyze code
Psalm analyze: `./vendor/bin/psalm --no-cache --no-file-cache`

Or if you use linux, use `make psalm`
Or if you use linux, use `make psalm`
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"minimum-stability": "dev",
"prefer-stable": true,
"version": "1.0.1",
"version": "1.1.1",
"require-dev": {
"symfony/var-dumper": "^6.2",
"vimeo/psalm": "^5.11"
Expand Down
36 changes: 36 additions & 0 deletions src/Actions/Card/CardClearDueDateAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Planka\Bridge\Actions\Card;

use Planka\Bridge\Contracts\Actions\ResponseResultInterface;
use Planka\Bridge\Contracts\Actions\AuthenticateInterface;
use Planka\Bridge\Contracts\Actions\ActionInterface;
use Planka\Bridge\Traits\AuthenticateTrait;
use Planka\Bridge\Traits\CardHydrateTrait;
use Planka\Bridge\Views\Dto\Card\CardDto;

final class CardClearDueDateAction implements ActionInterface, AuthenticateInterface, ResponseResultInterface
{
use AuthenticateTrait, CardHydrateTrait;

public function __construct(private readonly CardDto $card, string $token)
{
$this->setToken($token);
}

public function url(): string
{
return "api/cards/{$this->card->id}";
}

public function getOptions(): array
{
return [
'json' => [
'stopwatch' => null,
],
];
}
}
38 changes: 38 additions & 0 deletions src/Actions/Card/CardMoveAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Planka\Bridge\Actions\Card;

use Planka\Bridge\Contracts\Actions\ResponseResultInterface;
use Planka\Bridge\Contracts\Actions\AuthenticateInterface;
use Planka\Bridge\Contracts\Actions\ActionInterface;
use Planka\Bridge\Traits\AuthenticateTrait;
use Planka\Bridge\Traits\CardHydrateTrait;
use Planka\Bridge\Views\Dto\Card\CardDto;

final class CardMoveAction implements ActionInterface, AuthenticateInterface, ResponseResultInterface
{
use AuthenticateTrait, CardHydrateTrait;

public function __construct(private readonly CardDto $card, string $token)
{
$this->setToken($token);
}

public function url(): string
{
return "api/cards/{$this->card->id}";
}

public function getOptions(): array
{
return [
'json' => [
'listId' => $this->card->listId,
'boardId' => $this->card->boardId,
'position' => $this->card->position,
],
];
}
}
1 change: 0 additions & 1 deletion src/Actions/Card/CardUpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function getOptions(): array
'dueDate' => $this->card?->dueDate?->format('Y-m-d\TH:i:s.v\Z'),
'listId' => $this->card->listId,
'position' => $this->card->position,
'stopwatch'
],
];

Expand Down
20 changes: 20 additions & 0 deletions src/Controllers/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace Planka\Bridge\Controllers;

use Planka\Bridge\Actions\Card\CardClearDueDateAction;
use Planka\Bridge\Actions\Card\CardCreateAction;
use Planka\Bridge\Actions\Card\CardDeleteAction;
use Planka\Bridge\Actions\Card\CardMoveAction;
use Planka\Bridge\Actions\Card\CardUpdateAction;
use Planka\Bridge\Actions\Card\CardViewAction;
use Planka\Bridge\TransportClients\Client;
Expand Down Expand Up @@ -46,6 +48,24 @@ public function update(CardDto $card): CardDto
));
}

/** 'PATCH /api/cards/:id' */
public function clearTime(CardDto $card): CardDto
{
return $this->client->patch(new CardClearDueDateAction(
card: $card,
token: $this->config->getAuthToken()
));
}

/** 'PATCH /api/cards/:id' */
public function moveCard(CardDto $card): CardDto
{
return $this->client->patch(new CardMoveAction(
card: $card,
token: $this->config->getAuthToken()
));
}

/** 'PATCH /api/cards/:id' */
public function addSpentTime(CardDto $card, int $seconds): CardDto
{
Expand Down
19 changes: 17 additions & 2 deletions tests/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
// add board
$board = $client->board->create($projectGet->id, 'testCard', 1);
$boardGet = $client->board->get($board->item->id);
$boardOther = $client->board->create($projectGet->id, 'archive', 2);

$client->board->update($boardGet->item->id, 'romb');

// add board list
$list = $client->boardList->create($boardGet->item->id, 'one', 1);
$listOther = $client->boardList->create($boardOther->item->id, 'archive', 22);

// add card
$card = $client->card->create($list->id, 'card', 1);
Expand All @@ -72,11 +74,22 @@
$cardGet->description = 'ok!';
$client->card->update($cardGet);

// test moving to other board
$card->boardId = $boardOther->item->id;
$card->listId = $listOther->id;
$card->position = 33;
$client->card->moveCard($card);

$card->boardId = $board->item->id;
$card->listId = $list->id;
$card->position = 1;
$client->card->moveCard($card);

// add spend worked time to card
$client->card->addSpentTime($cardGet, 290);

// remove spend time
$cardGet->stopwatch = null;
$client->card->update($cardGet);
$client->card->clearTime($cardGet);

// get history action by card
$client->cardAction->getActions($cardGet->id);
Expand Down Expand Up @@ -119,12 +132,14 @@
$boardGet = $client->board->get($boardGet->item->id);
$user = $boardGet->included->users[0];
$member = $client->cardMembership->add($cardGet->id, $user->id);

// remove member
$client->cardMembership->remove($cardGet->id, $user->id);

// card due Date
$cardGet->dueDate = (new DateTimeImmutable())->modify('+ 1 year');
$client->card->update($cardGet);

// remove due date
$cardGet->dueDate = null;
$client->card->update($cardGet);
Expand Down

0 comments on commit e90e973

Please sign in to comment.