Skip to content

Commit

Permalink
nickname search
Browse files Browse the repository at this point in the history
add nickname search for nickname duplicate check
  • Loading branch information
huntmori committed Feb 1, 2024
1 parent 3b5d91d commit db0d713
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,22 @@

$group->get(
"/{uid}",
ProfileController::class.":getProfile"
ProfileController::class . ":getProfile"
)->add(JwtMiddleware::class);

$group->get(
"",
ProfileController::class.":getProfiles"
ProfileController::class . ":getProfiles"
)->add(JwtMiddleware::class);

$group->patch(
"/{uid}/activation",
ProfileController::class.":updateProfileActivation"
ProfileController::class . ":updateProfileActivation"
)->add(JwtMiddleware::class);

$group->get(
"/nickname/{nickname}",
ProfileController::class . ":searchByNickname"
)->add(JwtMiddleware::class);
});
/*
Expand Down
2 changes: 2 additions & 0 deletions src/Domain/Profile/Repository/ProfileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public function getUserProfileByUserIdxAndActivate(string $userUid, bool $activa
public function checkNicknameCount(string $nickname) : int;

public function updateProfileActivation(Profile $profile, bool $activation) : ?Profile;

public function getListByNickname(?string $getNickname) : array;
}
24 changes: 24 additions & 0 deletions src/Domain/Profile/Repository/ProfileRepositoryImplement.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,28 @@ public function updateProfileActivation(Profile $profile, bool $activation) : ?P

return $this->getUserProfileByProfileUid($profile->getUid());
}

public function getListByNickname(?string $getNickname) : array
{
$sql = "
SELECT
pro.idx,
pro.uid,
pro.user_uid as userUid,
pro.profile_nickname as profileNickName,
pro.is_primary as isPrimary,
pro.deleted,
pro.activated,
pro.banned,
pro.created_at as createdAt,
pro.updated_at as updatedAt
FROM
profile pro
WHERE 1=1
AND pro.profile_nickname = :nickname
";
$paramMap = [ 'nickname' => $getNickname];
$returnType = Profile::class;
return $this->selectList($sql, $paramMap, $returnType);
}
}
18 changes: 18 additions & 0 deletions src/Domain/Profile/controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Domain\Profile\models\ProfileGetByIdRequest;
use App\Domain\Profile\models\ProfileGetListRequest;
use App\Domain\Profile\models\ProfilePatchActivationRequest;
use App\Domain\Profile\models\SearchByNicknameRequest;
use App\Domain\Profile\service\ProfileService;
use App\Domain\User\service\UserService;
use Psr\Http\Message\ResponseInterface as Response;
Expand Down Expand Up @@ -99,4 +100,21 @@ public function updateProfileActivation(Request $request, Response $response, ar
return $this->respondWithData($response, $result->toArray(), 200);
}

public function searchByNickname(Request $request, Response $response, array $args): Response
{
$requestDto = new SearchByNicknameRequest($request, $args);
$profiles = $this->profileService->searchByNickname($requestDto);
$result = [];
for($i=0;$i<count($profiles);$i++) {
/** @var Profile $profile */
$profile = $profiles[$i];
$result[] = $profile->toArray();
}

return $this->respondWithData(
$response,
$result,
200
);
}
}
45 changes: 45 additions & 0 deletions src/Domain/Profile/models/SearchByNicknameRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Domain\Profile\models;

use App\Domain\Common\models\AuthorizationRequestTrait;
use App\Domain\Common\models\BaseDto;
use Psr\Http\Message\RequestInterface;

class SearchByNicknameRequest
{
public ?string $nickname;
private ?string $token;

use AuthorizationRequestTrait;

public function __construct(RequestInterface $request, array $arg)
{
$this->nickname = $arg['nickname'];
echo $this->getNickname().PHP_EOL;

$this->token = $this->extractToken($request);
}

public function getNickname(): ?string
{
return $this->nickname;
}

public function setNickname(?string $nickname): void
{
$this->nickname = $nickname;
}

public function getToken(): ?string
{
return $this->token;
}

public function setToken(?string $token): void
{
$this->token = $token;
}


}
3 changes: 3 additions & 0 deletions src/Domain/Profile/service/ProfileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Domain\Profile\entities\Profile;
use App\Domain\Profile\models\ProfileCreateRequest;
use App\Domain\Profile\models\ProfileGetByIdRequest;
use App\Domain\Profile\models\SearchByNicknameRequest;
use App\Domain\User\entities\User;

interface ProfileService
Expand All @@ -23,4 +24,6 @@ public function updateProfileActivation(User $user, Profile $profile, bool $acti

public function getUserProfileByProfileUid(string $uid) : ?Profile;

public function searchByNickname(SearchByNicknameRequest $requestDto) : array;

}
6 changes: 6 additions & 0 deletions src/Domain/Profile/service/ProfileServiceImplement.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Domain\Profile\entities\Profile;
use App\Domain\Profile\models\ProfileCreateRequest;
use App\Domain\Profile\models\ProfileGetByIdRequest;
use App\Domain\Profile\models\SearchByNicknameRequest;
use App\Domain\Profile\Repository\ProfileRepository;
use App\Domain\User\entities\User;
use App\Domain\User\repository\UserRepository;
Expand Down Expand Up @@ -138,4 +139,9 @@ public function getUserProfileByProfileUid(string $uid): ?Profile
{
return $this->profileRepository->getUserProfileByProfileUid($uid);
}

public function searchByNickname(SearchByNicknameRequest $requestDto): array
{
return $this->profileRepository->getListByNickname($requestDto->getNickname());
}
}

0 comments on commit db0d713

Please sign in to comment.