Skip to content

Commit

Permalink
add twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
flug committed Jun 25, 2020
1 parent 4829a9f commit 427228a
Show file tree
Hide file tree
Showing 32 changed files with 718 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ VEILLEUR_REPOSITORY_LANGUAGE='["php", "javascript", "java", "rust"]'
# For a PostgreSQL database, use: "postgresql://db_user:[email protected]:5432/db_name?serverVersion=11&charset=utf8"
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
DATABASE_URL=''
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN_KEY=
TWITTER_ACCESS_TOKEN_SECRET=

###< doctrine/doctrine-bundle ###

###> symfony/messenger ###
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

db
###> symfony/framework-bundle ###
/.env.local
.env
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
Expand Down
2 changes: 0 additions & 2 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

// any CSS you import will output into a single css file (app.css in this case)
import '../sass/app.sass';

// Need jQuery? Install it with "yarn add jquery", then uncomment to import it.
// import $ from 'jquery';

console.log('Hello Webpack Encore! Edit me in assets/js/app.js');
4 changes: 4 additions & 0 deletions assets/sass/app.sass
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
font-size: 11px
color: #24292e
list-style-type: none

.tweet-list
li
list-style-type: none
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"php": "^7.4",
"ext-ctype": "*",
"ext-iconv": "*",
"abraham/twitteroauth": "^1.1",
"sensio/framework-extra-bundle": "^5.1",
"symfony/asset": "5.1.*",
"symfony/console": "5.1.*",
Expand Down
56 changes: 55 additions & 1 deletion composer.lock

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

2 changes: 1 addition & 1 deletion config/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
frenquency_available: [daily, weekly , monthly]
frenquency_available: [today, daily, weekly , monthly]
languages: '%env(json:VEILLEUR_REPOSITORY_LANGUAGE)%'

# see https://symfony.com/doc/current/reference/configuration/framework.html
Expand Down
5 changes: 5 additions & 0 deletions config/packages/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ framework:
routing:
# Route your messages to the transports
# 'App\Message\YourMessage': async
buses:
command_bus:
middleware:
- doctrine_ping_connection
- doctrine_transaction
12 changes: 12 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@ services:
class: Symfony\Component\HttpClient\NativeHttpClient
factory: ['@Veilleur\Infrastructure\Github\Trending\Client\Factory', create]

twitter.client.factory:
class: Abraham\TwitterOAuth\TwitterOAuth
factory: ['@Veilleur\Infrastructure\Twitter\Client\Factory', create]
arguments:
- '%env(TWITTER_CONSUMER_KEY)%'
- '%env(TWITTER_CONSUMER_SECRET)%'
- '%env(TWITTER_ACCESS_TOKEN_KEY)%'
- '%env(TWITTER_ACCESS_TOKEN_SECRET)%'

Veilleur\Infrastructure\Github\Trending\Client:
- '@github.client.factory'

Veilleur\Infrastructure\Twitter\Client:
- '@twitter.client.factory'
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build": "encore production --progress"
},
"dependencies": {
"@primer/css": "^14.4.0"
"@primer/css": "^14.4.0",
"react-twitter-widgets": "^1.9.5"
}
}
39 changes: 39 additions & 0 deletions src/Application/Handler/DoDoAddAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);

namespace Veilleur\Application\Handler;

use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
use Veilleur\Domain\Command\Twitter\Account\Add as AddAccount;
use Veilleur\Domain\Handler\Twitter\DoAddAccount as AddAccountInterface;
use Veilleur\Domain\Repository\Twitter\Accounts as AccountsRepository;

class DoDoAddAccount implements AddAccountInterface, MessageSubscriberInterface
{
/**
* @var AccountsRepository
*/
private AccountsRepository $accounts;

public function __construct(AccountsRepository $accounts)
{
$this->accounts = $accounts;
}

public function __invoke(AddAccount $accountCommand)
{

$account = $this->accounts->findOneByUsername($accountCommand->getUsername());
if ($account instanceof \Veilleur\Domain\Model\Twitter\Account) {
return;
}
$account = new \Veilleur\Domain\Model\Twitter\Account($accountCommand->getUsername());
$this->accounts->persist($account);

}

public static function getHandledMessages(): iterable
{
yield AddAccount::class;
}
}
35 changes: 35 additions & 0 deletions src/Application/Handler/DoRemoveAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);

namespace Veilleur\Application\Handler;

use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
use Veilleur\Domain\Command\Twitter\Account\Delete;
use Veilleur\Domain\Handler\Twitter\DoRemoveAccount as DoRemoveAccountInterface;
use Veilleur\Domain\Repository\Twitter\Accounts;

class DoRemoveAccount implements DoRemoveAccountInterface, MessageSubscriberInterface
{
/**
* @var Accounts
*/
private Accounts $accounts;

public function __construct(Accounts $accounts)
{
$this->accounts = $accounts;
}

public function __invoke(Delete $delete)
{

$account = $this->accounts->findOneByUsername($delete->getUsername());
$this->accounts->remove($account);

}

public static function getHandledMessages(): iterable
{
yield Delete::class;
}
}
41 changes: 41 additions & 0 deletions src/Application/Repository/Accounts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);

namespace Veilleur\Application\Repository;

use Doctrine\Persistence\{ObjectManager, ObjectRepository};
use Doctrine\Persistence\ManagerRegistry;
use Veilleur\Domain\Model\Twitter\Account;
use Veilleur\Domain\Repository\Twitter\Accounts as AccountsInterface;

final class Accounts implements AccountsInterface
{
private ObjectManager $em;
private ObjectRepository $innerRepository;

public function __construct(ManagerRegistry $registry)
{
$this->em = $registry->getManager();
$this->innerRepository = $registry->getRepository(Account::class);
}

public function findAll(): iterable
{
return $this->innerRepository->findAll();
}

public function findOneByUsername(string $username): ?Account
{
return $this->innerRepository->find($username);
}

public function persist(Account $account): void
{
$this->em->persist($account);
}

public function remove(?Account $account)
{
$this->em->remove($account);
}
}
23 changes: 23 additions & 0 deletions src/Domain/Command/Twitter/Account/Add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace Veilleur\Domain\Command\Twitter\Account;

class Add
{
private string $username;

public function __construct(string $username)
{
$this->username = $username;
}

/**
* @return string
*/
public function getUsername(): string
{
return $this->username;
}

}
23 changes: 23 additions & 0 deletions src/Domain/Command/Twitter/Account/Delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace Veilleur\Domain\Command\Twitter\Account;

class Delete
{
private string $username;

public function __construct(string $username)
{
$this->username = $username;
}

/**
* @return string
*/
public function getUsername(): string
{
return $this->username;
}

}
11 changes: 11 additions & 0 deletions src/Domain/Handler/Twitter/DoAddAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Veilleur\Domain\Handler\Twitter;

use Veilleur\Domain\Command\Twitter\Account\Add as AddAccount;

interface DoAddAccount
{
public function __invoke(AddAccount $accountCommand);
}
12 changes: 12 additions & 0 deletions src/Domain/Handler/Twitter/DoRemoveAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);

namespace Veilleur\Domain\Handler\Twitter;

use Veilleur\Domain\Command\Twitter\Account\Delete;

interface DoRemoveAccount
{

public function __invoke(Delete $delete);
}
32 changes: 32 additions & 0 deletions src/Domain/Model/Twitter/Account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);

namespace Veilleur\Domain\Model\Twitter;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity()
*/
class Account
{
/**
* @ORM\Id()
* @ORM\GeneratedValue(strategy="NONE")
* @ORM\Column(type="string")
*/
public $username;

public function __construct(string $username)
{
$this->username = $username;
}

/**
* @return mixed
*/
public function getUsername()
{
return $this->username;
}
}
Empty file.
17 changes: 17 additions & 0 deletions src/Domain/Repository/Twitter/Accounts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);

namespace Veilleur\Domain\Repository\Twitter;

use Veilleur\Domain\Model\Twitter\Account;

interface Accounts
{
public function findOneByUsername(string $username): ?Account;

public function findAll(): iterable;

public function persist(Account $account): void;

public function remove(?Account $account);
}
Loading

0 comments on commit 427228a

Please sign in to comment.