Skip to content

Commit

Permalink
Refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
VampireAotD committed Aug 16, 2024
1 parent ac47622 commit 42fbb5f
Show file tree
Hide file tree
Showing 15 changed files with 666 additions and 481 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,13 @@ nginx:
+ environment:
+ LOGSTASH_URL: <your-url>
```

Also, **Anilibrary** logs can be send to **Logstash** as well. By default **Logstash** logging is disabled, to enable
it, set environment variable `LOG_STACK` in `src/.env` like this:

```diff
# src/.env

- LOG_STACK=daily
+ LOG_STACK=daily,logstash
```
2 changes: 1 addition & 1 deletion src/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ HORIZON_PATH=horizon
HORIZON_PREFIX=

LOG_CHANNEL=stack
LOG_STACK=single
LOG_STACK=daily
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

Expand Down
2 changes: 1 addition & 1 deletion src/.env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ HORIZON_PATH=horizon
HORIZON_PREFIX=

LOG_CHANNEL=null
LOG_STACK=single
LOG_STACK=daily
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @template-implements Arrayable<string, mixed>
*/
final readonly class CreateUserDTO implements Arrayable
final readonly class RegisterTelegramUserDTO implements Arrayable
{
public function __construct(
public int $telegramId,
Expand Down
4 changes: 2 additions & 2 deletions src/app/Http/Controllers/Telegram/TelegramController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Http\Controllers\Telegram;

use App\DTO\Service\Telegram\User\CreateUserDTO;
use App\DTO\Service\Telegram\User\RegisterTelegramUserDTO;
use App\Http\Controllers\Controller;
use App\Http\Requests\Telegram\AssignRequest;
use App\Services\TelegramUserService;
Expand All @@ -24,7 +24,7 @@ public function __construct(private readonly TelegramUserService $telegramUserSe
*/
public function assign(AssignRequest $request): RedirectResponse
{
$dto = new CreateUserDTO(
$dto = new RegisterTelegramUserDTO(
(int) $request->get('id'),
$request->get('first_name'),
$request->get('last_name'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Jobs\Telegram;

use App\DTO\Service\Telegram\User\CreateUserDTO;
use App\DTO\Service\Telegram\User\RegisterTelegramUserDTO;
use App\Enums\QueueEnum;
use App\Services\TelegramUserService;
use Illuminate\Bus\Queueable;
Expand All @@ -13,7 +13,7 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class CreateUserJob implements ShouldQueue
class RegisterTelegramUserJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
Expand All @@ -23,7 +23,7 @@ class CreateUserJob implements ShouldQueue
/**
* Create a new job instance.
*/
public function __construct(public readonly CreateUserDTO $dto)
public function __construct(public readonly RegisterTelegramUserDTO $dto)
{
$this->onQueue(QueueEnum::TELEGRAM_QUEUE->value)->onConnection('redis');
}
Expand Down
21 changes: 0 additions & 21 deletions src/app/Loggers/Logstash/LogstashHandler.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/app/Services/TelegramUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Services;

use App\DTO\Service\Telegram\User\CreateUserDTO;
use App\DTO\Service\Telegram\User\RegisterTelegramUserDTO;
use App\Models\TelegramUser;
use App\Models\User;
use App\Repositories\TelegramUser\TelegramUserRepositoryInterface;
Expand All @@ -17,15 +17,15 @@ public function __construct(private TelegramUserRepositoryInterface $telegramUse
{
}

public function upsert(CreateUserDTO $dto): TelegramUser
public function upsert(RegisterTelegramUserDTO $dto): TelegramUser
{
return $this->telegramUserRepository->upsert($dto->toArray());
}

/**
* @throws Throwable
*/
public function createAndAttach(User $user, CreateUserDTO $dto): TelegramUser
public function createAndAttach(User $user, RegisterTelegramUserDTO $dto): TelegramUser
{
return DB::transaction(function () use ($dto, $user): TelegramUser {
/** @var TelegramUser $telegramUser */
Expand Down
13 changes: 9 additions & 4 deletions src/app/Telegram/Commands/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace App\Telegram\Commands;

use App\DTO\Service\Telegram\User\CreateUserDTO;
use App\DTO\Service\Telegram\User\RegisterTelegramUserDTO;
use App\Enums\Telegram\Actions\ActionEnum;
use App\Enums\Telegram\Buttons\CommandButtonEnum;
use App\Jobs\Telegram\CreateUserJob;
use App\Jobs\Telegram\RegisterTelegramUserJob;
use SergiX44\Nutgram\Handlers\Type\Command;
use SergiX44\Nutgram\Nutgram;
use SergiX44\Nutgram\Telegram\Types\Keyboard\KeyboardButton;
Expand All @@ -24,8 +24,13 @@ public function handle(Nutgram $bot): void
$user = $bot->user();

if ($user && !$user->is_bot) {
CreateUserJob::dispatch(
new CreateUserDTO($user->id, $user->first_name, $user->last_name ?? 'not set', $user->username)
RegisterTelegramUserJob::dispatch(
new RegisterTelegramUserDTO(
telegramId: $user->id,
firstName : $user->first_name,
lastName : $user->last_name,
userName : $user->username
)
);
}

Expand Down
31 changes: 15 additions & 16 deletions src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
"license": "BSL-1.0",
"require": {
"php": "^8.3",
"aws/aws-sdk-php": "^3.316.4",
"cloudinary-labs/cloudinary-laravel": "^2.1.0",
"elasticsearch/elasticsearch": "^8.14.0",
"aws/aws-sdk-php": "^3.320.1",
"cloudinary-labs/cloudinary-laravel": "^2.2.1",
"elasticsearch/elasticsearch": "^8.15.0",
"firebase/php-jwt": "^6.10.1",
"guzzlehttp/guzzle": "^7.8.2",
"guzzlehttp/guzzle": "^7.9.2",
"inertiajs/inertia-laravel": "^1.3.0",
"laravel/framework": "v11.16.0",
"laravel/horizon": "^5.25.0",
"laravel/octane": "^2.5.2",
"laravel/reverb": "^1.0",
"laravel/framework": "v11.20.0",
"laravel/horizon": "^5.27.1",
"laravel/octane": "^2.5.3",
"laravel/reverb": "^1.1.0",
"laravel/sanctum": "^4.0.2",
"laravel/tinker": "^2.9.0",
"nutgram/laravel": "^1.4.1",
"opcodesio/log-viewer": "^3.10.1",
"nutgram/laravel": "^1.4.2",
"opcodesio/log-viewer": "^3.10.2",
"pusher/pusher-php-server": "^7.2.4",
"spatie/laravel-permission": "^6.9.0",
"tightenco/ziggy": "^2.2.1",
"tightenco/ziggy": "^2.3.0",
"tuupola/base62": "^2.1.0"
},
"require-dev": {
Expand All @@ -36,12 +36,11 @@
"fakerphp/faker": "^1.23.1",
"infection/infection": "^0.27.11",
"larastan/larastan": "^2.9.8",
"laravel/breeze": "^2.1.2",
"laravel/pint": "^1.16.2",
"laravel/sail": "^1.30.2",
"laravel/breeze": "^2.1.3",
"laravel/pint": "^1.17.2",
"mockery/mockery": "^1.6.12",
"nunomaduro/collision": "^8.3.0",
"phpunit/phpunit": "^10.5.22",
"nunomaduro/collision": "^8.4.0",
"phpunit/phpunit": "^10.5.30",
"psalm/plugin-laravel": "^2.11.0",
"spatie/laravel-ignition": "^2.8.0",
"vimeo/psalm": "^5.25.0"
Expand Down
Loading

0 comments on commit 42fbb5f

Please sign in to comment.