Skip to content

Commit

Permalink
feat: 아이디 중복체크 기능 (#183)
Browse files Browse the repository at this point in the history
* [#181] feat: 아이디 중복 체크 서비스 로직 작성

* [#181] feat: 아이디 중복 체크 API 작성
  • Loading branch information
shin-mallang authored Jan 1, 2024
1 parent 7891540 commit 8deab81
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public Long login(String username, String rawPassword) {
member.login(rawPassword, passwordEncoder);
return member.getId();
}

public boolean checkDuplicatedUsername(String username) {
return basicMemberRepository.existsByUsername(username);
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/mallang/auth/presentation/MemberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mallang.auth.application.BasicAuthService;
import com.mallang.auth.presentation.request.BasicLoginRequest;
import com.mallang.auth.presentation.request.BasicSignupRequest;
import com.mallang.auth.presentation.response.CheckDuplicateResponse;
import com.mallang.auth.presentation.support.Auth;
import com.mallang.auth.query.MemberQueryService;
import com.mallang.auth.query.response.MemberResponse;
Expand All @@ -15,6 +16,7 @@
import java.net.URI;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.repository.query.Param;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -34,6 +36,14 @@ public class MemberController {
@Value("${auth.session.ttl}")
private Integer authSessionTTL;

@GetMapping("/check-duplicate")
public ResponseEntity<CheckDuplicateResponse> checkDuplicate(
@Param("username") String username
) {
boolean duplicated = basicAuthService.checkDuplicatedUsername(username);
return ResponseEntity.ok(new CheckDuplicateResponse(duplicated));
}

@PostMapping
public ResponseEntity<Void> signup(
@Valid @RequestBody BasicSignupRequest request
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.mallang.auth.presentation.response;

public record CheckDuplicateResponse(
boolean duplicated
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
@SuppressWarnings("NonAsciiCharacters")
public class MemberAcceptanceSteps {

public static ExtractableResponse<Response> 아이디_중복_체크_요청(String username) {
return given()
.queryParam("username", username)
.get("/members/check-duplicate")
.then()
//.log().all()
.extract();
}

public static ExtractableResponse<Response> 일반_회원가입_요청(BasicSignupRequest request) {
return given()
.body(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static com.mallang.acceptance.AcceptanceSteps.찾을수_없음;
import static com.mallang.acceptance.auth.AuthAcceptanceSteps.회원가입과_로그인_후_세션_ID_반환;
import static com.mallang.acceptance.auth.MemberAcceptanceSteps.내_정보_조회_요청;
import static com.mallang.acceptance.auth.MemberAcceptanceSteps.아이디_중복_체크_요청;
import static com.mallang.acceptance.auth.MemberAcceptanceSteps.일반_로그인_요청;
import static com.mallang.acceptance.auth.MemberAcceptanceSteps.일반_회원가입_요청;
import static com.mallang.acceptance.auth.MemberAcceptanceSteps.회원_정보_조회_결과_데이터;
Expand All @@ -17,6 +18,7 @@

import com.mallang.acceptance.AcceptanceTest;
import com.mallang.auth.presentation.request.BasicSignupRequest;
import com.mallang.auth.presentation.response.CheckDuplicateResponse;
import com.mallang.auth.query.response.MemberResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -39,6 +41,33 @@ class MemberAcceptanceTest extends AcceptanceTest {
"profile"
);

@Nested
class 아이디_중복_체크_API {

@Test
void 주어진_아이디가_이미_존재하면_중복됨() {
// given
일반_회원가입_요청(회원가입_요청);

// when
var 응답 = 아이디_중복_체크_요청(아이디);

// then
CheckDuplicateResponse response = 응답.as(CheckDuplicateResponse.class);
assertThat(response.duplicated()).isTrue();
}

@Test
void 주어진_아이디가_존재하지_않으면_중복되지_않음() {
// when
var 응답 = 아이디_중복_체크_요청(아이디);

// then
CheckDuplicateResponse response = 응답.as(CheckDuplicateResponse.class);
assertThat(response.duplicated()).isFalse();
}
}

@Nested
class 회원가입_API {

Expand Down

0 comments on commit 8deab81

Please sign in to comment.