-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
24 changed files
with
1,230 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Notifications\SimpleMessageNotification; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Validation\Rule; | ||
use Orchid\Support\Facades\Toast; | ||
|
||
class SantaController extends Controller | ||
{ | ||
/** | ||
* Отображает главную страницу Тайного Санты. | ||
* | ||
* @return \Illuminate\Contracts\View\View | ||
*/ | ||
public function index(Request $request): View | ||
{ | ||
$participant = $request->user() | ||
->secretSantaParticipant() | ||
->firstOrNew(); | ||
|
||
return view('santa.index', [ | ||
'participant' => $participant, | ||
]); | ||
} | ||
|
||
/** | ||
* Отображает страницу с правилами участия в Тайном Санте. | ||
* | ||
* @return \Illuminate\Contracts\View\View | ||
*/ | ||
public function rules(): View | ||
{ | ||
return view('santa.rules'); | ||
} | ||
|
||
/** | ||
* Показывает форму для регистрации. | ||
*/ | ||
public function game(Request $request): View | ||
{ | ||
$participant = $request->user() | ||
->secretSantaParticipant() | ||
->firstOrNew(); | ||
|
||
return view('santa.game', [ | ||
'participant' => $participant, | ||
]); | ||
} | ||
|
||
/** | ||
* Обрабатывает заявку участника на участие в Тайном Санте. | ||
*/ | ||
public function update(Request $request): RedirectResponse | ||
{ | ||
$participant = $request->user() | ||
->secretSantaParticipant() | ||
->firstOrNew(); | ||
|
||
$data = $request->validate([ | ||
'telegram' => ['string', 'required_without:tracking_number'], | ||
'phone' => ['string', 'required_without:tracking_number'], | ||
'address' => ['string', 'required_without:tracking_number'], | ||
'about' => ['string', 'required_without:tracking_number'], | ||
'tracking_number' => [ | ||
'nullable', | ||
'string', | ||
Rule::requiredIf($participant->receiver_id), | ||
], | ||
]); | ||
|
||
$participant | ||
->fill($data) | ||
->save(); | ||
|
||
$participant | ||
->receiver | ||
?->user | ||
?->notify(new SimpleMessageNotification('Получатель подарка "Тайного Санты" обновил информацию. Пожалуйста, проверьте.')); | ||
|
||
Toast::success('Ваша заявка на участие в принята! Готовьтесь к сюрпризу.') | ||
->disableAutoHide(); | ||
|
||
return redirect()->route('santa'); | ||
} | ||
|
||
/** | ||
* Отменяет заявку участника на участие. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function delete(Request $request): RedirectResponse | ||
{ | ||
$participant = $request->user() | ||
->secretSantaParticipant() | ||
->firstOrNew(); | ||
|
||
$participant->delete(); | ||
|
||
Toast::success('Ваша заявка на участие отозвана! Спасибо, что предупредили заранее.') | ||
->disableAutoHide(); | ||
|
||
return redirect()->route('santa'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Concerns\HasUuids; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\SoftDeletes; | ||
|
||
class SecretSantaParticipant extends Model | ||
{ | ||
use HasUuids, SoftDeletes; | ||
|
||
protected $fillable = [ | ||
'address', | ||
'about', | ||
'tracking_number', | ||
'telegram', | ||
'phone', | ||
]; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected $with = [ | ||
'receiver', | ||
]; | ||
|
||
// Связь с пользователем | ||
public function user() | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
|
||
// Связь с получателем | ||
public function receiver() | ||
{ | ||
return $this | ||
->belongsTo(SecretSantaParticipant::class, 'receiver_id', 'user_id') | ||
->without('receiver'); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasReceiver(): bool | ||
{ | ||
return $this->receiver_id !== null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
database/migrations/2024_12_08_212535_create_secret_santa_participants_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('secret_santa_participants', function (Blueprint $table) { | ||
$table->uuid('id')->primary(); | ||
|
||
$table->foreignId('user_id') | ||
->constrained() | ||
->onDelete('cascade') | ||
->comment('Идентификатор пользователя (отправителя), который участвует в Тайном Санте'); | ||
|
||
$table->text('address') | ||
->comment('Адрес участника для отправки подарка'); | ||
|
||
$table->string('telegram') | ||
->nullable() | ||
->comment('Телеграм участника для связи'); | ||
|
||
$table->string('phone') | ||
->comment('Контактные данные участника для связи'); | ||
|
||
$table->text('about') | ||
->comment('Информация о пользователе, которую он предоставляет о себе для получателя'); | ||
|
||
$table->foreignId('receiver_id') | ||
->nullable() | ||
->constrained('users') | ||
->onDelete('set null') | ||
->comment('Идентификатор пользователя (получателя) из таблицы пользователей'); | ||
|
||
$table->string('tracking_number') | ||
->comment('Номер отслеживания посылки') | ||
->nullable(); | ||
|
||
$table->string('status') | ||
->comment('Статус участника в Тайном Санте') | ||
->default('new'); | ||
|
||
$table->timestamps(); | ||
$table->softDeletes(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('secret_santa_participants'); | ||
} | ||
}; |
2 changes: 1 addition & 1 deletion
2
public/build/assets/app-bdQfWviv.css → public/build/assets/app-8jhtCGii.css
Large diffs are not rendered by default.
Oops, something went wrong.
36 changes: 18 additions & 18 deletions
36
public/build/assets/app-B969tbq3.js → public/build/assets/app-CDEY8pR7.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.