Skip to content

Commit

Permalink
feat: update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
deniskorbakov committed Oct 27, 2024
1 parent 8a1fd36 commit 3364719
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
27 changes: 25 additions & 2 deletions app/Http/Controllers/Api/ChallengeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\DTO\Api\Challenge\Request\ChallengeFilterDTO;
use App\Models\Challenge;
use App\Models\Team;
use App\Models\User;
use App\Services\Api\ChallengeService;

class ChallengeController extends Controller
Expand All @@ -25,13 +27,34 @@ public function show(int $id): array
return $this->challengeService->show($challenge);
}

public function joinPersonal(): array
public function joinPersonal(int $id, int $userId): array
{
$user = User::query()->find($userId);
$challenge = Challenge::query()->find($id);

if ($user && $user->telegram_id && $challenge) {
$tg = new TelegramController();
$tg->sendMessage($user->telegram_id, 'Уведомление о челлендже - ' . $challenge->name);

return ['success' => true];
}

return [];
}

public function joinTeam(): array
public function joinTeam(int $id, int $teamId): array
{
$challenge = Challenge::query()->find($id);

$team = Team::query()->find($teamId);
$user = User::query()->find($team?->captain_id);

if ($team && $user && $user->telegram_id && $challenge) {
$tg = new TelegramController();

$tg->sendMessage($user->telegram_id, 'Отправили вашей команде вызов на челлендж - ' . $challenge->name);
}

return [];
}
}
8 changes: 4 additions & 4 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
});

Route::group(['prefix' => 'challenges'], static function () {
Route::get('/', [ChallengeController::class, 'index'])->name('teams.index');
Route::get('/{id}', [ChallengeController::class, 'show'])->name('teams.show');
Route::post('/{id}/joins/personal', [ChallengeController::class, 'joinPersonal'])->name('teams.joinPersonal');
Route::post('/{id}/joins/teams', [ChallengeController::class, 'joinTeam'])->name('teams.joinTeam');
Route::get('/', [ChallengeController::class, 'index'])->name('challenges.index');
Route::get('/{id}', [ChallengeController::class, 'show'])->name('challenges.show');
Route::post('/{id}/joins/personal/{userId}', [ChallengeController::class, 'joinPersonal'])->name('challenges.joinPersonal');
Route::post('/{id}/joins/teams/{teamId}', [ChallengeController::class, 'joinTeam'])->name('challenges.joinTeam');
});
});

Expand Down

0 comments on commit 3364719

Please sign in to comment.