Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Add links #4

Merged
merged 17 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ c3.php

# local app configs
config/params-local.php

/docker/postgres/data/*
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"yiisoft/log-target-file": "@dev",
"yiisoft/mailer": "@dev",
"yiisoft/mailer-swiftmailer": "@dev",
"yiisoft/request-body-parser": "^3.0@dev",
"yiisoft/router": "@dev",
"yiisoft/router-fastroute": "@dev",
"yiisoft/view": "@dev",
Expand Down
72 changes: 70 additions & 2 deletions composer.lock

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

34 changes: 26 additions & 8 deletions config/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

declare(strict_types=1);

use App\Service\Mailer;
use App\Common\Domain\Entity\Identity;
use App\Common\Service\Mailer;
use App\Module\Contact\Api\ContactMailer;
use App\Module\Contact\Service\MailerService;
use App\Module\Link\Api\UserLinkService;
use App\Module\Link\Domain\Entity\Link;
use App\Module\Link\Domain\Repository\LinkRepository;
use App\Module\Link\Service\UserLink;
use Cycle\ORM\ORMInterface;
use Psr\Container\ContainerInterface;
use Yiisoft\Aliases\Aliases;
use Yiisoft\Auth\AuthInterface;
use Yiisoft\Auth\IdentityRepositoryInterface;
use Yiisoft\Auth\Method\HttpHeader;
use Yiisoft\Factory\Definitions\Reference;

/* @var array $params */
Expand All @@ -14,21 +24,29 @@
ContainerInterface::class => static function (ContainerInterface $container) {
return $container;
},

Aliases::class => [
'__class' => Aliases::class,
'__construct()' => [$params['aliases']],
],

\App\Module\Contact\Api\ContactMailer::class => static function (ContainerInterface $container) use ($params) {
return (new \App\Module\Contact\Service\MailerService(
ContactMailer::class => static function (ContainerInterface $container) use ($params) {
return (new MailerService(
$container->get(Mailer::class),
$params['mailer']['adminEmail']
));
},

IdentityRepositoryInterface::class => static function (ContainerInterface $container) {
return $container->get(\Cycle\ORM\ORMInterface::class)
->getRepository(\App\Common\Domain\Entity\Identity::class);
return $container->get(ORMInterface::class)
->getRepository(Identity::class);
},
LinkRepository::class => static function (ContainerInterface $container) {
return $container->get(ORMInterface::class)
->getRepository(Link::class);
},
AuthInterface::class => static function (ContainerInterface $container) {
$httHeader = $container->get(HttpHeader::class);
$httHeader->setHeaderName('Authorization');

return $httHeader;
},
UserLinkService::class => Reference::to(UserLink::class),
];
11 changes: 2 additions & 9 deletions config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use App\Common\Application\ApplicationParameters;
use Cycle\Schema\Generator;
use Psr\Log\LogLevel;
use Yiisoft\Assets\AssetManager;
use Yiisoft\Form\Widget\Field;
Expand Down Expand Up @@ -143,25 +142,19 @@
* and its config as value:
*/
'schema-providers' => [
// \Yiisoft\Yii\Cycle\Schema\Provider\SimpleCacheSchemaProvider::class => [
// 'key' => 'db-schema'
// ],
// \Yiisoft\Yii\Cycle\Schema\Provider\FromFileSchemaProvider::class => [
// 'file' => '@runtime/cycle-schema.php'
// ],
// \Yiisoft\Yii\Cycle\Schema\Provider\FromConveyorSchemaProvider::class => [
// 'generators' => [
// // Generator\SyncTables::class, // sync table changes to database
// // \Cycle\Schema\Generator\SyncTables::class, // sync table changes to database
// ]
// ],
],

/**
* {@see \Yiisoft\Yii\Cycle\Schema\Conveyor\AnnotatedSchemaConveyor} settings
* A list of entity directories. You can use {@see \Yiisoft\Aliases\Aliases} in paths.
*/
'annotated-entity-paths' => [
'@src/Common/Domain/Entity',
'@src/Module/Link/Domain/Entity',
],
],

Expand Down
1 change: 0 additions & 1 deletion config/providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/* @var array $params */

use App\Common\Application\Provider\CacheProvider;
use App\Common\Application\Provider\EventDispatcherProvider;
use App\Common\Application\Provider\FileRotatorProvider;
use App\Common\Application\Provider\FileTargetProvider;
use App\Common\Application\Provider\LoggerProvider;
Expand Down
31 changes: 27 additions & 4 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,44 @@

declare(strict_types=1);

use App\Api\External\Controller\LinkController;
use App\Api\External\Controller\UserController;
use App\Api\UI\Controller\ContactController;
use App\Api\UI\Controller\SiteController;
use Yiisoft\Auth\Middleware\Auth;
use Yiisoft\Http\Method;
use Yiisoft\Router\Group;
use Yiisoft\Router\Route;
use roxblnfk\SmartStream\Middleware\BucketStreamMiddleware;
use Yiisoft\Request\Body\RequestBodyParser;

return [
// UI
Route::get('/', [SiteController::class, 'index'])->name('site/index'),
Route::get('/about', [SiteController::class, 'about'])->name('site/about'),
Route::methods([Method::GET, Method::POST], '/contact', [ContactController::class, 'contact'])
->name('contact/form'),

// External API
Group::create('/api', [
Route::anyMethod('/link', \App\Api\External\Controller\LinkController::class)->name('api/link'),
Route::anyMethod('/user', \App\Api\External\Controller\UserController::class)->name('api/user'),
Group::create(
'/api',
[
Route::get('/user', UserController::class)->name('api/user/get')->addMiddleware(Auth::class),
Route::post('/user', UserController::class)->name('api/user/post'),
Route::delete('/user', UserController::class)->name('api/user/delete'),
Route::put('/user', UserController::class)->name('api/user/put'),
Route::patch('/user', UserController::class)->name('api/user/patch'),
Route::options('/user', UserController::class)->name('api/user/options'),
Route::head('/user', UserController::class)->name('api/user/head'),

])->addMiddleware(\roxblnfk\SmartStream\Middleware\BucketStreamMiddleware::class),
Route::get('/link', LinkController::class)->name('api/link/get')->addMiddleware(Auth::class),
Route::post('/link', LinkController::class)->name('api/link/post')->addMiddleware(Auth::class),
Route::delete('/link', LinkController::class)->name('api/link/delete')->addMiddleware(Auth::class),
Route::put('/link', LinkController::class)->name('api/link/put'),
Route::patch('/link', LinkController::class)->name('api/link/patch'),
Route::options('/link', LinkController::class)->name('api/link/options'),
Route::head('/link', LinkController::class)->name('api/link/head'),
roxblnfk marked this conversation as resolved.
Show resolved Hide resolved
]
)->addMiddleware(BucketStreamMiddleware::class)
->addMiddleware(RequestBodyParser::class)
];
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3'

services:
php:
container_name: digest-php
image: yiisoftware/yii-php:7.4-apache
working_dir: /app
ports:
- 8080:80
volumes:
- ./:/app
- ~/.composer-docker/cache:/root/.composer/cache:delegated

postgresql:
container_name: postgresql
image: postgres:10.12
env_file:
- ./docker/postgres/database.env
ports:
- 5432:5432
volumes:
- ./docker/postgres/data/:/var/lib/postgresql/data/
restart: always

3 changes: 3 additions & 0 deletions docker/postgres/database.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POSTGRES_USER=postgres
POSTGRES_PASSWORD=pass
POSTGRES_DB=default
57 changes: 57 additions & 0 deletions resources/migrations/20200815.160455_0_default_create_link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Migration;

use Spiral\Migrations\Migration;

class OrmDefault185556e6f8caf503f3363d97fd0ffff2 extends Migration
{
protected const DATABASE = 'default';

public function up()
{
$this->table('link_suggestion')
->addColumn('id', 'primary', [
'nullable' => false,
'default' => null
])
->addColumn('url', 'string', [
'nullable' => false,
'default' => null,
'size' => 255
])
->addColumn('description', 'string', [
'nullable' => true,
'default' => null,
'size' => 255
])
->addColumn('created_at', 'datetime', [
'nullable' => false,
'default' => null
])
->addColumn('updated_at', 'datetime', [
'nullable' => false,
'default' => null
])
->addColumn('identity_id', 'integer', [
'nullable' => false,
'default' => null
])
->addIndex(["identity_id"], [
'name' => 'link_suggestion_index_identity_id_5f3911c14898c',
'unique' => false
])
->addForeignKey(["identity_id"], 'identity', ["id"], [
'name' => 'link_suggestion_foreign_identity_id_5f3911c14899c',
'delete' => 'CASCADE',
'update' => 'CASCADE'
])
->setPrimaryKeys(["id"])
->create();
}

public function down()
{
$this->table('link_suggestion')->drop();
}
}
2 changes: 1 addition & 1 deletion resources/views/contact/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Yiisoft\Form\Widget\Form;
use Yiisoft\Html\Html;

/* @var App\Form\ContactForm $form */
/* @var \App\Api\UI\Form\ContactForm $form */
/* @var Yiisoft\Router\UrlGeneratorInterface $url */
/* @var string|null $csrf */
/* @var Yiisoft\Form\Widget\Field $field */
Expand Down
Loading