Skip to content
This repository was archived by the owner on Oct 21, 2020. It is now read-only.

Commit b28ddb9

Browse files
author
Alex Agile
committed
Add Sprint selector endpoint
1 parent eb13564 commit b28ddb9

File tree

7 files changed

+124
-6
lines changed

7 files changed

+124
-6
lines changed

config/graphql/schema/Query.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ Query:
88
@=service("League\\Tactician\\CommandBus").handle(
99
newObject("Werkspot\\JiraDashboard\\TeamWidget\\Domain\\GetTeamsQuery")
1010
)
11+
teamWidgetSprints:
12+
type: "[Sprint]"
13+
resolve: >
14+
@=service("League\\Tactician\\CommandBus").handle(
15+
newObject("Werkspot\\JiraDashboard\\TeamWidget\\Domain\\GetSprintsQuery")
16+
)
1117
1218
sprintWidget:
1319
type: Sprint

src/Werkspot/JiraDashboard/SharedKernel/Infrastructure/Messaging/CommandBus/Tactician/TacticianCommandBusFactory.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
use Werkspot\JiraDashboard\SprintWidget\Domain\AddNewSprintCommand;
3131
use Werkspot\JiraDashboard\SprintWidget\Domain\GetActiveSprintByTeamQuery;
3232
use Werkspot\JiraDashboard\TeamWidget\Application\AddTeamCommandHandler;
33+
use Werkspot\JiraDashboard\TeamWidget\Application\GetSprintsQueryHandler;
3334
use Werkspot\JiraDashboard\TeamWidget\Application\GetTeamsQueryHandler;
3435
use Werkspot\JiraDashboard\TeamWidget\Domain\AddTeamCommand;
36+
use Werkspot\JiraDashboard\TeamWidget\Domain\GetSprintsQuery;
3537
use Werkspot\JiraDashboard\TeamWidget\Domain\GetTeamsQuery;
3638

3739
final class TacticianCommandBusFactory
@@ -84,8 +86,9 @@ public function __construct(
8486
$inflector = new HandleInflector();
8587

8688
// register commands/queries
87-
$getTeamsQueryHandler = new GetTeamsQueryHandler($this->teamRepository);
88-
$addTeamCommandHandler = new AddTeamCommandHandler($this->teamRepository);
89+
$getTeamsQueryHandler = new GetTeamsQueryHandler($this->teamRepository, $this->sprintRepository);
90+
$getSprintsQueryHandler = new GetSprintsQueryHandler($this->teamRepository, $this->sprintRepository);
91+
$addTeamCommandHandler = new AddTeamCommandHandler($this->teamRepository, $this->sprintRepository);
8992

9093
$getConfidenceBySprintQueryHandler = new GetConfidenceBySprintQueryHandler($this->sprintRepository, $this->confidenceRepository);
9194
$saveConfidenceCommandHandler = new SaveConfidenceCommandHandler($this->sprintRepository, $this->confidenceRepository);
@@ -102,6 +105,7 @@ public function __construct(
102105
$locator = new InMemoryLocator();
103106

104107
$locator->addHandler($getTeamsQueryHandler, GetTeamsQuery::class);
108+
$locator->addHandler($getSprintsQueryHandler, GetSprintsQuery::class);
105109
$locator->addHandler($addTeamCommandHandler, AddTeamCommand::class);
106110

107111
$locator->addHandler($getConfidenceBySprintQueryHandler, GetConfidenceBySprintQuery::class);

src/Werkspot/JiraDashboard/TeamWidget/Application/AddTeamCommandHandler.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Werkspot\JiraDashboard\TeamWidget\Application;
55

6+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Sprint\SprintRepositoryInterface;
67
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\Team;
78
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\TeamRepositoryInterface;
89
use Werkspot\JiraDashboard\SharedKernel\Domain\ValueObject\Id;
@@ -17,9 +18,15 @@ class AddTeamCommandHandler
1718
*/
1819
private $teamRepository;
1920

20-
public function __construct(TeamRepositoryInterface $teamRepository)
21+
/**
22+
* @var SprintRepositoryInterface
23+
*/
24+
private $sprintRepository;
25+
26+
public function __construct(TeamRepositoryInterface $teamRepository, SprintRepositoryInterface $sprintRepository)
2127
{
2228
$this->teamRepository = $teamRepository;
29+
$this->sprintRepository = $sprintRepository;
2330
}
2431

2532
public function handle(AddTeamCommand $command): void
@@ -28,7 +35,7 @@ public function handle(AddTeamCommand $command): void
2835

2936
$team = new Team(Id::create(), $teamName);
3037

31-
$teamWidget = new TeamWidget($this->teamRepository);
38+
$teamWidget = new TeamWidget($this->teamRepository, $this->sprintRepository);
3239
$teamWidget->addTeam($team);
3340
}
3441
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Werkspot\JiraDashboard\TeamWidget\Application;
5+
6+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Sprint\SprintRepositoryInterface;
7+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\Team;
8+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\TeamRepositoryInterface;
9+
use Werkspot\JiraDashboard\SharedKernel\Domain\ValueObject\Id;
10+
use Werkspot\JiraDashboard\TeamWidget\Domain\GetSprintsQuery;
11+
use Werkspot\JiraDashboard\TeamWidget\Domain\TeamWidget;
12+
13+
class GetSprintsQueryHandler
14+
{
15+
/**
16+
* @var TeamRepositoryInterface
17+
*/
18+
private $teamRepository;
19+
20+
/**
21+
* @var SprintRepositoryInterface
22+
*/
23+
private $sprintRepository;
24+
25+
public function __construct(TeamRepositoryInterface $teamRepository, SprintRepositoryInterface $sprintRepository)
26+
{
27+
$this->teamRepository = $teamRepository;
28+
$this->sprintRepository = $sprintRepository;
29+
}
30+
31+
/**
32+
* @return Team[]
33+
*/
34+
public function handle(GetSprintsQuery $getSprintsQuery): array
35+
{
36+
$teamWidget = new TeamWidget($this->teamRepository, $this->sprintRepository);
37+
38+
$teamIdValue = $getSprintsQuery->getTeamId();
39+
40+
$team = $this->teamRepository->find(Id::create($teamIdValue));
41+
42+
return $teamWidget->getSprints($team);
43+
}
44+
}

src/Werkspot/JiraDashboard/TeamWidget/Application/GetTeamsQueryHandler.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Werkspot\JiraDashboard\TeamWidget\Application;
55

6+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Sprint\SprintRepositoryInterface;
67
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\Team;
78
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\TeamRepositoryInterface;
89
use Werkspot\JiraDashboard\TeamWidget\Domain\GetTeamsQuery;
@@ -15,17 +16,23 @@ class GetTeamsQueryHandler
1516
*/
1617
private $teamRepository;
1718

18-
public function __construct(TeamRepositoryInterface $teamRepository)
19+
/**
20+
* @var SprintRepositoryInterface
21+
*/
22+
private $sprintRepository;
23+
24+
public function __construct(TeamRepositoryInterface $teamRepository, SprintRepositoryInterface $sprintRepository)
1925
{
2026
$this->teamRepository = $teamRepository;
27+
$this->sprintRepository = $sprintRepository;
2128
}
2229

2330
/**
2431
* @return Team[]
2532
*/
2633
public function handle(GetTeamsQuery $getTeamsQuery): array
2734
{
28-
$teamWidget = new TeamWidget($this->teamRepository);
35+
$teamWidget = new TeamWidget($this->teamRepository, $this->sprintRepository);
2936

3037
return $teamWidget->getTeams();
3138
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Werkspot\JiraDashboard\TeamWidget\Domain;
5+
6+
class GetSprintsQuery
7+
{
8+
/**
9+
* @var string
10+
*/
11+
private $teamId;
12+
13+
public function __construct(string $teamId)
14+
{
15+
$this->teamId = $teamId;
16+
}
17+
18+
public function getTeamId(): string
19+
{
20+
return $this->teamId;
21+
}
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Werkspot\Tests\JiraDashboard\TeamWidget\Integration;
5+
6+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Sprint\Sprint;
7+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\Team;
8+
use Werkspot\JiraDashboard\TeamWidget\Domain\GetSprintsQuery;
9+
use Werkspot\Tests\JiraDashboard\SharedKernel\Integration\IntegrationTestAbstract;
10+
11+
class GetSprintsQueryTest extends IntegrationTestAbstract
12+
{
13+
/**
14+
* @test
15+
*/
16+
public function getSprintsQuery_whenThereAreSomeSprints_shouldReturnSprintsData()
17+
{
18+
/** @var Team[] $allTeamsCollection */
19+
$allTeamsCollection = $this->teamRepositoryDoctrineAdapter->findAll();
20+
$team = array_shift($allTeamsCollection);
21+
22+
$getSprintsQuery = new GetSprintsQuery($team->getId()->id());
23+
$sprintsData = $this->commandBus->handle($getSprintsQuery);
24+
25+
$this->assertCount(1, $sprintsData);
26+
$this->assertInstanceOf(Sprint::class, array_shift($sprintsData));
27+
}
28+
}

0 commit comments

Comments
 (0)