feat: add room share events

pull/77/head
sualko 2020-09-18 14:46:11 +02:00
parent 0ad1b499d9
commit 41ba0d7137
5 changed files with 50 additions and 3 deletions

View File

@ -5,7 +5,7 @@ namespace OCA\BigBlueButton\Event;
use OCP\EventDispatcher\Event;
use OCA\BigBlueButton\Db\Room;
class RoomEvent extends Event {
abstract class RoomEvent extends Event {
/** @var Room */
private $room;

View File

@ -0,0 +1,6 @@
<?php
namespace OCA\BigBlueButton\Event;
class RoomShareCreatedEvent extends RoomShareEvent {
}

View File

@ -0,0 +1,6 @@
<?php
namespace OCA\BigBlueButton\Event;
class RoomShareDeletedEvent extends RoomShareEvent {
}

View File

@ -0,0 +1,20 @@
<?php
namespace OCA\BigBlueButton\Event;
use OCP\EventDispatcher\Event;
use OCA\BigBlueButton\Db\RoomShare;
abstract class RoomShareEvent extends Event {
/** @var RoomShare */
private $roomShare;
public function __construct(RoomShare $roomShare) {
$this->roomId = $roomShare;
}
public function getRoomShare(): RoomShare {
return $this->roomShare;
}
}

View File

@ -6,17 +6,26 @@ use Exception;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\EventDispatcher\IEventDispatcher;
use OCA\BigBlueButton\Db\RoomShare;
use OCA\BigBlueButton\Db\RoomShareMapper;
use OCA\BigBlueButton\Event\RoomShareCreatedEvent;
use OCA\BigBlueButton\Event\RoomShareDeletedEvent;
class RoomShareService {
/** @var RoomShareMapper */
private $mapper;
public function __construct(RoomShareMapper $mapper) {
/** @var IEventDispatcher */
private $eventDispatcher;
public function __construct(
RoomShareMapper $mapper,
IEventDispatcher $eventDispatcher) {
$this->mapper = $mapper;
$this->eventDispatcher = $eventDispatcher;
}
public function findAll(int $roomId): array {
@ -53,7 +62,11 @@ class RoomShareService {
$roomShare->setShareWith($shareWith);
$roomShare->setPermission($permission);
return $this->mapper->insert($roomShare);
$createdRoomShare = $this->mapper->insert($roomShare);
$this->eventDispatcher->dispatch(RoomShareCreatedEvent::class, new RoomShareCreatedEvent($createdRoomShare));
return $createdRoomShare;
}
}
@ -77,6 +90,8 @@ class RoomShareService {
$roomShare = $this->mapper->find($id);
$this->mapper->delete($roomShare);
$this->eventDispatcher->dispatch(RoomShareDeletedEvent::class, new RoomShareDeletedEvent($roomShare));
return $roomShare;
} catch (Exception $e) {
$this->handleException($e);