Compare commits
21 Commits
09737e768d
...
4b6cf902ff
Author | SHA1 | Date | |
---|---|---|---|
4b6cf902ff | |||
d6cb058830 | |||
0c5f2317fd | |||
6a2991eb5e | |||
481dcac2cc | |||
e8b79ca457 | |||
371395ddd5 | |||
8c353a49b7 | |||
491249c8d8 | |||
a648ba3db9 | |||
435e793eb2 | |||
05fabd7650 | |||
24e0cf0eea | |||
63ea5dac92 | |||
4583908230 | |||
2769585de0 | |||
b7d0a2453e | |||
e41f63f94f | |||
c96dabbd09 | |||
e8e9e50162 | |||
bb2b68507b |
9
.env.example
Normal file
9
.env.example
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
DOCKER_APP_PORT=8080
|
||||||
|
DOCKER_CAPTCHA_PORT=8081
|
||||||
|
DOCKER_DB_PORT=3306
|
||||||
|
MYSQL_ROOT_PASSWORD=root_pass
|
||||||
|
DB_DATABASE=my-projetcs
|
||||||
|
DB_USERNAME=my-projetcs
|
||||||
|
DB_PASSWORD=my-projetcs_pass
|
||||||
|
UID=1000
|
||||||
|
GID=1000
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 kor-elf
|
Copyright (c) 2024 Leonid Nikitin (kor-elf)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
20
README.md
20
README.md
@ -1,3 +1,19 @@
|
|||||||
# my-projects-website
|
## О проекте
|
||||||
|
|
||||||
Сайт для моих проектов.
|
Свой сервис, что бы быстро создавать сайты для своих проектов.
|
||||||
|
|
||||||
|
[Сайт проекта](https://my-projects-website.projects.kor-elf.net/)
|
||||||
|
|
||||||
|
## Зависимости
|
||||||
|
|
||||||
|
php 8.3 (модули: redis, gd)
|
||||||
|
|
||||||
|
redis
|
||||||
|
|
||||||
|
mysql 8
|
||||||
|
|
||||||
|
[Service Captcha](https://git.kor-elf.net/kor-elf/service-captcha)
|
||||||
|
|
||||||
|
## Лицензия
|
||||||
|
|
||||||
|
[MIT license](https://opensource.org/licenses/MIT).
|
||||||
|
18
app/application/.editorconfig
Normal file
18
app/application/.editorconfig
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.{yml,yaml}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[docker-compose.yml]
|
||||||
|
indent_size = 4
|
77
app/application/.env.example
Normal file
77
app/application/.env.example
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
APP_NAME=Laravel
|
||||||
|
APP_ENV=local
|
||||||
|
APP_KEY=
|
||||||
|
APP_DEBUG=true
|
||||||
|
APP_TIMEZONE=UTC
|
||||||
|
APP_URL=http://localhost
|
||||||
|
|
||||||
|
CAPTCHA_API_DOMAIN=http://your-domain-captcha-or-IP:8081
|
||||||
|
CAPTCHA_PRIVATE_TOKEN=
|
||||||
|
CAPTCHA_STATIC_PATH=http://your-domain-captcha-or-IP:8081/captcha
|
||||||
|
CAPTCHA_PUBLIC_TOKEN=
|
||||||
|
|
||||||
|
APP_FORCE_HTTPS=false
|
||||||
|
#UNIT_SOURCE="\"172.16.0.0/12\""
|
||||||
|
|
||||||
|
APP_DEFAULT_LOCALE=ru
|
||||||
|
APP_FAKER_LOCALE=ru_RU
|
||||||
|
APP_DEFAULT_USER_TIMEZONE=UTC
|
||||||
|
|
||||||
|
APP_MAINTENANCE_DRIVER=file
|
||||||
|
APP_MAINTENANCE_STORE=database
|
||||||
|
|
||||||
|
#LOGIN_MAX_REQUEST=50
|
||||||
|
#LOGIN_MAX_EMAIL_REQUEST=10
|
||||||
|
|
||||||
|
TINYMCE_LICENSE_KEY="gpl"
|
||||||
|
|
||||||
|
BCRYPT_ROUNDS=12
|
||||||
|
|
||||||
|
LOG_CHANNEL=stack
|
||||||
|
LOG_STACK=single
|
||||||
|
LOG_DEPRECATIONS_CHANNEL=null
|
||||||
|
LOG_LEVEL=debug
|
||||||
|
|
||||||
|
DB_CONNECTION=mysql
|
||||||
|
DB_HOST=127.0.0.1
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_DATABASE=laravel
|
||||||
|
DB_USERNAME=root
|
||||||
|
DB_PASSWORD=
|
||||||
|
|
||||||
|
SESSION_DRIVER=redis
|
||||||
|
SESSION_LIFETIME=120
|
||||||
|
SESSION_ENCRYPT=true
|
||||||
|
SESSION_PATH=/
|
||||||
|
SESSION_DOMAIN=null
|
||||||
|
|
||||||
|
BROADCAST_CONNECTION=log
|
||||||
|
FILESYSTEM_DISK=local
|
||||||
|
QUEUE_CONNECTION=redis
|
||||||
|
|
||||||
|
CACHE_STORE=redis
|
||||||
|
CACHE_PREFIX=
|
||||||
|
|
||||||
|
MEMCACHED_HOST=127.0.0.1
|
||||||
|
|
||||||
|
REDIS_CLIENT=phpredis
|
||||||
|
REDIS_HOST=app-redis
|
||||||
|
REDIS_PASSWORD=null
|
||||||
|
REDIS_PORT=6379
|
||||||
|
|
||||||
|
MAIL_MAILER=log
|
||||||
|
MAIL_HOST=127.0.0.1
|
||||||
|
MAIL_PORT=2525
|
||||||
|
MAIL_USERNAME=null
|
||||||
|
MAIL_PASSWORD=null
|
||||||
|
MAIL_ENCRYPTION=null
|
||||||
|
MAIL_FROM_ADDRESS="hello@example.com"
|
||||||
|
MAIL_FROM_NAME="${APP_NAME}"
|
||||||
|
|
||||||
|
AWS_ACCESS_KEY_ID=
|
||||||
|
AWS_SECRET_ACCESS_KEY=
|
||||||
|
AWS_DEFAULT_REGION=us-east-1
|
||||||
|
AWS_BUCKET=
|
||||||
|
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||||
|
|
||||||
|
VITE_APP_NAME="${APP_NAME}"
|
11
app/application/.gitattributes
vendored
Normal file
11
app/application/.gitattributes
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
* text=auto eol=lf
|
||||||
|
|
||||||
|
*.blade.php diff=html
|
||||||
|
*.css diff=css
|
||||||
|
*.html diff=html
|
||||||
|
*.md diff=markdown
|
||||||
|
*.php diff=php
|
||||||
|
|
||||||
|
/.github export-ignore
|
||||||
|
CHANGELOG.md export-ignore
|
||||||
|
.styleci.yml export-ignore
|
19
app/application/.gitignore
vendored
Normal file
19
app/application/.gitignore
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/.phpunit.cache
|
||||||
|
/node_modules
|
||||||
|
/public/build
|
||||||
|
/public/hot
|
||||||
|
/public/storage
|
||||||
|
/storage/*.key
|
||||||
|
/vendor
|
||||||
|
.env
|
||||||
|
.env.backup
|
||||||
|
.env.production
|
||||||
|
.phpunit.result.cache
|
||||||
|
Homestead.json
|
||||||
|
Homestead.yaml
|
||||||
|
auth.json
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
/.fleet
|
||||||
|
/.idea
|
||||||
|
/.vscode
|
66
app/application/README.md
Normal file
66
app/application/README.md
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
|
||||||
|
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
|
||||||
|
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
|
||||||
|
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## About Laravel
|
||||||
|
|
||||||
|
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
|
||||||
|
|
||||||
|
- [Simple, fast routing engine](https://laravel.com/docs/routing).
|
||||||
|
- [Powerful dependency injection container](https://laravel.com/docs/container).
|
||||||
|
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
|
||||||
|
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
|
||||||
|
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
|
||||||
|
- [Robust background job processing](https://laravel.com/docs/queues).
|
||||||
|
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
|
||||||
|
|
||||||
|
Laravel is accessible, powerful, and provides tools required for large, robust applications.
|
||||||
|
|
||||||
|
## Learning Laravel
|
||||||
|
|
||||||
|
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
|
||||||
|
|
||||||
|
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
|
||||||
|
|
||||||
|
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
|
||||||
|
|
||||||
|
## Laravel Sponsors
|
||||||
|
|
||||||
|
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
|
||||||
|
|
||||||
|
### Premium Partners
|
||||||
|
|
||||||
|
- **[Vehikl](https://vehikl.com/)**
|
||||||
|
- **[Tighten Co.](https://tighten.co)**
|
||||||
|
- **[WebReinvent](https://webreinvent.com/)**
|
||||||
|
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
|
||||||
|
- **[64 Robots](https://64robots.com)**
|
||||||
|
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
|
||||||
|
- **[Cyber-Duck](https://cyber-duck.co.uk)**
|
||||||
|
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
|
||||||
|
- **[Jump24](https://jump24.co.uk)**
|
||||||
|
- **[Redberry](https://redberry.international/laravel/)**
|
||||||
|
- **[Active Logic](https://activelogic.com)**
|
||||||
|
- **[byte5](https://byte5.de)**
|
||||||
|
- **[OP.GG](https://op.gg)**
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
|
||||||
|
|
||||||
|
## Code of Conduct
|
||||||
|
|
||||||
|
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
|
||||||
|
|
||||||
|
## Security Vulnerabilities
|
||||||
|
|
||||||
|
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
|
94
app/application/app/Console/Commands/CreateUserAdmin.php
Normal file
94
app/application/app/Console/Commands/CreateUserAdmin.php
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Dto\User\ManyRoleDto;
|
||||||
|
use App\Enums\SystemRole;
|
||||||
|
use App\Repositories\RoleRepository;
|
||||||
|
use App\Services\User\UserCommandHandler;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Validator as ValidatorFacade;
|
||||||
|
use Illuminate\Validation\Rules\Password;
|
||||||
|
use Illuminate\Validation\Validator;
|
||||||
|
|
||||||
|
final class CreateUserAdmin extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'app:create-user-admin {email} {password}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Create admin user.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle(UserCommandHandler $userCommandHandler, RoleRepository $roleRepository): void
|
||||||
|
{
|
||||||
|
$validator = $this->getData();
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
$this->errorMessageAndStop($validator->errors()->all());
|
||||||
|
}
|
||||||
|
$data = $validator->valid();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$role = $roleRepository->getRoleByCode(SystemRole::Admin->value);
|
||||||
|
if (is_null($role)) {
|
||||||
|
$this->errorMessageAndStop('Administrator role not found.');
|
||||||
|
}
|
||||||
|
$user = DB::transaction(function () use($data, $userCommandHandler, $role) {
|
||||||
|
$data['name'] = 'Administrator';
|
||||||
|
$user = $userCommandHandler->handleStore($data, $data['password']);
|
||||||
|
$userCommandHandler->handleConfirmationByEmail($user);
|
||||||
|
$roles = new ManyRoleDto([$role->id]);
|
||||||
|
$userCommandHandler->handleSyncRoles($user, $roles);
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
});
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->errorMessageAndStop($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info('The command was successful!');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getData(): Validator
|
||||||
|
{
|
||||||
|
return ValidatorFacade::make([
|
||||||
|
'email' => $this->argument('email'),
|
||||||
|
'password' => $this->argument('password'),
|
||||||
|
], [
|
||||||
|
'email' => ['required', 'email', 'unique:users,email'],
|
||||||
|
'password' => ['required', Password::default()],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function stop(): never
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function errorMessageAndStop(string | array $error): never
|
||||||
|
{
|
||||||
|
$this->info('User not created. See error messages below:');
|
||||||
|
|
||||||
|
if (is_array($error)) {
|
||||||
|
foreach ($error as $err) {
|
||||||
|
$this->error($err);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->error($error);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->stop();
|
||||||
|
}
|
||||||
|
}
|
10
app/application/app/Contracts/FormRequestDto.php
Normal file
10
app/application/app/Contracts/FormRequestDto.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
|
||||||
|
interface FormRequestDto
|
||||||
|
{
|
||||||
|
public function getDto(): Dto;
|
||||||
|
}
|
15
app/application/app/Contracts/Models/Storage.php
Normal file
15
app/application/app/Contracts/Models/Storage.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts\Models;
|
||||||
|
|
||||||
|
use App\Enums\StorageType;
|
||||||
|
use App\Models\Storage as StorageModel;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
interface Storage
|
||||||
|
{
|
||||||
|
public function storage(): MorphMany;
|
||||||
|
public function getStorageOne(StorageType $type): ?StorageModel;
|
||||||
|
public function getStorageMany(StorageType $type): Collection;
|
||||||
|
}
|
18
app/application/app/Contracts/Search.php
Normal file
18
app/application/app/Contracts/Search.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
|
use Illuminate\Pagination\CursorPaginator;
|
||||||
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
interface Search
|
||||||
|
{
|
||||||
|
public function __construct(Relation | Builder $query);
|
||||||
|
public function all(): Collection;
|
||||||
|
public function get(int $limit): Collection;
|
||||||
|
public function pagination(int $limit, int $page = 1): LengthAwarePaginator;
|
||||||
|
public function cursorPaginate(int $limit): CursorPaginator;
|
||||||
|
}
|
10
app/application/app/Contracts/ServiceResult.php
Normal file
10
app/application/app/Contracts/ServiceResult.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
interface ServiceResult
|
||||||
|
{
|
||||||
|
public function isSuccess(): bool;
|
||||||
|
public function isError(): bool;
|
||||||
|
}
|
12
app/application/app/Contracts/ServiceResultError.php
Normal file
12
app/application/app/Contracts/ServiceResultError.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
interface ServiceResultError
|
||||||
|
{
|
||||||
|
public function getCode(): ?int;
|
||||||
|
public function getMessage(): string;
|
||||||
|
public function getErrors(): array;
|
||||||
|
public function getErrorsOrMessage(): array|string;
|
||||||
|
public function getData(): array;
|
||||||
|
}
|
11
app/application/app/Contracts/StorageType.php
Normal file
11
app/application/app/Contracts/StorageType.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
interface StorageType
|
||||||
|
{
|
||||||
|
public function getTitle(): string;
|
||||||
|
public function getAcceptMimes(): array;
|
||||||
|
public function getFolderName(): string;
|
||||||
|
public static function cases(): array;
|
||||||
|
}
|
10
app/application/app/Contracts/StorageType/Audio.php
Normal file
10
app/application/app/Contracts/StorageType/Audio.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts\StorageType;
|
||||||
|
|
||||||
|
use App\Contracts\StorageType as StorageTypeContract;
|
||||||
|
|
||||||
|
interface Audio extends StorageTypeContract
|
||||||
|
{
|
||||||
|
public function isAudio(): bool;
|
||||||
|
}
|
10
app/application/app/Contracts/StorageType/Image.php
Normal file
10
app/application/app/Contracts/StorageType/Image.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts\StorageType;
|
||||||
|
|
||||||
|
use App\Contracts\StorageType as StorageTypeContract;
|
||||||
|
|
||||||
|
interface Image extends StorageTypeContract
|
||||||
|
{
|
||||||
|
public function isImage(): bool;
|
||||||
|
}
|
10
app/application/app/Contracts/StorageType/Video.php
Normal file
10
app/application/app/Contracts/StorageType/Video.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts\StorageType;
|
||||||
|
|
||||||
|
use App\Contracts\StorageType as StorageTypeContract;
|
||||||
|
|
||||||
|
interface Video extends StorageTypeContract
|
||||||
|
{
|
||||||
|
public function isVideo(): bool;
|
||||||
|
}
|
17
app/application/app/Dto/Builder/Project.php
Normal file
17
app/application/app/Dto/Builder/Project.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Builder;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
final readonly class Project
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ?bool $isPublic = null,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function isPublic(): ?bool
|
||||||
|
{
|
||||||
|
return $this->isPublic;
|
||||||
|
}
|
||||||
|
}
|
10
app/application/app/Dto/Builder/ProjectFeedback.php
Normal file
10
app/application/app/Dto/Builder/ProjectFeedback.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Builder;
|
||||||
|
|
||||||
|
final readonly class ProjectFeedback
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
|
||||||
|
) { }
|
||||||
|
}
|
10
app/application/app/Dto/Builder/ProjectLink.php
Normal file
10
app/application/app/Dto/Builder/ProjectLink.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Builder;
|
||||||
|
|
||||||
|
final readonly class ProjectLink
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
|
||||||
|
) { }
|
||||||
|
}
|
10
app/application/app/Dto/Builder/Role.php
Normal file
10
app/application/app/Dto/Builder/Role.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Builder;
|
||||||
|
|
||||||
|
final readonly class Role
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
|
||||||
|
) { }
|
||||||
|
}
|
10
app/application/app/Dto/Builder/User.php
Normal file
10
app/application/app/Dto/Builder/User.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Builder;
|
||||||
|
|
||||||
|
final readonly class User
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
|
||||||
|
) { }
|
||||||
|
}
|
21
app/application/app/Dto/HttpUserData.php
Normal file
21
app/application/app/Dto/HttpUserData.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto;
|
||||||
|
|
||||||
|
final readonly class HttpUserData
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ?string $clientIp = null,
|
||||||
|
private ?string $userAgent = null,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getClientIp(): ?string
|
||||||
|
{
|
||||||
|
return $this->clientIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserAgent(): ?string
|
||||||
|
{
|
||||||
|
return $this->userAgent;
|
||||||
|
}
|
||||||
|
}
|
27
app/application/app/Dto/QuerySettingsDto.php
Normal file
27
app/application/app/Dto/QuerySettingsDto.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto;
|
||||||
|
|
||||||
|
final readonly class QuerySettingsDto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private int $limit,
|
||||||
|
private int $page = 1,
|
||||||
|
private array $queryWith = []
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getLimit(): int
|
||||||
|
{
|
||||||
|
return $this->limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPage(): int
|
||||||
|
{
|
||||||
|
return $this->page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getQueryWith(): array
|
||||||
|
{
|
||||||
|
return $this->queryWith;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Language;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
|
||||||
|
final readonly class NewLanguage extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $name,
|
||||||
|
private int $index,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIndex(): int
|
||||||
|
{
|
||||||
|
return $this->index;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Project\About;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
|
||||||
|
final readonly class StoreUpdate extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $title,
|
||||||
|
private string $description,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getTitle(): string
|
||||||
|
{
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Project\Feedback;
|
||||||
|
|
||||||
|
use App\Dto\Builder\ProjectFeedback;
|
||||||
|
use App\Dto\Service\Pages;
|
||||||
|
|
||||||
|
final readonly class Index extends Pages
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ProjectFeedback $projectFeedbackBuilderDto,
|
||||||
|
int $page
|
||||||
|
) {
|
||||||
|
parent::__construct($page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProjectFeedbackBuilderDto(): ProjectFeedback
|
||||||
|
{
|
||||||
|
return $this->projectFeedbackBuilderDto;
|
||||||
|
}
|
||||||
|
}
|
21
app/application/app/Dto/Service/Admin/Project/Index.php
Normal file
21
app/application/app/Dto/Service/Admin/Project/Index.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Project;
|
||||||
|
|
||||||
|
use App\Dto\Builder\Project;
|
||||||
|
use App\Dto\Service\Pages;
|
||||||
|
|
||||||
|
final readonly class Index extends Pages
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private Project $projectBuilderDto,
|
||||||
|
int $page
|
||||||
|
) {
|
||||||
|
parent::__construct($page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProjectBuilderDto(): Project
|
||||||
|
{
|
||||||
|
return $this->projectBuilderDto;
|
||||||
|
}
|
||||||
|
}
|
54
app/application/app/Dto/Service/Admin/Project/Language.php
Normal file
54
app/application/app/Dto/Service/Admin/Project/Language.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Project;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
use App\Enums\Lang;
|
||||||
|
|
||||||
|
final readonly class Language extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $title,
|
||||||
|
private string $code,
|
||||||
|
private int $sort,
|
||||||
|
private bool $isDefault,
|
||||||
|
private ?string $isoCode = null,
|
||||||
|
private ?Lang $systemLang = null,
|
||||||
|
private ?int $id = null,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getTitle(): string
|
||||||
|
{
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCode(): string
|
||||||
|
{
|
||||||
|
return $this->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSort(): int
|
||||||
|
{
|
||||||
|
return $this->sort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDefault(): bool
|
||||||
|
{
|
||||||
|
return $this->isDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIsoCode(): ?string
|
||||||
|
{
|
||||||
|
return $this->isoCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSystemLang(): ?Lang
|
||||||
|
{
|
||||||
|
return $this->systemLang;
|
||||||
|
}
|
||||||
|
}
|
18
app/application/app/Dto/Service/Admin/Project/Languages.php
Normal file
18
app/application/app/Dto/Service/Admin/Project/Languages.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Project;
|
||||||
|
|
||||||
|
final class Languages
|
||||||
|
{
|
||||||
|
private $languages = [];
|
||||||
|
|
||||||
|
public function addLanguage(Language $language): void
|
||||||
|
{
|
||||||
|
$this->languages[] = $language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLanguages(): array
|
||||||
|
{
|
||||||
|
return $this->languages;
|
||||||
|
}
|
||||||
|
}
|
21
app/application/app/Dto/Service/Admin/Project/Link/Index.php
Normal file
21
app/application/app/Dto/Service/Admin/Project/Link/Index.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Project\Link;
|
||||||
|
|
||||||
|
use App\Dto\Builder\ProjectLink;
|
||||||
|
use App\Dto\Service\Pages;
|
||||||
|
|
||||||
|
final readonly class Index extends Pages
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ProjectLink $linkBuilderDto,
|
||||||
|
int $page,
|
||||||
|
) {
|
||||||
|
parent::__construct($page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLinkBuilderDto(): ProjectLink
|
||||||
|
{
|
||||||
|
return $this->linkBuilderDto;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Project\Link;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
|
||||||
|
final readonly class StoreUpdate extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $title,
|
||||||
|
private string $link,
|
||||||
|
private int $sort,
|
||||||
|
private ?int $languageId,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getTitle(): string
|
||||||
|
{
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLink(): string
|
||||||
|
{
|
||||||
|
return $this->link;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSort(): int
|
||||||
|
{
|
||||||
|
return $this->sort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLanguageId(): ?int
|
||||||
|
{
|
||||||
|
return $this->languageId;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Project;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
use App\Dto\Service\Storage\Storages;
|
||||||
|
|
||||||
|
final readonly class StoreUpdate extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $name,
|
||||||
|
private string $code,
|
||||||
|
private bool $isPublic,
|
||||||
|
private Languages $languages,
|
||||||
|
private Storages $storages,
|
||||||
|
private ?string $httpHost,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCode(): string
|
||||||
|
{
|
||||||
|
return $this->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isPublic(): bool
|
||||||
|
{
|
||||||
|
return $this->isPublic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLanguages(): Languages
|
||||||
|
{
|
||||||
|
return $this->languages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHttpHost(): ?string
|
||||||
|
{
|
||||||
|
return $this->httpHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStorages(): Storages
|
||||||
|
{
|
||||||
|
return $this->storages;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Project\Translation;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
|
||||||
|
final readonly class Translation extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $code,
|
||||||
|
private ?string $text
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getCode(): string
|
||||||
|
{
|
||||||
|
return $this->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getText(): ?string
|
||||||
|
{
|
||||||
|
return $this->text;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Project\Translation;
|
||||||
|
|
||||||
|
use App\Exceptions\Dto\Admin\Project\Transaction\TranslationsException;
|
||||||
|
|
||||||
|
final class Translations
|
||||||
|
{
|
||||||
|
private array $translations = [];
|
||||||
|
|
||||||
|
public function addTranslation(string $code, ?string $text): void
|
||||||
|
{
|
||||||
|
if (!in_array($code, self::getTranslationCodes())) {
|
||||||
|
throw new TranslationsException('Translation code "' . $code . '" not available');
|
||||||
|
}
|
||||||
|
$this->translations[] = new Translation($code, $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTranslations(): array
|
||||||
|
{
|
||||||
|
return $this->translations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getTranslationCodes(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'site.Menu',
|
||||||
|
'site.Powered by service',
|
||||||
|
'site.About project',
|
||||||
|
'site.Choose language',
|
||||||
|
'site.Page without translation',
|
||||||
|
'site.Project',
|
||||||
|
'site.Feedback',
|
||||||
|
'site.Feedback-send',
|
||||||
|
'site.required field',
|
||||||
|
'site.attributes.name',
|
||||||
|
'site.attributes.email',
|
||||||
|
'site.attributes.message',
|
||||||
|
'site.Message sent successfully',
|
||||||
|
'Server Error',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Project\Translation;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
|
||||||
|
final readonly class Update extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private Translations $translations,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getTranslations(): Translations
|
||||||
|
{
|
||||||
|
return $this->translations;
|
||||||
|
}
|
||||||
|
}
|
21
app/application/app/Dto/Service/Admin/Role/Index.php
Normal file
21
app/application/app/Dto/Service/Admin/Role/Index.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Role;
|
||||||
|
|
||||||
|
use App\Dto\Builder\Role;
|
||||||
|
use App\Dto\Service\Pages;
|
||||||
|
|
||||||
|
final readonly class Index extends Pages
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private Role $roleBuilderDto,
|
||||||
|
int $page
|
||||||
|
) {
|
||||||
|
parent::__construct($page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRoleBuilderDto(): Role
|
||||||
|
{
|
||||||
|
return $this->roleBuilderDto;
|
||||||
|
}
|
||||||
|
}
|
29
app/application/app/Dto/Service/Admin/Role/StoreUpdate.php
Normal file
29
app/application/app/Dto/Service/Admin/Role/StoreUpdate.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\Role;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
|
||||||
|
final readonly class StoreUpdate extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $name,
|
||||||
|
private ?string $code,
|
||||||
|
private array $permissions,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCode(): ?string
|
||||||
|
{
|
||||||
|
return $this->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPermissions(): array
|
||||||
|
{
|
||||||
|
return $this->permissions;
|
||||||
|
}
|
||||||
|
}
|
21
app/application/app/Dto/Service/Admin/User/Index.php
Normal file
21
app/application/app/Dto/Service/Admin/User/Index.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\User;
|
||||||
|
|
||||||
|
use App\Dto\Builder\User;
|
||||||
|
use App\Dto\Service\Pages;
|
||||||
|
|
||||||
|
final readonly class Index extends Pages
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private User $userBuilderDto,
|
||||||
|
int $page
|
||||||
|
) {
|
||||||
|
parent::__construct($page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserBuilderDto(): User
|
||||||
|
{
|
||||||
|
return $this->userBuilderDto;
|
||||||
|
}
|
||||||
|
}
|
36
app/application/app/Dto/Service/Admin/User/StoreUpdate.php
Normal file
36
app/application/app/Dto/Service/Admin/User/StoreUpdate.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Admin\User;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
use App\Dto\User\ManyRoleDto;
|
||||||
|
|
||||||
|
final readonly class StoreUpdate extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $name,
|
||||||
|
private string $email,
|
||||||
|
private ManyRoleDto $roles,
|
||||||
|
private ?string $password = null
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEmail(): string
|
||||||
|
{
|
||||||
|
return $this->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPassword(): ?string
|
||||||
|
{
|
||||||
|
return $this->password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRoles(): ManyRoleDto
|
||||||
|
{
|
||||||
|
return $this->roles;
|
||||||
|
}
|
||||||
|
}
|
27
app/application/app/Dto/Service/Authorization.php
Normal file
27
app/application/app/Dto/Service/Authorization.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service;
|
||||||
|
|
||||||
|
final readonly class Authorization extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $email,
|
||||||
|
private string $password,
|
||||||
|
private bool $remember = false
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getEmail(): string
|
||||||
|
{
|
||||||
|
return $this->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPassword(): string
|
||||||
|
{
|
||||||
|
return $this->password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRemember(): bool
|
||||||
|
{
|
||||||
|
return $this->remember;
|
||||||
|
}
|
||||||
|
}
|
8
app/application/app/Dto/Service/Dto.php
Normal file
8
app/application/app/Dto/Service/Dto.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service;
|
||||||
|
|
||||||
|
abstract readonly class Dto
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
15
app/application/app/Dto/Service/Pages.php
Normal file
15
app/application/app/Dto/Service/Pages.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service;
|
||||||
|
|
||||||
|
abstract readonly class Pages extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private int $page
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getPage(): int
|
||||||
|
{
|
||||||
|
return $this->page;
|
||||||
|
}
|
||||||
|
}
|
17
app/application/app/Dto/Service/Private/Profile/Update.php
Normal file
17
app/application/app/Dto/Service/Private/Profile/Update.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Private\Profile;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
|
||||||
|
final readonly class Update extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $name
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Private\Profile;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
use App\Enums\Lang;
|
||||||
|
|
||||||
|
final readonly class UpdateSettings extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ?Lang $lang,
|
||||||
|
private ?string $timezone
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getLang(): ?Lang
|
||||||
|
{
|
||||||
|
return $this->lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTimezone(): ?string
|
||||||
|
{
|
||||||
|
return $this->timezone;
|
||||||
|
}
|
||||||
|
}
|
36
app/application/app/Dto/Service/Site/Feedback/Send.php
Normal file
36
app/application/app/Dto/Service/Site/Feedback/Send.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Site\Feedback;
|
||||||
|
|
||||||
|
use App\Dto\HttpUserData;
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
|
||||||
|
final readonly class Send extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $message,
|
||||||
|
private HttpUserData $httpUserData,
|
||||||
|
private ?string $name,
|
||||||
|
private ?string $email,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getName(): ?string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEmail(): ?string
|
||||||
|
{
|
||||||
|
return $this->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMessage(): string
|
||||||
|
{
|
||||||
|
return $this->message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHttpUserData(): HttpUserData
|
||||||
|
{
|
||||||
|
return $this->httpUserData;
|
||||||
|
}
|
||||||
|
}
|
29
app/application/app/Dto/Service/Storage/File.php
Normal file
29
app/application/app/Dto/Service/Storage/File.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Storage;
|
||||||
|
|
||||||
|
use App\Contracts\StorageType;
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
use App\Exceptions\Dto\Storage\FileException;
|
||||||
|
|
||||||
|
final readonly class File extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private int $id,
|
||||||
|
private StorageType $storageType,
|
||||||
|
) {
|
||||||
|
if ($this->id < 1) {
|
||||||
|
throw new FileException('ID cannot be equal to or less than zero: ' . $this->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId(): int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStorageType(): StorageType
|
||||||
|
{
|
||||||
|
return $this->storageType;
|
||||||
|
}
|
||||||
|
}
|
57
app/application/app/Dto/Service/Storage/Storage.php
Normal file
57
app/application/app/Dto/Service/Storage/Storage.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Storage;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
use App\Enums\StorageType;
|
||||||
|
use app\Exceptions\Dto\Storage\StorageException;
|
||||||
|
|
||||||
|
final readonly class Storage extends Dto
|
||||||
|
{
|
||||||
|
private ?File $file;
|
||||||
|
private bool $isDelete;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
array $data,
|
||||||
|
private StorageType $storageType,
|
||||||
|
private bool $isMany,
|
||||||
|
) {
|
||||||
|
$file = null;
|
||||||
|
if (isset($data['file'])) {
|
||||||
|
if ((int) $data['file'] <= 0) {
|
||||||
|
throw new StorageException('ID cannot be equal to or less than zero: ' . $data['file']);
|
||||||
|
}
|
||||||
|
$file = new File(
|
||||||
|
id: (int) $data['file'],
|
||||||
|
storageType: $this->storageType,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->file = $file;
|
||||||
|
$this->isDelete = !empty($data['delete']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFile(): ?File
|
||||||
|
{
|
||||||
|
return $this->file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDelete(): bool
|
||||||
|
{
|
||||||
|
return $this->isDelete;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isFile(): bool
|
||||||
|
{
|
||||||
|
return \is_null($this->file) === false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStorageType(): StorageType
|
||||||
|
{
|
||||||
|
return $this->storageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isMany(): bool
|
||||||
|
{
|
||||||
|
return $this->isMany;
|
||||||
|
}
|
||||||
|
}
|
73
app/application/app/Dto/Service/Storage/Storages.php
Normal file
73
app/application/app/Dto/Service/Storage/Storages.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Storage;
|
||||||
|
|
||||||
|
use App\Enums\StorageType;
|
||||||
|
use app\Exceptions\Dto\Storage\StoragesException;
|
||||||
|
|
||||||
|
final class Storages
|
||||||
|
{
|
||||||
|
private array $storages = [];
|
||||||
|
|
||||||
|
public function add(array $data, StorageType $type): void
|
||||||
|
{
|
||||||
|
if (isset($this->storages[$type->value])) {
|
||||||
|
throw new StoragesException('You cannot attach two files of the same type!');
|
||||||
|
}
|
||||||
|
$this->storages[$type->value] = new Storage(data: $data, storageType: $type, isMany: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addMany(array $data, StorageType $type): void
|
||||||
|
{
|
||||||
|
if (!isset($this->storages[$type->value])) {
|
||||||
|
$this->storages[$type->value] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($data as $storageData) {
|
||||||
|
$this->storages[$type->value][] = new Storage(data: $storageData, storageType: $type, isMany: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toArray(): array
|
||||||
|
{
|
||||||
|
return $this->storages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllStorageIds(): array
|
||||||
|
{
|
||||||
|
$ids = [];
|
||||||
|
foreach ($this->storages as $storage) {
|
||||||
|
/** @var Storage $storage */
|
||||||
|
if (!is_array($storage)) {
|
||||||
|
if ($storage->isFile() && !$storage->isDelete()) {
|
||||||
|
$ids[] = $storage->getFile()->getId();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach ($storage as $storageOne) {
|
||||||
|
/** @var Storage $storageOne */
|
||||||
|
if ($storageOne->isFile() && !$storageOne->isDelete()) {
|
||||||
|
$ids[] = $storageOne->getFile()->getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllStorages(): array
|
||||||
|
{
|
||||||
|
$storages = [];
|
||||||
|
foreach ($this->storages as $storage) {
|
||||||
|
if (!is_array($storage)) {
|
||||||
|
$storages[] = $storage;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach ($storage as $storageOne) {
|
||||||
|
$storages[] = $storageOne;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $storages;
|
||||||
|
}
|
||||||
|
}
|
32
app/application/app/Dto/Service/Storage/Upload.php
Normal file
32
app/application/app/Dto/Service/Storage/Upload.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\Storage;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
use App\Enums\Morph;
|
||||||
|
use App\Enums\StorageType;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
|
||||||
|
final readonly class Upload extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private UploadedFile $file,
|
||||||
|
private StorageType $storageType,
|
||||||
|
private Morph $morph,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getFile(): UploadedFile
|
||||||
|
{
|
||||||
|
return $this->file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStorageType(): StorageType
|
||||||
|
{
|
||||||
|
return $this->storageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMorph(): Morph
|
||||||
|
{
|
||||||
|
return $this->morph;
|
||||||
|
}
|
||||||
|
}
|
17
app/application/app/Dto/Service/User/UpdatePassword.php
Normal file
17
app/application/app/Dto/Service/User/UpdatePassword.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\Service\User;
|
||||||
|
|
||||||
|
use App\Dto\Service\Dto;
|
||||||
|
|
||||||
|
final readonly class UpdatePassword extends Dto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $password
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function getPassword(): string
|
||||||
|
{
|
||||||
|
return $this->password;
|
||||||
|
}
|
||||||
|
}
|
32
app/application/app/Dto/User/ManyRoleDto.php
Normal file
32
app/application/app/Dto/User/ManyRoleDto.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Dto\User;
|
||||||
|
|
||||||
|
use App\Exceptions\Dto\User\ManyRoleDtoException;
|
||||||
|
|
||||||
|
final class ManyRoleDto
|
||||||
|
{
|
||||||
|
private array $roles = [];
|
||||||
|
|
||||||
|
public function __construct(array $roles = []) {
|
||||||
|
foreach ($roles as $role) {
|
||||||
|
if (!is_numeric($role) || is_float($role)) {
|
||||||
|
throw new ManyRoleDtoException('Not an integer: ' . $role . '.');
|
||||||
|
}
|
||||||
|
$this->add((int) $role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add(int $id): void
|
||||||
|
{
|
||||||
|
if ($id < 1) {
|
||||||
|
throw new ManyRoleDtoException('Only Integer > 0.');
|
||||||
|
}
|
||||||
|
$this->roles[] = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toArray(): array
|
||||||
|
{
|
||||||
|
return $this->roles;
|
||||||
|
}
|
||||||
|
}
|
17
app/application/app/Enums/CacheTag.php
Normal file
17
app/application/app/Enums/CacheTag.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use Illuminate\Cache\TaggedCache;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
enum CacheTag: string
|
||||||
|
{
|
||||||
|
case Project = 'project';
|
||||||
|
case ProjectTranslation = 'project_translation';
|
||||||
|
|
||||||
|
public function getCache(): TaggedCache
|
||||||
|
{
|
||||||
|
return Cache::tags($this->value);
|
||||||
|
}
|
||||||
|
}
|
46
app/application/app/Enums/Lang.php
Normal file
46
app/application/app/Enums/Lang.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
enum Lang: int
|
||||||
|
{
|
||||||
|
case Ru = 1;
|
||||||
|
case En = 2;
|
||||||
|
|
||||||
|
public function getTitle(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Ru => 'Русский',
|
||||||
|
self::En => 'English'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLocale(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Ru => 'ru',
|
||||||
|
self::En => 'en'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function toArray(): array
|
||||||
|
{
|
||||||
|
$choices = [];
|
||||||
|
foreach (self::cases() as $lang) {
|
||||||
|
$choices[] = [
|
||||||
|
'name' => $lang->name,
|
||||||
|
'value' => $lang->value,
|
||||||
|
'title' => $lang->getTitle(),
|
||||||
|
'locale' => $lang->getLocale()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $choices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function toCollection(): Collection
|
||||||
|
{
|
||||||
|
return collect(self::toArray());
|
||||||
|
}
|
||||||
|
}
|
31
app/application/app/Enums/Morph.php
Normal file
31
app/application/app/Enums/Morph.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use App\Models\Project;
|
||||||
|
|
||||||
|
enum Morph: int
|
||||||
|
{
|
||||||
|
case Project = 1;
|
||||||
|
|
||||||
|
public function getPathModel(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Project => Project::class,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFolderName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function map(): array
|
||||||
|
{
|
||||||
|
$map = [];
|
||||||
|
foreach (self::cases() as $item) {
|
||||||
|
$map[$item->value] = $item->getPathModel();
|
||||||
|
}
|
||||||
|
return $map;
|
||||||
|
}
|
||||||
|
}
|
78
app/application/app/Enums/Permission.php
Normal file
78
app/application/app/Enums/Permission.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum Permission: string
|
||||||
|
{
|
||||||
|
case AdminPanel = 'allow-admin-panel';
|
||||||
|
case Role = 'role';
|
||||||
|
case User = 'user';
|
||||||
|
case Project = 'project';
|
||||||
|
case ProjectContent = 'project-content';
|
||||||
|
case ProjectLink = 'project-link';
|
||||||
|
case ProjectTranslation = 'project-translation';
|
||||||
|
case ProjectFeedback = 'project-feedback';
|
||||||
|
|
||||||
|
public function getPermissions(): array
|
||||||
|
{
|
||||||
|
$permissions = match ($this) {
|
||||||
|
self::AdminPanel => [
|
||||||
|
'view' => __('permissions.Administrative panel allowed'),
|
||||||
|
],
|
||||||
|
self::ProjectContent => [
|
||||||
|
'view' => __('permissions.Allowed to watch'),
|
||||||
|
'create' => __('permissions.Allowed to create'),
|
||||||
|
'update' => __('permissions.Allowed to edit'),
|
||||||
|
],
|
||||||
|
self::ProjectTranslation => [
|
||||||
|
'view' => __('permissions.Allowed to watch'),
|
||||||
|
'update' => __('permissions.Allowed to edit'),
|
||||||
|
],
|
||||||
|
self::ProjectFeedback => [
|
||||||
|
'view' => __('permissions.Allowed to watch'),
|
||||||
|
],
|
||||||
|
default => $this->getBasePermissions()
|
||||||
|
};
|
||||||
|
|
||||||
|
return $permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle(): string
|
||||||
|
{
|
||||||
|
return __('permissions.' . $this->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function formatValue(string $permission): string
|
||||||
|
{
|
||||||
|
return $this->value . '.' . $permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function toArrayList(): array
|
||||||
|
{
|
||||||
|
$permissions = [];
|
||||||
|
foreach (self::cases() as $permissionEnum) {
|
||||||
|
foreach ($permissionEnum->getPermissions() as $permissionName => $permissionTitle) {
|
||||||
|
$name = $permissionEnum->formatValue($permissionName);
|
||||||
|
$title = $permissionEnum->getTitle() . ' - ' . $permissionTitle;
|
||||||
|
$permissions[$name] = $title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function toArrayListCodes(): array
|
||||||
|
{
|
||||||
|
return \array_keys(self::toArrayList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getBasePermissions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'view' => __('permissions.Allowed to watch'),
|
||||||
|
'create' => __('permissions.Allowed to create'),
|
||||||
|
'update' => __('permissions.Allowed to edit'),
|
||||||
|
'delete' => __('permissions.Allowed to delete'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
38
app/application/app/Enums/Site/ProjectSection.php
Normal file
38
app/application/app/Enums/Site/ProjectSection.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums\Site;
|
||||||
|
|
||||||
|
use App\Models\Project;
|
||||||
|
use App\Models\ProjectLanguage;
|
||||||
|
|
||||||
|
enum ProjectSection
|
||||||
|
{
|
||||||
|
case Home;
|
||||||
|
case Feedback;
|
||||||
|
case FeedbackSend;
|
||||||
|
|
||||||
|
public function url(Project $project, ?ProjectLanguage $language = null): string
|
||||||
|
{
|
||||||
|
$parameters = [];
|
||||||
|
$prefixProject = '';
|
||||||
|
if ($project->http_host === null) {
|
||||||
|
$prefixProject = 'project.';
|
||||||
|
$parameters['project'] = $project->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prefixLanguage = '';
|
||||||
|
if ($language?->is_default === false) {
|
||||||
|
$parameters['language'] = $language->code;
|
||||||
|
$prefixLanguage = '-language';
|
||||||
|
}
|
||||||
|
|
||||||
|
$route = match ($this) {
|
||||||
|
self::Home => \route($prefixProject . 'home' . $prefixLanguage, $parameters, false),
|
||||||
|
|
||||||
|
self::Feedback => \route($prefixProject . 'feedback' . $prefixLanguage, $parameters, false),
|
||||||
|
self::FeedbackSend => \route($prefixProject . 'feedback.send' . $prefixLanguage, $parameters, false),
|
||||||
|
};
|
||||||
|
|
||||||
|
return $project->http_host . $route;
|
||||||
|
}
|
||||||
|
}
|
53
app/application/app/Enums/StorageType.php
Normal file
53
app/application/app/Enums/StorageType.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use App\Contracts\StorageType\Audio;
|
||||||
|
use App\Contracts\StorageType\Image;
|
||||||
|
use App\Contracts\StorageType\Video;
|
||||||
|
|
||||||
|
enum StorageType: int implements Image, Video, Audio
|
||||||
|
{
|
||||||
|
case Logo = 1;
|
||||||
|
|
||||||
|
public function getTitle(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Logo => __('validation.attributes.logo'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAcceptMimes(): array
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Logo => ['jpeg', 'jpg', 'png'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isImage(): bool
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Logo => true,
|
||||||
|
default => false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isVideo(): bool
|
||||||
|
{
|
||||||
|
return match ($this->name) {
|
||||||
|
default => false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isAudio(): bool
|
||||||
|
{
|
||||||
|
return match ($this->name) {
|
||||||
|
default => false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFolderName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
}
|
9
app/application/app/Enums/SystemRole.php
Normal file
9
app/application/app/Enums/SystemRole.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum SystemRole: string
|
||||||
|
{
|
||||||
|
case Admin = 'admin';
|
||||||
|
case AdminProject = 'admin-project';
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Exceptions\Dto\Admin\Project\Transaction;
|
||||||
|
|
||||||
|
final class TranslationsException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Exceptions\Dto\Storage;
|
||||||
|
|
||||||
|
final class FileException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace app\Exceptions\Dto\Storage;
|
||||||
|
|
||||||
|
final class StorageException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace app\Exceptions\Dto\Storage;
|
||||||
|
|
||||||
|
final class StoragesException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Exceptions\Dto\User;
|
||||||
|
|
||||||
|
final class ManyRoleDtoException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace app\Exceptions\Services\Storage;
|
||||||
|
|
||||||
|
final class StorageCommandHandlerException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Exceptions\Services\Storage;
|
||||||
|
|
||||||
|
final class StorageSaveFileException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
40
app/application/app/Helpers/Helpers.php
Normal file
40
app/application/app/Helpers/Helpers.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
final readonly class Helpers
|
||||||
|
{
|
||||||
|
public static function getTimeZoneList(): Collection
|
||||||
|
{
|
||||||
|
return Cache::rememberForever('timezones_list_collection', function () {
|
||||||
|
$timezone = [];
|
||||||
|
foreach (timezone_identifiers_list(\DateTimeZone::ALL) as $key => $value) {
|
||||||
|
$timezone[$value] = $value . ' (UTC ' . now($value)->format('P') . ')';
|
||||||
|
}
|
||||||
|
return collect($timezone)->sortKeys();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getUserTimeZone() {
|
||||||
|
return auth()->user()?->timezone ?? config('app.user_timezone');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $name = 'field[key]' return 'field.key'
|
||||||
|
*/
|
||||||
|
public static function formatAttributeNameToRequestName(string $name): string
|
||||||
|
{
|
||||||
|
return Str::of($name)
|
||||||
|
->replace(
|
||||||
|
['.', '[', ']'],
|
||||||
|
['_', '.', ''],
|
||||||
|
)
|
||||||
|
->rtrim('.')
|
||||||
|
->value();
|
||||||
|
}
|
||||||
|
}
|
10
app/application/app/Http/Controllers/Admin/Controller.php
Normal file
10
app/application/app/Http/Controllers/Admin/Controller.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller as BaseController;
|
||||||
|
|
||||||
|
abstract class Controller extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
final class DashboardController extends Controller
|
||||||
|
{
|
||||||
|
public function index(): View
|
||||||
|
{
|
||||||
|
return view('admin/dashboard/index');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Http\Requests\Admin\Languages\NewLanguageRequest;
|
||||||
|
use App\Http\Resources\Admin\Languages\NewLanguage;
|
||||||
|
use App\Services\Admin\LanguageService;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
final class LanguagesController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly LanguageService $languageService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function newLanguage(NewLanguageRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$result = $this->languageService->newLanguage($request->getDto());
|
||||||
|
if ($result->isError()) {
|
||||||
|
return response()->json($result->getData())->setStatusCode($result->getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(new NewLanguage($result));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin\Projects;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
|
use App\Http\Requests\Admin\Projects\About\StoreUpdateRequest;
|
||||||
|
use App\Services\Admin\Project\AboutService;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
final class AboutController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly AboutService $aboutService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function languages(int $project, Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->aboutService->languages($project, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/projects/about/languages', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(int $project, int $language, Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->aboutService->edit($project, $language, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/projects/about/edit', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(int $project, int $language, StoreUpdateRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->aboutService->storeOrUpdate($project, $language, $data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.projects.about.edit', [
|
||||||
|
'project' => $project,
|
||||||
|
'language' => $language,
|
||||||
|
])->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin\Projects;
|
||||||
|
|
||||||
|
use App\Dto\QuerySettingsDto;
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
|
use App\Http\Requests\Admin\Projects\Feedbacks\IndexRequest;
|
||||||
|
use App\Services\Admin\Project\FeedbackService;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
final class FeedbacksController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly FeedbackService $feedbackService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function index(IndexRequest $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$data = $request->getDto();
|
||||||
|
$querySettingsDto = new QuerySettingsDto(
|
||||||
|
limit: 20,
|
||||||
|
page: $data->getPage(),
|
||||||
|
queryWith: ['project']
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $this->feedbackService->index($data->getProjectFeedbackBuilderDto(), $querySettingsDto, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin.projects.feedbacks.index', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function project(int $projectId, IndexRequest $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$data = $request->getDto();
|
||||||
|
$querySettingsDto = new QuerySettingsDto(
|
||||||
|
limit: 20,
|
||||||
|
page: $data->getPage(),
|
||||||
|
queryWith: []
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $this->feedbackService->project($projectId, $data->getProjectFeedbackBuilderDto(), $querySettingsDto, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin.projects.feedbacks.project', $result->getData());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,100 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin\Projects;
|
||||||
|
|
||||||
|
use App\Dto\QuerySettingsDto;
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
|
use App\Http\Requests\Admin\Projects\Links\IndexRequest;
|
||||||
|
use App\Http\Requests\Admin\Projects\Links\StoreUpdateRequest;
|
||||||
|
use App\Services\Admin\Project\LinkService;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
final class LinksController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly LinkService $linkService
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function index(int $projectId, IndexRequest $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$data = $request->getDto();
|
||||||
|
$querySettingsDto = new QuerySettingsDto(
|
||||||
|
limit: 20,
|
||||||
|
page: $data->getPage(),
|
||||||
|
queryWith: ['language']
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $this->linkService->index($projectId, $data->getLinkBuilderDto(), $querySettingsDto, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/projects/links/index', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(int $projectId, Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->linkService->create($projectId, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/projects/links/create', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(int $projectId, int $id, Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->linkService->edit($projectId, $id, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/projects/links/edit', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(int $projectId, StoreUpdateRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->linkService->store($projectId, $data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.projects.links.edit', [
|
||||||
|
'project' => $projectId,
|
||||||
|
'link' => $result->getModel()->id,
|
||||||
|
])->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(int $projectId, int $id, StoreUpdateRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->linkService->update($projectId, $id, $data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.projects.links.edit', [
|
||||||
|
'project' => $projectId,
|
||||||
|
'link' => $result->getModel()->id,
|
||||||
|
])->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(int $projectId, int $id, Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->linkService->destroy($projectId, $id, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.projects.links.index', ['project' => $projectId])->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin\Projects;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Admin\Projects\Translations\UpdateRequest;
|
||||||
|
use App\Services\Admin\Project\TranslationService;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
final class TranslationsController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly TranslationService $translationService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function languages(int $projectId, Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->translationService->languages($projectId, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/projects/translations/languages', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(int $projectId, int $languageId, Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->translationService->edit($projectId, $languageId, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/projects/translations/edit', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(int $projectId, int $languageId, UpdateRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$data = $request->getDto();
|
||||||
|
$result = $this->translationService->update($projectId, $languageId, $data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.projects.translations.edit', [
|
||||||
|
'project' => $projectId,
|
||||||
|
'language' => $languageId,
|
||||||
|
])->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,104 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Dto\QuerySettingsDto;
|
||||||
|
use App\Http\Requests\Admin\Projects\IndexRequest;
|
||||||
|
use App\Http\Requests\Admin\Projects\StoreUpdateRequest;
|
||||||
|
use App\Services\Admin\ProjectService;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
final class ProjectsController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly ProjectService $projectService
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function index(IndexRequest $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$data = $request->getDto();
|
||||||
|
$querySettingsDto = new QuerySettingsDto(
|
||||||
|
limit: 20,
|
||||||
|
page: $data->getPage(),
|
||||||
|
queryWith: []
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $this->projectService->index($data->getProjectBuilderDto(), $querySettingsDto, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/projects/index', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show(int $id, Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->projectService->show($id, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/projects/show', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->projectService->create($user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/projects/create', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(int $id, Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->projectService->edit($id, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/projects/edit', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(StoreUpdateRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->projectService->store($data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.projects.edit', $result->getModel())->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(int $id, StoreUpdateRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->projectService->update($id, $data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.projects.edit', $result->getModel())->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(int $id, Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->projectService->destroy($id, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.projects.index')->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Dto\QuerySettingsDto;
|
||||||
|
use App\Http\Requests\Admin\Roles\IndexRequest;
|
||||||
|
use App\Http\Requests\Admin\Roles\StoreUpdateRequest;
|
||||||
|
use App\Services\Admin\RoleService;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
final class RolesController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly RoleService $roleService
|
||||||
|
) { }
|
||||||
|
public function index(IndexRequest $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$data = $request->getDto();
|
||||||
|
$querySettingsDto = new QuerySettingsDto(
|
||||||
|
limit: 20,
|
||||||
|
page: $data->getPage(),
|
||||||
|
queryWith: ['morph']
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $this->roleService->index($data->getRoleBuilderDto(), $querySettingsDto, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/roles/index', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->roleService->create($user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/roles/create', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(int $id, Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->roleService->edit($id, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/roles/edit', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(StoreUpdateRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->roleService->store($data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.roles.edit', $result->getModel())->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(int $id, StoreUpdateRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->roleService->update($id, $data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.roles.edit', $result->getModel())->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(int $id, Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->roleService->destroy($id, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.roles.index')->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
}
|
106
app/application/app/Http/Controllers/Admin/UsersController.php
Normal file
106
app/application/app/Http/Controllers/Admin/UsersController.php
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Dto\QuerySettingsDto;
|
||||||
|
use App\Http\Requests\Admin\Users\IndexRequest;
|
||||||
|
use App\Http\Requests\Admin\Users\StoreUpdateRequest;
|
||||||
|
use App\Http\Requests\Admin\Users\UpdatePasswordRequest;
|
||||||
|
use App\Services\Admin\UserService;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
final class UsersController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly UserService $userService
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function index(IndexRequest $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$data = $request->getDto();
|
||||||
|
$querySettingsDto = new QuerySettingsDto(
|
||||||
|
limit: 20,
|
||||||
|
page: $data->getPage(),
|
||||||
|
queryWith: []
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $this->userService->index($data->getUserBuilderDto(), $querySettingsDto, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/users/index', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->userService->create($user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/users/create', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(int $id, Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->userService->edit($id, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin/users/edit', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(StoreUpdateRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->userService->store($data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.users.edit', $result->getModel())->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(int $id, StoreUpdateRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->userService->update($id, $data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.users.edit', $result->getModel())->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatePassword(int $id, UpdatePasswordRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->userService->updatePassword($id, $data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.users.edit', $result->getModel())->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(int $id, Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->userService->destroy($id, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.users.index')->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
}
|
47
app/application/app/Http/Controllers/AuthController.php
Normal file
47
app/application/app/Http/Controllers/AuthController.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Requests\AuthorizationRequest;
|
||||||
|
use App\Services\AuthService;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
final class AuthController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly AuthService $authService
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function login(): View
|
||||||
|
{
|
||||||
|
return view('login');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function authorization(AuthorizationRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$authorization = $request->getDto();
|
||||||
|
$result = $this->authService->authorization($authorization);
|
||||||
|
if ($result->isError()) {
|
||||||
|
if ($result->getCode() === Response::HTTP_UNAUTHORIZED) {
|
||||||
|
Log::warning('Unauthorized ' . $authorization->getEmail() . ' [' . $request->getClientIp() . ']');
|
||||||
|
}
|
||||||
|
return redirect()->route('login')->withInput()->withErrors($result->getMessage());
|
||||||
|
}
|
||||||
|
$request->session()->regenerate();
|
||||||
|
Log::notice('Logged in ' . $authorization->getEmail() . ' [' . $request->getClientIp() . ']');
|
||||||
|
return redirect()->route('admin.home');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logout(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
Auth::logout();
|
||||||
|
$request->session()->invalidate();
|
||||||
|
$request->session()->regenerateToken();
|
||||||
|
return redirect(route('login'));
|
||||||
|
}
|
||||||
|
}
|
18
app/application/app/Http/Controllers/Controller.php
Normal file
18
app/application/app/Http/Controllers/Controller.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Contracts\ServiceResultError as ServiceResultErrorContract;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
abstract class Controller
|
||||||
|
{
|
||||||
|
final protected function errors(ServiceResultErrorContract $result): never
|
||||||
|
{
|
||||||
|
if ($result->getCode() === Response::HTTP_UNPROCESSABLE_ENTITY) {
|
||||||
|
redirect()->back()->withInput()->withErrors($result->getErrors());
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
abort($result->getCode(), $result->getMessage());
|
||||||
|
}
|
||||||
|
}
|
10
app/application/app/Http/Controllers/Private/Controller.php
Normal file
10
app/application/app/Http/Controllers/Private/Controller.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Private;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller as BaseController;
|
||||||
|
|
||||||
|
abstract class Controller extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Private;
|
||||||
|
|
||||||
|
use App\Enums\Lang;
|
||||||
|
use App\Helpers\Helpers;
|
||||||
|
use App\Http\Requests\Private\Profile\UpdatePasswordRequest;
|
||||||
|
use App\Http\Requests\Private\Profile\UpdateRequest;
|
||||||
|
use App\Http\Requests\Private\Profile\UpdateSettingsRequest;
|
||||||
|
use App\Services\Private\ProfileService;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
final class ProfileController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly ProfileService $profileService
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function profile(Request $request): View
|
||||||
|
{
|
||||||
|
return view('private/profile/profile', [
|
||||||
|
'user' => $request->user()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settings(Request $request): View
|
||||||
|
{
|
||||||
|
return view('private/profile/settings', [
|
||||||
|
'user' => $request->user(),
|
||||||
|
'languages' => Lang::toCollection()->pluck(value: 'title', key: 'value')->toArray(),
|
||||||
|
'timezone' => Helpers::getTimeZoneList()->toArray(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(UpdateRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
$result = $this->profileService->update($data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getMessage());
|
||||||
|
}
|
||||||
|
return redirect()->route('profile.edit')->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatePassword(UpdatePasswordRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
$result = $this->profileService->updatePassword($data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getMessage());
|
||||||
|
}
|
||||||
|
return redirect()->route('profile.edit')->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSettings(UpdateSettingsRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
$result = $this->profileService->updateSettings($data, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getMessage());
|
||||||
|
}
|
||||||
|
return redirect()->route('profile.settings')->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
}
|
18
app/application/app/Http/Controllers/Site/Controller.php
Normal file
18
app/application/app/Http/Controllers/Site/Controller.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Site;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller as BaseController;
|
||||||
|
use app\ServiceResults\Site\PagePossibleWithoutTranslation;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
abstract class Controller extends BaseController
|
||||||
|
{
|
||||||
|
protected function viewPageWithoutTranslation(PagePossibleWithoutTranslation $result): View
|
||||||
|
{
|
||||||
|
return \view('site.page-without-translation', [
|
||||||
|
'project' => $result->getProject(),
|
||||||
|
'websiteTranslations' => $result->getWebsiteTranslations(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Site;
|
||||||
|
|
||||||
|
use App\Http\Requests\Site\Feedback\SendRequest;
|
||||||
|
use App\Models\ProjectFeedback;
|
||||||
|
use App\Services\Site\FeedbackService;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
final class FeedbackController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly FeedbackService $feedbackService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function index(Request $request): View
|
||||||
|
{
|
||||||
|
return view('site.feedback.index', [
|
||||||
|
'project' => $request->get('project'),
|
||||||
|
'websiteTranslations' => $request->get('websiteTranslations'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function send(SendRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$project = $request->get('project');
|
||||||
|
$websiteTranslations = $request->get('websiteTranslations');
|
||||||
|
$user = $request->user();
|
||||||
|
$data = $request->getDto();
|
||||||
|
|
||||||
|
$result = $this->feedbackService->send($data, $project, $websiteTranslations, $user);
|
||||||
|
if ($result->isError()) {
|
||||||
|
return redirect()->back()->withInput()->withErrors($result->getErrorsOrMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = \App\Enums\Site\ProjectSection::Feedback->url($project, $websiteTranslations->getLanguage());
|
||||||
|
return redirect($url)->withSuccess($result->getMessage());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Site;
|
||||||
|
|
||||||
|
use App\Services\Site\ProjectService;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
final class ProjectsController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly ProjectService $projectService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function index(Request $request): View
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
$project = $request->get('project');
|
||||||
|
$websiteTranslations = $request->get('websiteTranslations');
|
||||||
|
|
||||||
|
if (\is_null($project)) {
|
||||||
|
$with = ['storage'];
|
||||||
|
$result = $this->projectService->getProjects($user, $with);
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return \view('site.projects.index', $result->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->projectService->getAboutByProject($project, $websiteTranslations, $request->user());
|
||||||
|
if ($result->isError()) {
|
||||||
|
$this->errors($result);
|
||||||
|
}
|
||||||
|
if ($result->isTranslation()) {
|
||||||
|
return $this->viewPageWithoutTranslation($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return \view('site.projects.about', $result->getData());
|
||||||
|
}
|
||||||
|
}
|
10
app/application/app/Http/Controllers/Storage/Controller.php
Normal file
10
app/application/app/Http/Controllers/Storage/Controller.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Storage;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller as BaseController;
|
||||||
|
|
||||||
|
abstract class Controller extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Storage;
|
||||||
|
|
||||||
|
use App\Http\Requests\Storage\ImageRequest;
|
||||||
|
use App\Http\Resources\Storage\Upload;
|
||||||
|
use App\Services\Storage\ImageService;
|
||||||
|
|
||||||
|
final class ImagesController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly ImageService $imageService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public function uploadAndResize(ImageRequest $request)
|
||||||
|
{
|
||||||
|
$data = $request->getDto();
|
||||||
|
$user = $request->user();
|
||||||
|
$result = $this->imageService->uploadAndResize($data, $user);
|
||||||
|
|
||||||
|
if (!$result->isSuccess()) {
|
||||||
|
return response()->json($result->getData())->setStatusCode($result->getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(new Upload($result->getStorage()));
|
||||||
|
}
|
||||||
|
}
|
26
app/application/app/Http/Middleware/AdminPanel.php
Normal file
26
app/application/app/Http/Middleware/AdminPanel.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
final class AdminPanel
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||||
|
*/
|
||||||
|
public function handle(Request $request, Closure $next): Response
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
$request->user() === null || $request->user()->cannot('AdminPanel')
|
||||||
|
) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
48
app/application/app/Http/Middleware/ProjectAndLanguage.php
Normal file
48
app/application/app/Http/Middleware/ProjectAndLanguage.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Enums\CacheTag;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
class ProjectAndLanguage extends ProjectLanguage
|
||||||
|
{
|
||||||
|
public function handle(Request $request, Closure $next): Response
|
||||||
|
{
|
||||||
|
$projectCode = $request->route()?->parameter('project');
|
||||||
|
if ($projectCode === null) {
|
||||||
|
abort(Response::HTTP_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
$seconds = 3600;
|
||||||
|
$project = CacheTag::Project->getCache()->remember(self::class . $projectCode, $seconds, function () use ($projectCode) {
|
||||||
|
return $this->projectRepository->getProjectByCode($projectCode) ?? false;
|
||||||
|
});
|
||||||
|
if ($project === false) {
|
||||||
|
abort(Response::HTTP_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
$project->http_host !== null
|
||||||
|
&& $project->http_host !== $request->getSchemeAndHttpHost()
|
||||||
|
) {
|
||||||
|
return redirect($project->http_host, 302);
|
||||||
|
}
|
||||||
|
|
||||||
|
$languageCode = $request->route()?->parameter('language');
|
||||||
|
$websiteTranslations = $this->getWebsiteTranslations($project, $languageCode);
|
||||||
|
if (\is_null($websiteTranslations)) {
|
||||||
|
abort(Response::HTTP_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($request->route()->parameters['project']);
|
||||||
|
unset($request->route()->parameters['language']);
|
||||||
|
|
||||||
|
$request->attributes->set('project', $project);
|
||||||
|
$request->attributes->set('websiteTranslations', $websiteTranslations);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Enums\CacheTag;
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
final class ProjectDomainAndLanguage extends ProjectLanguage
|
||||||
|
{
|
||||||
|
public function handle(Request $request, Closure $next): Response
|
||||||
|
{
|
||||||
|
$httpHost = $request->getSchemeAndHttpHost();
|
||||||
|
if (
|
||||||
|
config('app.force_https') === true
|
||||||
|
&& Str::startsWith($httpHost, 'http://')
|
||||||
|
) {
|
||||||
|
$httpHost = Str::of($httpHost)->replaceFirst('http://', 'https://')->toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
$seconds = 3600;
|
||||||
|
$project = CacheTag::Project->getCache()->remember(self::class . $httpHost, $seconds, function () use ($httpHost) {
|
||||||
|
return $this->projectRepository->getProjectByHttpHost($httpHost) ?? false;
|
||||||
|
});
|
||||||
|
if ($project === false) {
|
||||||
|
$project = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$websiteTranslations = null;
|
||||||
|
if ($project !== null) {
|
||||||
|
$languageCode = $request->route()?->parameter('language');
|
||||||
|
$websiteTranslations = $this->getWebsiteTranslations($project, $languageCode);
|
||||||
|
if (\is_null($websiteTranslations)) {
|
||||||
|
abort(Response::HTTP_NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($request->route()->parameters['language']);
|
||||||
|
$request->attributes->set('project', $project);
|
||||||
|
$request->attributes->set('websiteTranslations', $websiteTranslations);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
43
app/application/app/Http/Middleware/ProjectLanguage.php
Normal file
43
app/application/app/Http/Middleware/ProjectLanguage.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Enums\CacheTag;
|
||||||
|
use App\Models\Project;
|
||||||
|
use App\Repositories\ProjectLanguageRepository;
|
||||||
|
use App\Repositories\ProjectRepository;
|
||||||
|
use App\Repositories\ProjectTranslationRepository;
|
||||||
|
use App\Services\WebsiteTranslations;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
|
abstract class ProjectLanguage
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected readonly ProjectRepository $projectRepository,
|
||||||
|
private readonly ProjectLanguageRepository $projectLanguageRepository,
|
||||||
|
private readonly ProjectTranslationRepository $projectTranslationRepository
|
||||||
|
) { }
|
||||||
|
|
||||||
|
protected function getWebsiteTranslations(Project $project, ?string $languageCode): ?WebsiteTranslations
|
||||||
|
{
|
||||||
|
$seconds = 3600 * 3;
|
||||||
|
$language = CacheTag::Project->getCache()->remember(self::class . $project->id . '-' . $languageCode, $seconds, function () use ($project, $languageCode) {
|
||||||
|
return $this->projectLanguageRepository->getProjectLanguageByCodeOrDefault($project, $languageCode) ?? false;
|
||||||
|
});
|
||||||
|
if ($language === false) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ($language !== null) {
|
||||||
|
if ($language->system_lang) {
|
||||||
|
App::setLocale($language->system_lang->getLocale());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$seconds = 3600 * 24;
|
||||||
|
$translations = CacheTag::ProjectTranslation->getCache()->remember(self::class . '-translations-' . $project->id . '-' . $language->id, $seconds, function () use ($project, $language) {
|
||||||
|
return $this->projectTranslationRepository->getProjectTranslations($project->id, $language->id)->all()->pluck('text', 'code')->toArray();
|
||||||
|
});
|
||||||
|
|
||||||
|
return new WebsiteTranslations($language, $translations);
|
||||||
|
}
|
||||||
|
}
|
19
app/application/app/Http/Middleware/UserLocale.php
Normal file
19
app/application/app/Http/Middleware/UserLocale.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
|
final class UserLocale
|
||||||
|
{
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
if ($request->user() && $request->user()->lang) {
|
||||||
|
App::setLocale($request->user()->lang->getLocale());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin\Languages;
|
||||||
|
|
||||||
|
use App\Contracts\FormRequestDto;
|
||||||
|
use App\Dto\Service\Admin\Language\NewLanguage;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class NewLanguageRequest extends FormRequest implements FormRequestDto
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ['required', 'numeric'],
|
||||||
|
'name' => ['required', 'string'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDto(): NewLanguage
|
||||||
|
{
|
||||||
|
return new NewLanguage(
|
||||||
|
name: $this->input('name'),
|
||||||
|
index: $this->input('index'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin\Projects\About;
|
||||||
|
|
||||||
|
use App\Contracts\FormRequestDto;
|
||||||
|
use App\Dto\Service\Admin\Project\About\StoreUpdate;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
final class StoreUpdateRequest extends FormRequest implements FormRequestDto
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => ['required', 'string', 'max:255',],
|
||||||
|
'description' => ['nullable', 'string',],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDto(): StoreUpdate
|
||||||
|
{
|
||||||
|
return new StoreUpdate(
|
||||||
|
title: $this->input('title'),
|
||||||
|
description: $this->input('description'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin\Projects\Feedbacks;
|
||||||
|
|
||||||
|
use App\Contracts\FormRequestDto;
|
||||||
|
use App\Dto\Builder\ProjectFeedback;
|
||||||
|
use App\Dto\Service\Admin\Project\Feedback\Index;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
final class IndexRequest extends FormRequest implements FormRequestDto
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'page' => ['nullable', 'numeric', 'min:1']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDto(): Index
|
||||||
|
{
|
||||||
|
return new Index(
|
||||||
|
projectFeedbackBuilderDto: new ProjectFeedback(),
|
||||||
|
page: (int) $this->input('page', 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin\Projects;
|
||||||
|
|
||||||
|
use App\Contracts\FormRequestDto;
|
||||||
|
use App\Dto\Builder\Project;
|
||||||
|
use App\Dto\Service\Admin\Project\Index;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
final class IndexRequest extends FormRequest implements FormRequestDto
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
$this->redirect = route('admin.projects.index');
|
||||||
|
return [
|
||||||
|
'page' => ['nullable', 'numeric', 'min:1']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDto(): Index
|
||||||
|
{
|
||||||
|
return new Index(
|
||||||
|
projectBuilderDto: new Project(),
|
||||||
|
page: (int) $this->input('page', 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin\Projects\Links;
|
||||||
|
|
||||||
|
use App\Contracts\FormRequestDto;
|
||||||
|
use App\Dto\Builder\ProjectLink;
|
||||||
|
use App\Dto\Service\Admin\Project\Link\Index;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
final class IndexRequest extends FormRequest implements FormRequestDto
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'page' => ['nullable', 'numeric', 'min:1']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDto(): Index
|
||||||
|
{
|
||||||
|
return new Index(
|
||||||
|
linkBuilderDto: new ProjectLink(),
|
||||||
|
page: (int) $this->input('page', 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin\Projects\Links;
|
||||||
|
|
||||||
|
use App\Contracts\FormRequestDto;
|
||||||
|
use App\Dto\Service\Admin\Project\Link\StoreUpdate;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
final class StoreUpdateRequest extends FormRequest implements FormRequestDto
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => ['required', 'string', 'max:255'],
|
||||||
|
'link' => ['required', 'string', 'max:255', 'url:http,https'],
|
||||||
|
'sort' => ['required', 'integer', 'min:-1000', 'max:1000'],
|
||||||
|
'language_id' => ['nullable', 'integer', 'min:1'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDto(): StoreUpdate
|
||||||
|
{
|
||||||
|
$languageId = $this->input('language_id');
|
||||||
|
if (! \is_null($languageId)) {
|
||||||
|
$languageId = (int) $languageId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new StoreUpdate(
|
||||||
|
title: $this->input('title'),
|
||||||
|
link: $this->input('link'),
|
||||||
|
sort: (int) $this->input('sort'),
|
||||||
|
languageId: $languageId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin\Projects;
|
||||||
|
|
||||||
|
use App\Contracts\FormRequestDto;
|
||||||
|
use App\Dto\Service\Admin\Project\Language;
|
||||||
|
use App\Dto\Service\Admin\Project\Languages;
|
||||||
|
use App\Dto\Service\Admin\Project\StoreUpdate;
|
||||||
|
use App\Dto\Service\Storage\Storages;
|
||||||
|
use App\Enums\Lang;
|
||||||
|
use App\Enums\StorageType;
|
||||||
|
use App\Rules\HttpHost;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rules\Enum;
|
||||||
|
|
||||||
|
class StoreUpdateRequest extends FormRequest implements FormRequestDto
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
$projectId = $this->project ?? null;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
'code' => ['required', 'string', 'min:3', 'max:255', 'regex:/^[a-z0-9_-]+$/'],
|
||||||
|
'http_host' => ['nullable', 'string', 'max:255', new HttpHost(), 'unique:projects,http_host,' . $projectId],
|
||||||
|
'is_public' => ['required', 'boolean'],
|
||||||
|
|
||||||
|
'logo.file' => ['nullable', 'numeric', 'min:1'],
|
||||||
|
'logo.delete' => ['nullable', 'boolean'],
|
||||||
|
|
||||||
|
'languages.items.*.id' => ['nullable', 'numeric'],
|
||||||
|
'languages.items.*.title' => ['required', 'string', 'max:255'],
|
||||||
|
'languages.items.*.code' => ['required', 'string', 'min:2', 'max:30', 'regex:/^[a-z_]+$/'],
|
||||||
|
'languages.items.*.sort' => ['required', 'numeric', 'min:-1000', 'max:1000'],
|
||||||
|
'languages.items.*.system_lang' => ['nullable', new Enum(Lang::class)],
|
||||||
|
'languages.items.*.iso_code' => ['nullable', 'string', 'max:30', 'regex:/^[a-zA-Z-]+$/'],
|
||||||
|
'languages.default' => ['required', 'numeric', function (string $attribute, mixed $value, \Closure $fail) {
|
||||||
|
$languages = $this->input('languages.items', []);
|
||||||
|
if (!isset($languages[$value])) {
|
||||||
|
$this->validator->getMessageBag()->add('languages.default', __('validation.required', ['attribute' => __('validation.attributes.language-default')]));
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
'languages.items' => ['required', 'array', function (string $attribute, mixed $value, \Closure $fail) {
|
||||||
|
$values = [];
|
||||||
|
foreach ($value as $index => $item) {
|
||||||
|
if (!isset($item['code'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (in_array($item['code'], $values)) {
|
||||||
|
$this->validator->getMessageBag()->add('languages.items.' . $index . '.code', __('validation.unique', ['attribute' => __('validation.attributes.language-code')]));
|
||||||
|
}
|
||||||
|
$values[] = $item['code'];
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getDto(): StoreUpdate
|
||||||
|
{
|
||||||
|
return new StoreUpdate(
|
||||||
|
name: $this->input('name'),
|
||||||
|
code: $this->input('code'),
|
||||||
|
isPublic: (bool) $this->input('is_public', false),
|
||||||
|
languages: $this->languages(),
|
||||||
|
storages: $this->storages(),
|
||||||
|
httpHost: $this->input('http_host', null),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function languages(): Languages
|
||||||
|
{
|
||||||
|
$languages = new Languages();
|
||||||
|
|
||||||
|
$default = $this->input('languages.default', null);
|
||||||
|
if ($default !== null) {
|
||||||
|
$default = (int) $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->input('languages.items', []) as $index => $lang) {
|
||||||
|
$languageId = $lang['id'] ?? null;
|
||||||
|
if ($languageId !== null) {
|
||||||
|
$languageId = (int) $languageId;
|
||||||
|
}
|
||||||
|
$systemLang = null;
|
||||||
|
if ($lang['system_lang'] !== null) {
|
||||||
|
$systemLang = Lang::tryFrom((int) $lang['system_lang']);
|
||||||
|
}
|
||||||
|
$language = new Language(
|
||||||
|
title: $lang['title'],
|
||||||
|
code: $lang['code'],
|
||||||
|
sort: (int) $lang['sort'],
|
||||||
|
isDefault: ($default === $index),
|
||||||
|
isoCode: $lang['iso_code'] ?? null,
|
||||||
|
systemLang: $systemLang,
|
||||||
|
id: $languageId,
|
||||||
|
);
|
||||||
|
$languages->addLanguage($language);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $languages;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function storages(): Storages
|
||||||
|
{
|
||||||
|
$storages = new Storages();
|
||||||
|
|
||||||
|
$logo = $this->get('logo', []);
|
||||||
|
$storages->add($logo, StorageType::Logo);
|
||||||
|
|
||||||
|
return $storages;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Admin\Projects\Translations;
|
||||||
|
|
||||||
|
use App\Contracts\FormRequestDto;
|
||||||
|
use App\Dto\Service\Admin\Project\Translation\Translation;
|
||||||
|
use App\Dto\Service\Admin\Project\Translation\Translations;
|
||||||
|
use App\Dto\Service\Admin\Project\Translation\Update;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rules\In;
|
||||||
|
|
||||||
|
final class UpdateRequest extends FormRequest implements FormRequestDto
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'translations' => ['nullable', 'array'],
|
||||||
|
'translations.*.code' => ['required', 'string', new In(Translations::getTranslationCodes())],
|
||||||
|
'translations.*.text' => ['nullable', 'string', 'max:1000'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDto(): Update
|
||||||
|
{
|
||||||
|
$translations = new Translations();
|
||||||
|
foreach ($this->input('translations', []) as $translation) {
|
||||||
|
$translations->addTranslation(
|
||||||
|
code: $translation['code'],
|
||||||
|
text: $translation['text'] ?? null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Update($translations);
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user