Skip to content

Commit

Permalink
remove: 일반 회원 관련 API 제거 (#204)
Browse files Browse the repository at this point in the history
* [#194] refactor: 아이디 중복 체크를 query service에서 담당

* [#194] remove: 일반 회원가입 API 제거
  • Loading branch information
shin-mallang authored Jan 6, 2024
1 parent f046ab6 commit f6e7e75
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,4 @@ public Long login(String username, String rawPassword) {
member.login(rawPassword, passwordEncoder);
return member.getId();
}

public boolean checkDuplicatedUsername(String username) {
return basicMemberRepository.existsByUsername(username);
}
}
44 changes: 0 additions & 44 deletions src/main/java/com/mallang/auth/presentation/MemberController.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
package com.mallang.auth.presentation;

import static com.mallang.auth.presentation.support.AuthConstant.MEMBER_ID;
import static org.springframework.http.HttpStatus.OK;

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;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
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;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -32,40 +20,8 @@
@RestController
public class MemberController {

private final BasicAuthService basicAuthService;
private final MemberQueryService memberQueryService;

@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
) {
Long id = basicAuthService.signup(request.toCommand());
return ResponseEntity.created(URI.create("/members/" + id)).build();
}

@PostMapping("/login")
public ResponseEntity<Void> login(
@Valid @RequestBody BasicLoginRequest request,
HttpServletRequest httpServletRequest
) {
Long memberId = basicAuthService.login(request.username(), request.password());
HttpSession session = httpServletRequest.getSession(true);
session.setAttribute(MEMBER_ID, memberId);
session.setMaxInactiveInterval(authSessionTTL);
return ResponseEntity.status(OK).build();
}

@GetMapping("/logout")
public ResponseEntity<Void> logout(
HttpServletRequest request,
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/mallang/auth/query/BasicAuthQueryService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mallang.auth.query;

import com.mallang.auth.query.repository.BasicMemberQueryRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class BasicAuthQueryService {

private final BasicMemberQueryRepository basicMemberQueryRepository;

public boolean checkDuplicatedUsername(String username) {
return basicMemberQueryRepository.existsByUsername(username);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mallang.auth.query.repository;

import com.mallang.auth.domain.BasicMember;
import org.springframework.data.jpa.repository.JpaRepository;

public interface BasicMemberQueryRepository extends JpaRepository<BasicMember, Long> {

boolean existsByUsername(String username);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mallang.auth.presentation.response;
package com.mallang.auth.query.response;

public record CheckDuplicateResponse(
boolean duplicated
Expand Down
100 changes: 0 additions & 100 deletions src/test/java/com/mallang/acceptance/auth/MemberAcceptanceTest.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
package com.mallang.acceptance.auth;

import static com.mallang.acceptance.AcceptanceSteps.생성됨;
import static com.mallang.acceptance.AcceptanceSteps.응답_상태를_검증한다;
import static com.mallang.acceptance.AcceptanceSteps.인증되지_않음;
import static com.mallang.acceptance.AcceptanceSteps.정상_처리;
import static com.mallang.acceptance.AcceptanceSteps.중복됨;
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.일반_회원가입_요청;
import static com.mallang.acceptance.auth.MemberAcceptanceSteps.회원_정보_조회_결과_데이터;
import static com.mallang.acceptance.auth.MemberAcceptanceSteps.회원_정보_조회_결과를_검증한다;
import static com.mallang.acceptance.auth.MemberAcceptanceSteps.회원_정보_조회_요청;
import static org.assertj.core.api.Assertions.assertThat;

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;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
Expand All @@ -42,97 +33,6 @@ 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 {

@Test
void 회원가입한다() {
// when
var 응답 = 일반_회원가입_요청(회원가입_요청);

// then
응답_상태를_검증한다(응답, 생성됨);
}

@Test
void 아이디가_중복되면_예외() {
// given
일반_회원가입_요청(회원가입_요청);

// when
var 응답 = 일반_회원가입_요청(회원가입_요청);

// then
응답_상태를_검증한다(응답, 중복됨);
}
}

@Nested
class 로그인_API {

@BeforeEach
void setUp() {
일반_회원가입_요청(회원가입_요청);
}

@Test
void 로그인한다() {
// when
var 응답 = 일반_로그인_요청(아이디, 비밀번호);

// then
응답_상태를_검증한다(응답, 정상_처리);
assertThat(응답.cookie("JSESSIONID")).isNotNull();
}

@Test
void 아이디가_없으면_예외() {
// when
var 응답 = 일반_로그인_요청(아이디 + "wrong", 비밀번호);

// then
응답_상태를_검증한다(응답, 찾을수_없음);
assertThat(응답.cookie("JSESSIONID")).isNull();
}

@Test
void 비밀번호가_없으면_예외() {
// when
var 응답 = 일반_로그인_요청(아이디, 비밀번호 + "wrong");

// then
응답_상태를_검증한다(응답, 인증되지_않음);
assertThat(응답.cookie("JSESSIONID")).isNull();
}
}

@Nested
class 로그아웃_API {

Expand Down

0 comments on commit f6e7e75

Please sign in to comment.