Skip to content

Commit

Permalink
#100 - Init projektu - pobieranie przykładowych zdjęć restauracji
Browse files Browse the repository at this point in the history
Po załadowaniu restauracji korzystamy z faker to pobrania losowych zdjec dla restauracji.
Pobrane zdjecia nastepnie wrzucamy na minio.
Dzieki temu na naszej stronie glownej pojawia sie loga restauracji.
Obecnie faker korzysta tylko z lorempixel, ktore nie dziala (fzaninotto/Faker#1884)
Korzystamy wiec tymczasowo z forka, ktory dodaje usluge https://picsum.photos/
  • Loading branch information
morawskim committed Feb 1, 2020
1 parent af376fc commit b5bdd22
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ setup: .env
mkdir -p frontend/web/assets
chmod 777 frontend/web/assets
docker-compose up -d mongo
# in future move to wait_for script
# in future move to wait_for script, also for minio
sleep 5
docker-compose up -d mongo-init-replica
docker-compose up -d
docker-compose exec cli bash -c "composer install"
docker-compose exec cli bash -c "cd frontend && yarn install --frozen-lock-file"
docker-compose exec cli bash -c 'cd frontend && yarn build'
docker-compose exec cli bash -c "./yii migrate/up --interactive 0"
docker-compose exec cli bash -c "./yii init/create-bucket"
docker-compose exec cli bash -c "./yii fixture/load '*' --interactive 0 "
docker-compose exec cli bash -c "cd provision/rocketchat/ && npm ci"
docker-compose exec cli bash -c "cd provision/rocketchat/ && node incomingIntegration.js"
Expand Down
20 changes: 20 additions & 0 deletions common/tests/unit/fixtures/RestaurantFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace common\tests\unit\fixtures;

use common\enums\BucketEnum;
use common\services\FileService;
use common\services\FixtureStore;
use Faker\Factory;
use frontend\models\Restaurants;
use yii\test\ActiveFixture;

Expand All @@ -16,4 +19,21 @@ public function beforeLoad(): void
parent::beforeLoad();
FixtureStore::getInstance()->addFixture($this);
}

public function afterLoad(): void
{
$faker = Factory::create();
/** @var Restaurants $restaurant */
foreach (array_keys($this->data) as $alias) {
$restaurant = $this->getModel($alias);
$path = $faker->picsum(null, 400, 400, true);

$key = basename($path);
$restaurant->img_url = $key;
/** @var FileService $fileService */
$fileService = \Yii::$container->get(FileService::class);
$fileService->storeFile(BucketEnum::RESTAURANT . '/' . $key, $path);
$restaurant->save(false);
}
}
}
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
{
"type": "git",
"url": "https://github.com/morawskim/yii2-utils"
},
{
"type": "git",
"url": "https://github.com/morawskim/Faker"
}
],
"require": {
Expand Down Expand Up @@ -62,7 +66,8 @@
"phpcompatibility/php-compatibility": "^9.1",
"phpstan/phpstan-deprecation-rules": "^0.11.2",
"phpstan/phpstan-strict-rules": "^0.11.1",
"ergebnis/phpstan-rules": "^0.14.2"
"ergebnis/phpstan-rules": "^0.14.2",
"fzaninotto/faker": "dev-picsum as v1.8.0"
},
"config": {
"process-timeout": 1800,
Expand Down
38 changes: 22 additions & 16 deletions composer.lock

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

38 changes: 38 additions & 0 deletions console/controllers/InitController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace console\controllers;

use Aws\S3\S3Client;
use common\enums\BucketEnum;
use yii\console\Controller;

class InitController extends Controller
{
public function actionCreateBucket(): void
{
$bucket = 'ssorder';
/** @var S3Client $s3Client */
$s3Client = \Yii::$container->get(S3Client::class);
$s3Client->createBucket(['Bucket' => $bucket]);

$policyJson = <<<EOS
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"PublicRead",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::$bucket/*"]
}
]
}
EOS;

$s3Client->putBucketPolicy([
'Bucket' => $bucket,
'Policy' => $policyJson
]);
}
}

0 comments on commit b5bdd22

Please sign in to comment.