Skip to content

Commit 0ccf499

Browse files
authored
Merge pull request #41 from MRR-Group/mailing
Mailing
2 parents 1302404 + 1cce72a commit 0ccf499

26 files changed

+532
-345
lines changed

app/Http/Controllers/Api/StatisticController.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Controllers\Api;
46

57
use App\Http\Controllers\Controller;
68
use App\Models\Achievement;
79
use App\Models\Game;
810
use App\Models\GameDetail;
911
use App\Models\User;
10-
use Illuminate\Http\Request;
1112

1213
class StatisticController extends Controller
1314
{
14-
public function users() {
15+
public function users()
16+
{
1517
$hours_played = 0;
1618
$common_games = 0;
1719

18-
foreach(GameDetail::all() as $game) {
20+
foreach (GameDetail::all() as $game) {
1921
if (count($game->games) >= 2) {
20-
$common_games += 1;
22+
++$common_games;
2123
}
2224
}
2325

24-
foreach(Game::all() as $game) {
26+
foreach (Game::all() as $game) {
2527
$hours_played += $game->play_time / 60;
2628
}
2729

@@ -36,7 +38,8 @@ public function users() {
3638
], 200);
3739
}
3840

39-
public function games() {
41+
public function games()
42+
{
4043
$most_completed = null;
4144
$most_completed_result = 0;
4245

@@ -50,7 +53,7 @@ public function games() {
5053
return response()->json(["message" => "Cannot load statistics for empty library"], 404);
5154
}
5255

53-
foreach(Game::all() as $game) {
56+
foreach (Game::all() as $game) {
5457
$achievements = $game->achievements;
5558
$completion = $game->game_completion();
5659

app/Http/Controllers/InviteController.php

+9
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
use App\Exceptions\InviteNotFoundException;
1010
use App\Exceptions\UserNotFoundException;
1111
use App\Http\Requests\InviteUpdateRequest;
12+
use App\Mail\InviteAcceptedNotification;
13+
use App\Mail\InviteReceivedNotification;
1214
use App\Models\GameDetail;
1315
use App\Models\Invite;
1416
use App\Models\User;
1517
use Illuminate\Http\Request;
18+
use Illuminate\Support\Facades\Mail;
1619
use Illuminate\Support\Facades\Redirect;
1720
use Inertia\Inertia;
1821

@@ -37,6 +40,8 @@ public function send_invite(int $user_id, int $game_id, Request $request)
3740
$invite->receiver()->associate($target_user);
3841
$invite->save();
3942

43+
Mail::to($invite->receiver->email)->send(new InviteReceivedNotification($invite));
44+
4045
return Redirect::route("invite.show")->with("status", "Request sent to " . $target_user->name);
4146
}
4247

@@ -98,6 +103,10 @@ public function update(InviteUpdateRequest $request, int $id)
98103

99104
$status = $invite->is_accepted ? "accepted" : "rejected";
100105

106+
if ($invite->is_accepted) {
107+
Mail::to($invite->sender->email)->send(new InviteAcceptedNotification($invite));
108+
}
109+
101110
return Redirect::route("invite.show")->with("status", $status . " invite from " . $invite->sender->name);
102111
}
103112

app/Http/Controllers/LangController.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Controllers;
46

57
class LangController extends Controller
68
{
7-
public function set(string $locale) {
8-
if (!in_array($locale, ['en', 'pl'])) {
9+
public function set(string $locale)
10+
{
11+
if (!in_array($locale, ["en", "pl"], true)) {
912
return response()->json([], 400);
1013
}
1114

1215
app()->setLocale($locale);
13-
session()->put('locale', $locale);
16+
session()->put("locale", $locale);
1417

1518
return response()->json([], 200);
1619
}

app/Http/Controllers/Steam/SteamDataFetcherController.php

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Http\JsonResponse;
1010
use Illuminate\Http\Request;
1111
use Illuminate\Support\Facades\Bus;
12+
use Illuminate\Support\Facades\Cache;
1213
use Inertia\Inertia;
1314
use Inertia\Response;
1415

@@ -24,6 +25,8 @@ public function show(Request $request): Response
2425
public function fetch(Request $request, SteamService $steam): Response
2526
{
2627
$user = $request->user();
28+
Cache::forget("library-" . $user->id);
29+
2730
$batch = $steam->fetch_games($user);
2831

2932
return Inertia::render("Steam/Fetch", [

app/Http/Middleware/Localization.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Middleware;
46

57
use Closure;
@@ -11,10 +13,10 @@ class Localization
1113
{
1214
public function handle(Request $request, Closure $next)
1315
{
14-
if (Session::has('locale')) {
15-
App::setLocale(Session::get('locale'));
16+
if (Session::has("locale")) {
17+
App::setLocale(Session::get("locale"));
1618
}
17-
19+
1820
return $next($request);
1921
}
20-
}
22+
}
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Mail;
6+
7+
use App\Models\Invite;
8+
use Illuminate\Bus\Queueable;
9+
use Illuminate\Mail\Mailable;
10+
use Illuminate\Mail\Mailables\Content;
11+
use Illuminate\Mail\Mailables\Envelope;
12+
use Illuminate\Queue\SerializesModels;
13+
14+
class InviteAcceptedNotification extends Mailable
15+
{
16+
use Queueable;
17+
use SerializesModels;
18+
19+
public function __construct(
20+
private Invite $invite,
21+
) {}
22+
23+
public function envelope(): Envelope
24+
{
25+
return new Envelope(
26+
subject: $this->invite->receiver->name . " accepted your invite!",
27+
);
28+
}
29+
30+
public function content(): Content
31+
{
32+
return new Content(
33+
view: "emails.invite-accepted",
34+
with: [
35+
"sender_name" => $this->invite->sender->name,
36+
"receiver_name" => $this->invite->receiver->name,
37+
"game" => $this->invite->game->name,
38+
],
39+
);
40+
}
41+
42+
/**
43+
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
44+
*/
45+
public function attachments(): array
46+
{
47+
return [];
48+
}
49+
}
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Mail;
6+
7+
use App\Models\Invite;
8+
use Illuminate\Bus\Queueable;
9+
use Illuminate\Mail\Mailable;
10+
use Illuminate\Mail\Mailables\Content;
11+
use Illuminate\Mail\Mailables\Envelope;
12+
use Illuminate\Queue\SerializesModels;
13+
14+
class InviteReceivedNotification extends Mailable
15+
{
16+
use Queueable;
17+
use SerializesModels;
18+
19+
public function __construct(
20+
private Invite $invite,
21+
) {}
22+
23+
public function envelope(): Envelope
24+
{
25+
return new Envelope(
26+
subject: "You have a new invite!",
27+
);
28+
}
29+
30+
public function content(): Content
31+
{
32+
return new Content(
33+
view: "emails.invite-received",
34+
with: [
35+
"sender_name" => $this->invite->sender->name,
36+
"receiver_name" => $this->invite->receiver->name,
37+
"game" => $this->invite->game->name,
38+
],
39+
);
40+
}
41+
42+
/**
43+
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
44+
*/
45+
public function attachments(): array
46+
{
47+
return [];
48+
}
49+
}

app/Mail/SteamFetchedNotification.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Mail;
6+
7+
use App\Models\User;
8+
use Illuminate\Bus\Queueable;
9+
use Illuminate\Mail\Mailable;
10+
use Illuminate\Mail\Mailables\Content;
11+
use Illuminate\Mail\Mailables\Envelope;
12+
use Illuminate\Queue\SerializesModels;
13+
14+
class SteamFetchedNotification extends Mailable
15+
{
16+
use Queueable;
17+
use SerializesModels;
18+
19+
public function __construct(
20+
private User $user,
21+
) {}
22+
23+
public function envelope(): Envelope
24+
{
25+
return new Envelope(
26+
subject: "Steam Buddy Ready to Roll!",
27+
);
28+
}
29+
30+
public function content(): Content
31+
{
32+
return new Content(
33+
view: "emails.steam-fetched",
34+
with: [
35+
"name" => $this->user->name,
36+
],
37+
);
38+
}
39+
40+
/**
41+
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
42+
*/
43+
public function attachments(): array
44+
{
45+
return [];
46+
}
47+
}

app/Services/Steam/SteamService.php

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Services\Steam;
66

77
use App\Jobs\FetchSteamGame;
8+
use App\Mail\SteamFetchedNotification;
89
use App\Models\Achievement;
910
use App\Models\AchievementDetail;
1011
use App\Models\Game;
@@ -15,6 +16,7 @@
1516
use Carbon\Carbon;
1617
use Illuminate\Bus\Batch;
1718
use Illuminate\Support\Facades\Bus;
19+
use Illuminate\Support\Facades\Mail;
1820

1921
class SteamService
2022
{
@@ -36,6 +38,8 @@ public function fetch_games(User $user): Batch
3638
->then(function () use ($user): void {
3739
$user->last_fetch = Carbon::now();
3840
$user->save();
41+
42+
Mail::to($user->email)->send(new SteamFetchedNotification($user));
3943
})->dispatch();
4044
}
4145

0 commit comments

Comments
 (0)