Skip to content

Commit 927cd96

Browse files
author
Alexander Miertsch
committed
Merge pull request #59 from basz/feature/reopen-a-todo
add reopen todo
2 parents 57e6fb4 + c7b607d commit 927cd96

File tree

15 files changed

+367
-6
lines changed

15 files changed

+367
-6
lines changed

config/autoload/dependencies.global.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
\Prooph\ProophessorDo\Model\User\UserCollection::class => \Prooph\ProophessorDo\Container\Infrastructure\Repository\EventStoreUserCollectionFactory::class,
3232
\Prooph\ProophessorDo\Model\Todo\Handler\PostTodoHandler::class => \Prooph\ProophessorDo\Container\Model\Todo\PostTodoHandlerFactory::class,
3333
\Prooph\ProophessorDo\Model\Todo\Handler\MarkTodoAsDoneHandler::class => \Prooph\ProophessorDo\Container\Model\Todo\MarkTodoAsDoneHandlerFactory::class,
34+
\Prooph\ProophessorDo\Model\Todo\Handler\ReopenTodoHandler::class => \Prooph\ProophessorDo\Container\Model\Todo\ReopenTodoHandlerFactory::class,
3435
\Prooph\ProophessorDo\Model\Todo\Handler\AddDeadlineToTodoHandler::class => \Prooph\ProophessorDo\Container\Model\Todo\AddDeadlineToTodoHandlerFactory::class,
3536
\Prooph\ProophessorDo\Model\Todo\TodoList::class => \Prooph\ProophessorDo\Container\Infrastructure\Repository\EventStoreTodoListFactory::class,
3637
// Projections

config/autoload/prooph.global.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
\Prooph\ProophessorDo\Model\User\Command\RegisterUser::class => \Prooph\ProophessorDo\Model\User\Handler\RegisterUserHandler::class,
5151
\Prooph\ProophessorDo\Model\Todo\Command\PostTodo::class => \Prooph\ProophessorDo\Model\Todo\Handler\PostTodoHandler::class,
5252
\Prooph\ProophessorDo\Model\Todo\Command\MarkTodoAsDone::class => \Prooph\ProophessorDo\Model\Todo\Handler\MarkTodoAsDoneHandler::class,
53+
\Prooph\ProophessorDo\Model\Todo\Command\ReopenTodo::class => \Prooph\ProophessorDo\Model\Todo\Handler\ReopenTodoHandler::class,
5354
\Prooph\ProophessorDo\Model\Todo\Command\AddDeadlineToTodo::class => \Prooph\ProophessorDo\Model\Todo\Handler\AddDeadlineToTodoHandler::class,
5455
],
5556
],
@@ -71,6 +72,10 @@
7172
\Prooph\ProophessorDo\Projection\Todo\TodoProjector::class,
7273
\Prooph\ProophessorDo\Projection\User\UserProjector::class,
7374
],
75+
\Prooph\ProophessorDo\Model\Todo\Event\TodoWasReopened::class => [
76+
\Prooph\ProophessorDo\Projection\Todo\TodoProjector::class,
77+
\Prooph\ProophessorDo\Projection\User\UserProjector::class,
78+
],
7479
\Prooph\ProophessorDo\Model\Todo\Event\DeadlineWasAddedToTodo::class => [
7580
\Prooph\ProophessorDo\Projection\Todo\TodoProjector::class,
7681
],

config/autoload/routes.global.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@
101101
],
102102
],
103103
],
104+
[
105+
'name' => 'command::reopen-todo',
106+
'path' => '/api/commands/reopen-todo',
107+
'middleware' => [
108+
\Prooph\ProophessorDo\Middleware\JsonPayload::class,
109+
\Prooph\Psr7Middleware\CommandMiddleware::class,
110+
],
111+
'allowed_methods' => ['POST'],
112+
'options' => [
113+
'values' => [
114+
\Prooph\Psr7Middleware\CommandMiddleware::NAME_ATTRIBUTE => \Prooph\ProophessorDo\Model\Todo\Command\ReopenTodo::class,
115+
],
116+
],
117+
],
104118
[
105119
'name' => 'command::add-deadline-to-todo',
106120
'path' => '/api/commands/add-deadline-to-todo',

public/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ body {
9696
text-decoration: none;
9797
}
9898

99-
.glyphicon-unchecked {
99+
.glyphicon-unchecked,.glyphicon-check {
100100
cursor: pointer;
101101
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/*
3+
* This file is part of prooph/proophessor.
4+
* (c) 2014-2015 prooph software GmbH <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Date: 2/16/16
10+
*/
11+
namespace Prooph\ProophessorDo\Container\Model\Todo;
12+
13+
use Interop\Container\ContainerInterface;
14+
use Prooph\ProophessorDo\Model\Todo\Handler\ReopenTodoHandler;
15+
use Prooph\ProophessorDo\Model\Todo\TodoList;
16+
17+
/**
18+
* Class ReopenTodoFactory
19+
*
20+
* @package Application\Infrastructure\HandlerFactory
21+
* @author Bas Kamer <[email protected]>
22+
*/
23+
final class ReopenTodoHandlerFactory
24+
{
25+
/**
26+
* @param ContainerInterface $container
27+
* @return ReopenTodoHandlerFactory
28+
*/
29+
public function __invoke(ContainerInterface $container)
30+
{
31+
return new ReopenTodoHandler(
32+
$container->get(TodoList::class)
33+
);
34+
}
35+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/*
3+
* This file is part of prooph/proophessor.
4+
* (c) 2014-2015 prooph software GmbH <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Date: 2/16/16
10+
*/
11+
namespace Prooph\ProophessorDo\Model\Todo\Command;
12+
13+
use Prooph\Common\Messaging\Command;
14+
use Prooph\Common\Messaging\PayloadConstructable;
15+
use Prooph\Common\Messaging\PayloadTrait;
16+
use Prooph\ProophessorDo\Model\Todo\TodoId;
17+
18+
/**
19+
* Class ReopenTodo
20+
*
21+
* @package Prooph\ProophessorDo\Model\Todo
22+
* @author Bas Kamer <[email protected]>
23+
*/
24+
final class ReopenTodo extends Command implements PayloadConstructable
25+
{
26+
use PayloadTrait;
27+
28+
/**
29+
*
30+
* @param TodoId $todoId
31+
* @return ReopenTodo
32+
*/
33+
public static function forTodo($todoId)
34+
{
35+
return new self([
36+
'todo_id' => (string) $todoId,
37+
]);
38+
}
39+
40+
/**
41+
* @return TodoId
42+
*/
43+
public function todoId()
44+
{
45+
return TodoId::fromString($this->payload['todo_id']);
46+
}
47+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/*
3+
* This file is part of prooph/proophessor.
4+
* (c) 2014-2015 prooph software GmbH <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Date: 2/16/16
10+
*/
11+
namespace Prooph\ProophessorDo\Model\Todo\Event;
12+
13+
use Prooph\EventSourcing\AggregateChanged;
14+
use Prooph\ProophessorDo\Model\Todo\TodoId;
15+
use Prooph\ProophessorDo\Model\Todo\TodoStatus;
16+
17+
/**
18+
* Class TodoWasReopened
19+
*
20+
* @package Prooph\ProophessorDo\Model\Todo\Event
21+
* @author Bas Kamer <[email protected]>
22+
*/
23+
final class TodoWasReopened extends AggregateChanged
24+
{
25+
private $todoId;
26+
27+
private $status;
28+
29+
/**
30+
* @param TodoId $todoId
31+
* @param TodoStatus $status
32+
* @return TodoWasMarkedAsDone
33+
*/
34+
public static function withStatus(TodoId $todoId, TodoStatus $status)
35+
{
36+
$event = self::occur($todoId->toString(), [
37+
'status' => $status->toString()
38+
]);
39+
40+
$event->todoId = $todoId;
41+
$event->status = $status;
42+
43+
return $event;
44+
}
45+
46+
/**
47+
* @return TodoId
48+
*/
49+
public function todoId()
50+
{
51+
if (null === $this->todoId) {
52+
$this->todoId = TodoId::fromString($this->aggregateId());
53+
}
54+
return $this->todoId;
55+
}
56+
57+
/**
58+
* @return TodoStatus
59+
*/
60+
public function status()
61+
{
62+
if (null === $this->status) {
63+
$this->status = TodoStatus::fromString($this->payload['status']);
64+
}
65+
return $this->status;
66+
}
67+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/*
3+
* This file is part of prooph/proophessor.
4+
* (c) 2014-2015 prooph software GmbH <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Date: 2/16/16
10+
*/
11+
namespace Prooph\ProophessorDo\Model\Todo\Exception;
12+
13+
use Prooph\ProophessorDo\Model\Todo\Todo;
14+
use Prooph\ProophessorDo\Model\Todo\TodoStatus;
15+
16+
/**
17+
* Class CannotReopenTodo
18+
*
19+
* @package Prooph\ProophessorDo\Model\Todo\Exception
20+
* @author Bas Kamer <[email protected]>
21+
*/
22+
final class CannotReopenTodo extends \RuntimeException
23+
{
24+
/**
25+
* @param TodoStatus $status
26+
* @param Todo $todo
27+
* @return CannotReopenTodo
28+
*/
29+
public static function notMarkedDone(Todo $todo)
30+
{
31+
return new self(sprintf(
32+
'Tried to reopen status of Todo %s. But Todo is not marked as done!',
33+
$todo->todoId()->toString()
34+
));
35+
}
36+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*
3+
* This file is part of prooph/proophessor.
4+
* (c) 2014-2015 prooph software GmbH <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Date: 2/16/16
10+
*/
11+
namespace Prooph\ProophessorDo\Model\Todo\Exception;
12+
13+
use Prooph\ProophessorDo\Model\Todo\TodoId;
14+
15+
/**
16+
* Class TodoNotFound
17+
*
18+
* @package Prooph\ProophessorDo\Model\Todo
19+
* @author Bas Kamer <[email protected]>
20+
*/
21+
final class TodoNotFound extends \InvalidArgumentException
22+
{
23+
/**
24+
* @param TodoId $todoId
25+
* @return TodoNotFound
26+
*/
27+
public static function withTodoId(TodoId $todoId)
28+
{
29+
return new self(sprintf('Todo with id %s cannot be found.', $todoId->toString()));
30+
}
31+
}

src/Model/Todo/Handler/MarkTodoAsDoneHandler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Prooph\ProophessorDo\Model\Todo\Handler;
1212

1313
use Prooph\ProophessorDo\Model\Todo\Command\MarkTodoAsDone;
14+
use Prooph\ProophessorDo\Model\Todo\Exception\TodoNotFound;
1415
use Prooph\ProophessorDo\Model\Todo\TodoList;
1516

1617
/**
@@ -40,6 +41,9 @@ public function __construct(TodoList $todoList)
4041
public function __invoke(MarkTodoAsDone $command)
4142
{
4243
$todo = $this->todoList->get($command->todoId());
44+
if (! $todo) {
45+
throw TodoNotFound::withTodoId($command->todoId());
46+
}
4347

4448
$todo->markAsDone();
4549
}

0 commit comments

Comments
 (0)