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/notify video was created #316

Open
wants to merge 3 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"elasticsearch/elasticsearch": "^7",
"monolog/monolog": "^3",

"endclothing/prometheus_client_php": "^1"
"endclothing/prometheus_client_php": "^1",
"abraham/twitteroauth": "^4.0"
},
"require-dev": {
"ext-xdebug": "*",
Expand Down
140 changes: 139 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Mooc/Videos/Application/Create/VideoCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@
use CodelyTv\Mooc\Shared\Domain\Videos\VideoUrl;
use CodelyTv\Mooc\Videos\Domain\Video;
use CodelyTv\Mooc\Videos\Domain\VideoId;
use CodelyTv\Mooc\Videos\Domain\VideoNotificationSender;
use CodelyTv\Mooc\Videos\Domain\VideoRepository;
use CodelyTv\Mooc\Videos\Domain\VideoTitle;
use CodelyTv\Mooc\Videos\Domain\VideoType;
use CodelyTv\Shared\Domain\Bus\Event\EventBus;

final class VideoCreator
{
public function __construct(private readonly VideoRepository $repository, private readonly EventBus $bus)
{
}
public function __construct(
private readonly VideoRepository $repository,
private readonly EventBus $bus,
private readonly ?VideoNotificationSender $notificationSender = null
) {}

public function create(VideoId $id, VideoType $type, VideoTitle $title, VideoUrl $url, CourseId $courseId): void
{
$video = Video::create($id, $type, $title, $url, $courseId);

$this->repository->save($video);

$this->notificationSender?->videoCreated($video);

$this->bus->publish(...$video->pullDomainEvents());
}
}
20 changes: 20 additions & 0 deletions src/Mooc/Videos/Domain/VideoNotificationSender.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Videos\Domain;

use CodelyTv\Shared\Domain\Notification\Notification;
use CodelyTv\Shared\Domain\Notification\Notificator;

final class VideoNotificationSender
{
public function __construct(private readonly Notificator $notificator) {}

public function videoCreated(Video $video): void
{
$this->notificator->notify(
new Notification("A new video has been published: " . $video->title()->value() . ". Check it out!")
);
}
}
14 changes: 14 additions & 0 deletions src/Shared/Domain/Notification/Notification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Shared\Domain\Notification;

final class Notification
{
public function __construct(private readonly string $text) {}

public function getText(): string {
return $this->text;
}
}
10 changes: 10 additions & 0 deletions src/Shared/Domain/Notification/Notificator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Shared\Domain\Notification;

interface Notificator
{
public function notify(Notification $notification): void;
}
24 changes: 24 additions & 0 deletions src/Shared/Infrastructure/Notification/TwitterNotificator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Shared\Infrastructure\Notification;

use Abraham\TwitterOAuth\TwitterOAuth;
use CodelyTv\Shared\Domain\Notification\Notification;
use CodelyTv\Shared\Domain\Notification\Notificator;

final class TwitterNotificator implements Notificator
{
private readonly TwitterOAuth $client;

public function __construct(string $key, string $secret, string $accessToken, string $accessTokenSecret)
{
$this->client = new TwitterOAuth($key, $secret, $accessToken, $accessTokenSecret);
}

public function notify(Notification $notification): void
{
$this->client->post("statuses/update", ["status" => $notification->getText()]);
}
}