Skip to content

Commit a363f5e

Browse files
authored
Initialize the Secret Santa game for the New Year
* Initialize the Secret Santa game for the New Year * Fixed code style * Improve santa text * Improve text & added new columns * Added missing model * Fixed code style --------- Co-authored-by: tabuna <tabuna@users.noreply.github.com>
1 parent 78c6ae6 commit a363f5e

24 files changed

+1230
-21
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Notifications\SimpleMessageNotification;
6+
use Illuminate\Contracts\View\View;
7+
use Illuminate\Http\RedirectResponse;
8+
use Illuminate\Http\Request;
9+
use Illuminate\Validation\Rule;
10+
use Orchid\Support\Facades\Toast;
11+
12+
class SantaController extends Controller
13+
{
14+
/**
15+
* Отображает главную страницу Тайного Санты.
16+
*
17+
* @return \Illuminate\Contracts\View\View
18+
*/
19+
public function index(Request $request): View
20+
{
21+
$participant = $request->user()
22+
->secretSantaParticipant()
23+
->firstOrNew();
24+
25+
return view('santa.index', [
26+
'participant' => $participant,
27+
]);
28+
}
29+
30+
/**
31+
* Отображает страницу с правилами участия в Тайном Санте.
32+
*
33+
* @return \Illuminate\Contracts\View\View
34+
*/
35+
public function rules(): View
36+
{
37+
return view('santa.rules');
38+
}
39+
40+
/**
41+
* Показывает форму для регистрации.
42+
*/
43+
public function game(Request $request): View
44+
{
45+
$participant = $request->user()
46+
->secretSantaParticipant()
47+
->firstOrNew();
48+
49+
return view('santa.game', [
50+
'participant' => $participant,
51+
]);
52+
}
53+
54+
/**
55+
* Обрабатывает заявку участника на участие в Тайном Санте.
56+
*/
57+
public function update(Request $request): RedirectResponse
58+
{
59+
$participant = $request->user()
60+
->secretSantaParticipant()
61+
->firstOrNew();
62+
63+
$data = $request->validate([
64+
'telegram' => ['string', 'required_without:tracking_number'],
65+
'phone' => ['string', 'required_without:tracking_number'],
66+
'address' => ['string', 'required_without:tracking_number'],
67+
'about' => ['string', 'required_without:tracking_number'],
68+
'tracking_number' => [
69+
'nullable',
70+
'string',
71+
Rule::requiredIf($participant->receiver_id),
72+
],
73+
]);
74+
75+
$participant
76+
->fill($data)
77+
->save();
78+
79+
$participant
80+
->receiver
81+
?->user
82+
?->notify(new SimpleMessageNotification('Получатель подарка "Тайного Санты" обновил информацию. Пожалуйста, проверьте.'));
83+
84+
Toast::success('Ваша заявка на участие в принята! Готовьтесь к сюрпризу.')
85+
->disableAutoHide();
86+
87+
return redirect()->route('santa');
88+
}
89+
90+
/**
91+
* Отменяет заявку участника на участие.
92+
*
93+
* @param \Illuminate\Http\Request $request
94+
*
95+
* @return \Illuminate\Http\RedirectResponse
96+
*/
97+
public function delete(Request $request): RedirectResponse
98+
{
99+
$participant = $request->user()
100+
->secretSantaParticipant()
101+
->firstOrNew();
102+
103+
$participant->delete();
104+
105+
Toast::success('Ваша заявка на участие отозвана! Спасибо, что предупредили заранее.')
106+
->disableAutoHide();
107+
108+
return redirect()->route('santa');
109+
}
110+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Concerns\HasUuids;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\SoftDeletes;
8+
9+
class SecretSantaParticipant extends Model
10+
{
11+
use HasUuids, SoftDeletes;
12+
13+
protected $fillable = [
14+
'address',
15+
'about',
16+
'tracking_number',
17+
'telegram',
18+
'phone',
19+
];
20+
21+
/**
22+
* @var string[]
23+
*/
24+
protected $with = [
25+
'receiver',
26+
];
27+
28+
// Связь с пользователем
29+
public function user()
30+
{
31+
return $this->belongsTo(User::class);
32+
}
33+
34+
// Связь с получателем
35+
public function receiver()
36+
{
37+
return $this
38+
->belongsTo(SecretSantaParticipant::class, 'receiver_id', 'user_id')
39+
->without('receiver');
40+
}
41+
42+
/**
43+
* @return bool
44+
*/
45+
public function hasReceiver(): bool
46+
{
47+
return $this->receiver_id !== null;
48+
}
49+
}

app/Models/User.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ public function challengesReapositories()
200200
return $this->hasMany(ChallengeApplication::class);
201201
}
202202

203+
/**
204+
* @return \Illuminate\Database\Eloquent\Relations\HasOne
205+
*/
206+
public function secretSantaParticipant()
207+
{
208+
return $this->hasOne(SecretSantaParticipant::class);
209+
}
210+
203211
/**
204212
* Reward the user with an achievement.
205213
*

app/Notifications/SimpleMessageNotification.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Notifications\Channels\SiteMessage;
88
use Illuminate\Bus\Queueable;
99
use Illuminate\Contracts\Queue\ShouldQueue;
10+
use Illuminate\Notifications\Messages\MailMessage;
1011
use Illuminate\Notifications\Notification;
1112
use NotificationChannels\WebPush\WebPushChannel;
1213
use NotificationChannels\WebPush\WebPushMessage;
@@ -34,9 +35,26 @@ public function via(User $user)
3435
return [
3536
SiteChannel::class,
3637
WebPushChannel::class,
38+
'mail',
3739
];
3840
}
3941

42+
/**
43+
* Get the mail representation of the notification.
44+
*
45+
* @param User $user
46+
*
47+
* @throws \Throwable
48+
*
49+
* @return MailMessage
50+
*/
51+
public function toMail(User $user)
52+
{
53+
return (new MailMessage)
54+
->subject('Новое уведомление')
55+
->line($this->message);
56+
}
57+
4058
/**
4159
* Get the app representation of the notification.
4260
*
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('secret_santa_participants', function (Blueprint $table) {
15+
$table->uuid('id')->primary();
16+
17+
$table->foreignId('user_id')
18+
->constrained()
19+
->onDelete('cascade')
20+
->comment('Идентификатор пользователя (отправителя), который участвует в Тайном Санте');
21+
22+
$table->text('address')
23+
->comment('Адрес участника для отправки подарка');
24+
25+
$table->string('telegram')
26+
->nullable()
27+
->comment('Телеграм участника для связи');
28+
29+
$table->string('phone')
30+
->comment('Контактные данные участника для связи');
31+
32+
$table->text('about')
33+
->comment('Информация о пользователе, которую он предоставляет о себе для получателя');
34+
35+
$table->foreignId('receiver_id')
36+
->nullable()
37+
->constrained('users')
38+
->onDelete('set null')
39+
->comment('Идентификатор пользователя (получателя) из таблицы пользователей');
40+
41+
$table->string('tracking_number')
42+
->comment('Номер отслеживания посылки')
43+
->nullable();
44+
45+
$table->string('status')
46+
->comment('Статус участника в Тайном Санте')
47+
->default('new');
48+
49+
$table->timestamps();
50+
$table->softDeletes();
51+
});
52+
}
53+
54+
/**
55+
* Reverse the migrations.
56+
*/
57+
public function down(): void
58+
{
59+
Schema::dropIfExists('secret_santa_participants');
60+
}
61+
};

public/build/assets/app-bdQfWviv.css renamed to public/build/assets/app-8jhtCGii.css

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

public/build/assets/app-B969tbq3.js renamed to public/build/assets/app-CDEY8pR7.js

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

public/build/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
"src": "public/img/ui/blockquote/warning.svg"
1717
},
1818
"resources/css/app.scss": {
19-
"file": "assets/app-bdQfWviv.css",
19+
"file": "assets/app-8jhtCGii.css",
2020
"src": "resources/css/app.scss",
2121
"isEntry": true
2222
},
2323
"resources/js/app.js": {
24-
"file": "assets/app-B969tbq3.js",
24+
"file": "assets/app-CDEY8pR7.js",
2525
"name": "app",
2626
"src": "resources/js/app.js",
2727
"isEntry": true,

public/img/ui/santa/blob.svg

Lines changed: 13 additions & 0 deletions
Loading

public/img/ui/santa/pattern.svg

Lines changed: 22 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)