Skip to content

Commit

Permalink
fix: update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
deniskorbakov committed Oct 27, 2024
1 parent c468026 commit fa9d98d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
23 changes: 23 additions & 0 deletions app/DTO/Api/User/Response/UserShowDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\DTO\Api\User\Response;

use App\Models\User;
use Spatie\LaravelData\Data;

class UserShowDTO extends Data
{
public function __construct(
public User $user,
public bool $isEditor
){
}

public static function fromModel(User $user): self
{
return new self(
$user,
$user->id === auth()->id()
);
}
}
10 changes: 10 additions & 0 deletions app/Http/Controllers/Api/ChallengeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ public function show(int $id): array

return $this->challengeService->show($challenge);
}

public function joinPersonal(): array
{
return [];
}

public function joinTeam(): array
{
return [];
}
}
4 changes: 3 additions & 1 deletion app/Http/Controllers/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public function __construct(

public function show(int $id): array
{
return User::query()->findOrFail($id)?->toArray();
$user = User::query()->findOrFail($id);

return $this->userService->show($user);
}

public function update(int $id, UserUpdateDTO $userUpdateDTO): array|JsonResponse
Expand Down
6 changes: 6 additions & 0 deletions app/Services/Api/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\DTO\Api\User\Response\UserAchievementPersonalDTO;
use App\DTO\Api\User\Response\UserAchievementTeamsDTO;
use App\DTO\Api\User\Response\UserChallengeDTO;
use App\DTO\Api\User\Response\UserShowDTO;
use App\DTO\Api\User\Response\UserTeamDTO;
use App\Models\Team;
use App\Models\User;
Expand All @@ -16,6 +17,11 @@

class UserService
{
public function show(User $user): array
{
return UserShowDTO::from($user)->toArray();
}

public function achievement(Team $team, User $user): array
{
$achievementPersonal = $user->achievements()->get();
Expand Down
2 changes: 2 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
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');
});
});

Expand Down

0 comments on commit fa9d98d

Please sign in to comment.