From c61cf87937b6c8aceaeddf4c6e427fc3a8747115 Mon Sep 17 00:00:00 2001 From: deniskorbakov Date: Sun, 27 Oct 2024 02:57:29 +0300 Subject: [PATCH] feat: add logic --- app/DTO/Api/Team/Request/TeamUpdateDTO.php | 19 +++++++++++ app/Http/Controllers/Api/TeamController.php | 30 ++++++++++++++++ .../Enums/Challenge}/ChallengeType.php | 2 +- app/Models/Team.php | 3 +- app/Services/Api/TeamService.php | 34 +++++++++++++++++++ config/auth.php | 2 +- database/factories/ChallengeFactory.php | 2 +- routes/api.php | 6 ++++ 8 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 app/DTO/Api/Team/Request/TeamUpdateDTO.php create mode 100644 app/Http/Controllers/Api/TeamController.php rename app/{Enums => Models/Enums/Challenge}/ChallengeType.php (85%) create mode 100644 app/Services/Api/TeamService.php diff --git a/app/DTO/Api/Team/Request/TeamUpdateDTO.php b/app/DTO/Api/Team/Request/TeamUpdateDTO.php new file mode 100644 index 0000000..ec9997e --- /dev/null +++ b/app/DTO/Api/Team/Request/TeamUpdateDTO.php @@ -0,0 +1,19 @@ +findOrFail($id)?->toArray(); + } + + public function update(int $id, TeamUpdateDTO $teamUpdateDTO): array|JsonResponse + { + $team = Team::query()->findOrFail($id); + + return $this->teamService->update($team, $teamUpdateDTO); + } +} diff --git a/app/Enums/ChallengeType.php b/app/Models/Enums/Challenge/ChallengeType.php similarity index 85% rename from app/Enums/ChallengeType.php rename to app/Models/Enums/Challenge/ChallengeType.php index 6ea21af..b8d0d7f 100644 --- a/app/Enums/ChallengeType.php +++ b/app/Models/Enums/Challenge/ChallengeType.php @@ -1,6 +1,6 @@ captain_id === auth()->id()) { + $savedImage = null; + + if ($teamUpdateDTO->image) { + $savedImage = $teamUpdateDTO->image->store(options: ['disk' => 'public']); + } + + $team->update([ + 'image' => Storage::disk('public')->url($savedImage), + 'name' => $teamUpdateDTO->name, + 'description' => $teamUpdateDTO->description, + ]); + + return $team->toArray(); + } + + return response()->json(['message' => 'you are dont captain'], 403); + } +} diff --git a/config/auth.php b/config/auth.php index 0ba5d5d..84e3969 100644 --- a/config/auth.php +++ b/config/auth.php @@ -110,6 +110,6 @@ | */ - 'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800), + 'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 1080000000), ]; diff --git a/database/factories/ChallengeFactory.php b/database/factories/ChallengeFactory.php index d1283db..5c09569 100644 --- a/database/factories/ChallengeFactory.php +++ b/database/factories/ChallengeFactory.php @@ -4,8 +4,8 @@ namespace Database\Factories; -use App\Enums\ChallengeType; use App\Models\Achievement; +use App\Models\Enums\Challenge\ChallengeType; use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\Factory; diff --git a/routes/api.php b/routes/api.php index 0a3addf..c7c7970 100755 --- a/routes/api.php +++ b/routes/api.php @@ -3,6 +3,7 @@ declare(strict_types=1); use App\Http\Controllers\Api\AuthController; +use App\Http\Controllers\Api\TeamController; use App\Http\Controllers\Api\UserController; use Illuminate\Support\Facades\Route; @@ -17,4 +18,9 @@ Route::get('/{id}/challenges', [UserController::class, 'challenge'])->name('users.challenge'); Route::get('/{id}/achievements', [UserController::class, 'achievement'])->name('users.achievement'); }); + + Route::group(['prefix' => 'teams'], static function () { + Route::get('/{id}', [TeamController::class, 'show'])->name('teams.show'); + Route::post('/{id}', [TeamController::class, 'update'])->name('teams.update'); + }); });