Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Тайный Санта #255

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions app/Http/Controllers/SantaController.php
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');
}
}
49 changes: 49 additions & 0 deletions app/Models/SecretSantaParticipant.php
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;
}
}
8 changes: 8 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ public function challengesReapositories()
return $this->hasMany(ChallengeApplication::class);
}

/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function secretSantaParticipant()
{
return $this->hasOne(SecretSantaParticipant::class);
}

/**
* Reward the user with an achievement.
*
Expand Down
18 changes: 18 additions & 0 deletions app/Notifications/SimpleMessageNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Notifications\Channels\SiteMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use NotificationChannels\WebPush\WebPushChannel;
use NotificationChannels\WebPush\WebPushMessage;
Expand Down Expand Up @@ -34,9 +35,26 @@ public function via(User $user)
return [
SiteChannel::class,
WebPushChannel::class,
'mail',
];
}

/**
* Get the mail representation of the notification.
*
* @param User $user
*
* @throws \Throwable
*
* @return MailMessage
*/
public function toMail(User $user)
{
return (new MailMessage)
->subject('Новое уведомление')
->line($this->message);
}

/**
* Get the app representation of the notification.
*
Expand Down
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');
}
};

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/build/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"src": "public/img/ui/blockquote/warning.svg"
},
"resources/css/app.scss": {
"file": "assets/app-bdQfWviv.css",
"file": "assets/app-8jhtCGii.css",
"src": "resources/css/app.scss",
"isEntry": true
},
"resources/js/app.js": {
"file": "assets/app-B969tbq3.js",
"file": "assets/app-CDEY8pR7.js",
"name": "app",
"src": "resources/js/app.js",
"isEntry": true,
Expand Down
13 changes: 13 additions & 0 deletions public/img/ui/santa/blob.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions public/img/ui/santa/pattern.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions public/img/ui/santa/snowflake-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions public/img/ui/santa/snowflake-3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions public/img/ui/santa/snowflake-4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading