Skip to content

Commit e265415

Browse files
committed
Merge branch 'dev' of github.com:BinaryStudioAcademy/thread-php into feature/no-content-fix
# Conflicts: # frontend/src/components/view/feed/FeedContainer.vue
2 parents e58e1ab + f0c3c1c commit e265415

File tree

25 files changed

+329
-37
lines changed

25 files changed

+329
-37
lines changed

backend/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ APP_PORT=7777
5252
MYSQL_PORT_TEST_DB=33062
5353

5454
BEANSTALKD_HOST=
55+
FILESYSTEM_DRIVER=public

backend/app/Action/Auth/UploadProfileImageAction.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,31 @@
55
namespace App\Action\Auth;
66

77
use App\Repository\UserRepository;
8-
use Illuminate\Filesystem\FilesystemManager;
98
use Illuminate\Support\Facades\Auth;
9+
use Illuminate\Support\Facades\Storage;
10+
use Illuminate\Support\Facades\Config;
1011

1112
final class UploadProfileImageAction
1213
{
13-
private const UPLOAD_DIR = 'profile-images';
14-
1514
private $userRepository;
16-
private $filesystemManager;
1715

18-
public function __construct(UserRepository $userRepository, FilesystemManager $filesystemManager)
16+
public function __construct(UserRepository $userRepository)
1917
{
2018
$this->userRepository = $userRepository;
21-
$this->filesystemManager = $filesystemManager;
2219
}
2320

2421
public function execute(UploadProfileImageRequest $request): UploadProfileImageResponse
2522
{
2623
$user = Auth::user();
2724

28-
$disk = $this->filesystemManager->disk('public');
29-
30-
$filePath = $disk->putFileAs(
31-
self::UPLOAD_DIR,
25+
$filePath = Storage::putFileAs(
26+
Config::get('filesystems.profile_images_dir'),
3227
$request->getImage(),
33-
$user->id,
28+
$request->getImage()->hashName(),
3429
'public'
3530
);
3631

37-
// added timestamp to url to let browser know that image was changed
38-
$user->profile_image = $disk->url($filePath) . '?t=' . time();
32+
$user->profile_image = Storage::url($filePath);
3933

4034
$user = $this->userRepository->save($user);
4135

backend/app/Action/Tweet/AddTweetAction.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Entity\Tweet;
88
use App\Repository\TweetRepository;
99
use Illuminate\Support\Facades\Auth;
10+
use App\Events\TweetAddedEvent;
1011

1112
final class AddTweetAction
1213
{
@@ -24,6 +25,8 @@ public function execute(AddTweetRequest $request): AddTweetResponse
2425
$tweet->text = $request->getText();
2526

2627
$tweet = $this->tweetRepository->save($tweet);
28+
29+
broadcast(new TweetAddedEvent($tweet))->toOthers();
2730

2831
return new AddTweetResponse($tweet);
2932
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use Illuminate\Broadcasting\Channel;
6+
use Illuminate\Queue\SerializesModels;
7+
use Illuminate\Broadcasting\PrivateChannel;
8+
use Illuminate\Broadcasting\PresenceChannel;
9+
use Illuminate\Foundation\Events\Dispatchable;
10+
use Illuminate\Broadcasting\InteractsWithSockets;
11+
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
12+
use App\Entity\Tweet;
13+
use App\Http\Presenter\Tweet\TweetArrayPresenter;
14+
use Illuminate\Support\Facades\App;
15+
16+
class TweetAddedEvent implements ShouldBroadcast
17+
{
18+
use Dispatchable, InteractsWithSockets, SerializesModels;
19+
20+
public $tweet;
21+
22+
public function __construct(Tweet $tweet)
23+
{
24+
$this->tweet = App::make(TweetArrayPresenter::class)->present($tweet);
25+
}
26+
27+
public function broadcastAs(): string
28+
{
29+
return 'tweet.added';
30+
}
31+
32+
public function broadcastOn(): PrivateChannel
33+
{
34+
return new PrivateChannel('tweets');
35+
}
36+
}

backend/app/Providers/BroadcastServiceProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class BroadcastServiceProvider extends ServiceProvider
1414
*/
1515
public function boot()
1616
{
17-
Broadcast::routes();
17+
Broadcast::routes([
18+
'middleware' => ['api']
19+
]);
1820

1921
require base_path('routes/channels.php');
2022
}

backend/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"laravel/framework": "5.8.*",
1818
"laravel/tinker": "^1.0",
1919
"pda/pheanstalk": "^4.0",
20+
"pusher/pusher-php-server": "^3.4",
2021
"tymon/jwt-auth": "1.0.*"
2122
},
2223
"require-dev": {

backend/composer.lock

Lines changed: 137 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
*/
172172
App\Providers\AppServiceProvider::class,
173173
App\Providers\AuthServiceProvider::class,
174-
// App\Providers\BroadcastServiceProvider::class,
174+
App\Providers\BroadcastServiceProvider::class,
175175
App\Providers\EventServiceProvider::class,
176176
App\Providers\RouteServiceProvider::class,
177177

backend/config/filesystems.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
],
6868

69-
'tweet_images_dir' => 'tweet-images'
69+
'tweet_images_dir' => 'tweet-images',
70+
'profile_images_dir' => 'profile-images'
7071

7172
];

backend/routes/channels.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
Broadcast::channel('App.User.{id}', function ($user, $id) {
1515
return (int) $user->id === (int) $id;
1616
});
17+
18+
Broadcast::channel('tweets', function () {
19+
return true;
20+
});

0 commit comments

Comments
 (0)