Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add events for row added and row updated #1101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/Event/RowAddedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace OCA\Tables\Event;

use OCA\Tables\Db\Row2;
use OCP\EventDispatcher\Event;

final class RowAddedEvent extends Event {
public function __construct(protected Row2 $row) {
parent::__construct();
}

public function getRow(): Row2 {
return $this->row;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blizzz What's your thought on just returning the entity directly here?

I'm unsure if we shall expose the internal row entity through events, rather expose specific getters or use a serializable event as #1103 mentioned

}
}
18 changes: 18 additions & 0 deletions lib/Event/RowUpdatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace OCA\Tables\Event;

use OCA\Tables\Db\Row2;
use OCP\EventDispatcher\Event;

final class RowUpdatedEvent extends Event {
public function __construct(protected Row2 $row) {
parent::__construct();
}

public function getRow(): Row2 {
return $this->row;
}
}
14 changes: 12 additions & 2 deletions lib/Service/RowService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use OCA\Tables\Errors\InternalError;
use OCA\Tables\Errors\NotFoundError;
use OCA\Tables\Errors\PermissionError;
use OCA\Tables\Event\RowAddedEvent;
use OCA\Tables\Event\RowDeletedEvent;
use OCA\Tables\Event\RowUpdatedEvent;
use OCA\Tables\ResponseDefinitions;
use OCA\Tables\Service\ColumnTypes\IColumnTypeBusiness;
use OCP\AppFramework\Db\DoesNotExistException;
Expand Down Expand Up @@ -213,7 +215,11 @@ public function create(?int $tableId, ?int $viewId, array $data): Row2 {
$row2->setTableId($tableId);
$row2->setData($data);
try {
return $this->row2Mapper->insert($row2, $this->columnMapper->findAllByTable($tableId));
$insertedRow = $this->row2Mapper->insert($row2, $this->columnMapper->findAllByTable($tableId));

$this->eventDispatcher->dispatchTyped(new RowAddedEvent(row: $insertedRow));

return $insertedRow;
} catch (InternalError|Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage());
Expand Down Expand Up @@ -410,7 +416,11 @@ public function updateSet(
}
}

return $this->filterRowResult($view ?? null, $this->row2Mapper->update($item, $columns));
$updatedRow = $this->row2Mapper->update($item, $columns);

$this->eventDispatcher->dispatchTyped(new RowUpdatedEvent(row: $updatedRow));

return $this->filterRowResult($view ?? null, $updatedRow);
}

/**
Expand Down
Loading