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 631db2f commit 8a1fd36
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
17 changes: 17 additions & 0 deletions app/DTO/Api/Team/Request/TeamCreateDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\DTO\Api\Team\Request;

use Illuminate\Http\UploadedFile;
use Spatie\LaravelData\Attributes\Validation\Max;
use Spatie\LaravelData\Data;

class TeamCreateDTO extends Data
{
public function __construct(
public string $name,
public string $description,
public ?UploadedFile $image,
){
}
}
12 changes: 12 additions & 0 deletions app/Http/Controllers/Api/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Http\Controllers\Api;

use App\DTO\Api\Team\Request\TeamCreateDTO;
use App\DTO\Api\Team\Request\TeamUpdateDTO;
use App\Models\Team;
use App\Models\User;
Expand All @@ -18,6 +19,17 @@ public function __construct(
{
}

public function create(TeamCreateDTO $teamCreateDTO): array
{
$team = Team::query()->create([
'name' => $teamCreateDTO->name,
'description' => $teamCreateDTO->description,
'captain_id' => auth()->id(),
]);

return $team->toArray() ?? [];
}

public function show(int $id): array
{
return Team::query()->find($id)?->toArray() ?? [];
Expand Down
5 changes: 3 additions & 2 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
});

Route::group(['prefix' => 'teams'], static function () {
Route::get('/{id}', [TeamController::class, 'show'])->name('teams.show');
Route::post('/{id}', [TeamController::class, 'update'])->name('teams.update');
Route::post('/create', [TeamController::class, 'create'])->name('teams.create');
Route::get('/{id}/members', [TeamController::class, 'members'])->name('teams.members');
Route::get('/{id}/challenges', [TeamController::class, 'challenge'])->name('users.challenge');
Route::get('/{id}/achievements', [TeamController::class, 'achievements'])->name('teams.achievements');
Route::post('/{teamId}/delete/{userId}', [TeamController::class, 'delete'])->name('teams.delete');
Route::post('/{teamId}/join/member/{userId}', [TeamController::class, 'joinMember'])->name('teams.delete');
Route::post('/{id}', [TeamController::class, 'update'])->name('teams.update');
Route::get('/{id}', [TeamController::class, 'show'])->name('teams.show');
});

Route::group(['prefix' => 'challenges'], static function () {
Expand Down

0 comments on commit 8a1fd36

Please sign in to comment.