Skip to content

Commit ab1761b

Browse files
author
Mario Marco
committed
GG-403 added getEventsFilteredByAggregate, countGivenEventsByAggregate, countEventsFilteredByAggregate to EventStoreRepository
1 parent 1256a81 commit ab1761b

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/Repository/EventStoreRepository.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ interface EventStoreRepository extends DddEventStoreRepository
1111
{
1212
public function countEventsFor(Uuid $aggregateId): int;
1313

14+
public function countGivenEventsByAggregate(Uuid $aggregateId, string ...$events): int;
15+
16+
public function countEventsFilteredByAggregate(Uuid $aggregateId, string ...$events): int;
17+
1418
public function countEventsForSince(Uuid $aggregateId, DateTimeValueObject $since): int;
1519

1620
public function getGivenEventsByAggregate(Uuid $aggregateId, int $offset, int $limit, string ...$events): array;

src/Repository/PostgresBaseAggregateRepository.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,35 @@ protected function countByAggregateId(Uuid $aggregateId): int
169169
return $result['count'];
170170
}
171171

172+
protected function countGivenEventsByAggregateId(Uuid $aggregateId, string ...$eventNames): int
173+
{
174+
$stmt = $this->connection
175+
->createQueryBuilder()
176+
->select('count(message_id) as count')
177+
->from($this->tableName())
178+
->where('message_name IN (:eventNames)');
179+
180+
$stmt->setParameter('aggregateId', $aggregateId->value(), \PDO::PARAM_STR);
181+
$stmt->setParameter('eventNames', $eventNames, Connection::PARAM_STR_ARRAY);
182+
183+
return $stmt->execute()->fetchOne();
184+
}
185+
186+
protected function countFilteredEventsByAggregateId(Uuid $aggregateId, string ...$eventNames): int
187+
{
188+
$stmt = $this->connection
189+
->createQueryBuilder()
190+
->select('count(message_id) as count')
191+
->from($this->tableName())
192+
->where('message_name NOT IN (:eventNames)');
193+
194+
$stmt->setParameter('aggregateId', $aggregateId->value(), \PDO::PARAM_STR);
195+
$stmt->setParameter('eventNames', $eventNames, Connection::PARAM_STR_ARRAY);
196+
197+
return $stmt->execute()->fetchOne();
198+
}
199+
200+
172201
protected function countByAggregateIdSince(Uuid $aggregateId, DateTimeValueObject $since): int
173202
{
174203
$stmt = $this->connection->prepare(

src/Repository/PostgresEventStoreRepository.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ public function countEventsFor(Uuid $aggregateId): int
6767
return $this->countByAggregateId($aggregateId);
6868
}
6969

70+
public function countGivenEventsByAggregate(Uuid $aggregateId, string ...$events): int
71+
{
72+
return $this->countGivenEventsByAggregateId( $aggregateId, ...$events);
73+
}
74+
75+
public function countEventsFilteredByAggregate(Uuid $aggregateId, string ...$events): int
76+
{
77+
return $this->countFilteredEventsByAggregateId($aggregateId, ...$events);
78+
}
79+
7080
public function countEventsForSince(Uuid $aggregateId, DateTimeValueObject $since): int
7181
{
7282
return $this->countByAggregateIdSince($aggregateId, $since);

0 commit comments

Comments
 (0)