From 6bd4bdd3cfe128df1b8caa5131b450c81a5a9069 Mon Sep 17 00:00:00 2001 From: shin-mallang Date: Tue, 2 Jan 2024 08:16:06 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[#197]=20feat:=20=EB=B8=94=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=9D=B4=EB=A6=84=20=EC=A4=91=EB=B3=B5=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/mallang/blog/query/BlogQueryService.java | 4 ++++ .../mallang/blog/query/repository/BlogQueryRepository.java | 3 +++ .../mallang/blog/query/response/CheckDuplicateResponse.java | 6 ++++++ 3 files changed, 13 insertions(+) create mode 100644 src/main/java/com/mallang/blog/query/response/CheckDuplicateResponse.java diff --git a/src/main/java/com/mallang/blog/query/BlogQueryService.java b/src/main/java/com/mallang/blog/query/BlogQueryService.java index f7fe54a5..dc1788c2 100644 --- a/src/main/java/com/mallang/blog/query/BlogQueryService.java +++ b/src/main/java/com/mallang/blog/query/BlogQueryService.java @@ -24,4 +24,8 @@ public BlogResponse findByOwnerId(Long memberId) { Member member = memberQueryRepository.getById(memberId); return BlogResponse.from(blogQueryRepository.getByOwner(member)); } + + public boolean checkDuplicatedBlogName(String blogName) { + return blogQueryRepository.existsByName(blogName); + } } diff --git a/src/main/java/com/mallang/blog/query/repository/BlogQueryRepository.java b/src/main/java/com/mallang/blog/query/repository/BlogQueryRepository.java index c1005387..3d6d0978 100644 --- a/src/main/java/com/mallang/blog/query/repository/BlogQueryRepository.java +++ b/src/main/java/com/mallang/blog/query/repository/BlogQueryRepository.java @@ -38,4 +38,7 @@ default Blog getByOwner(Member owner) { } Optional findByOwner(Member owner); + + @Query("SELECT COUNT(b) > 0 FROM Blog b WHERE b.name.value = :blogName") + boolean existsByName(@Param("blogName") String blogName); } diff --git a/src/main/java/com/mallang/blog/query/response/CheckDuplicateResponse.java b/src/main/java/com/mallang/blog/query/response/CheckDuplicateResponse.java new file mode 100644 index 00000000..dcf1fae8 --- /dev/null +++ b/src/main/java/com/mallang/blog/query/response/CheckDuplicateResponse.java @@ -0,0 +1,6 @@ +package com.mallang.blog.query.response; + +public record CheckDuplicateResponse( + boolean duplicated +) { +} From c8f7da4990a0f4ff9bd00c390c64ea96ceb6dcdf Mon Sep 17 00:00:00 2001 From: shin-mallang Date: Tue, 2 Jan 2024 08:16:16 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[#197]=20feat:=20=EB=B8=94=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=9D=B4=EB=A6=84=20=EC=A4=91=EB=B3=B5=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20API=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mallang/auth/config/AuthConfig.java | 1 + .../blog/presentation/BlogController.java | 10 ++++++ .../acceptance/blog/BlogAcceptanceSteps.java | 8 +++++ .../acceptance/blog/BlogAcceptanceTest.java | 32 ++++++++++++++++++- 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mallang/auth/config/AuthConfig.java b/src/main/java/com/mallang/auth/config/AuthConfig.java index 650af9dd..d5c88d93 100644 --- a/src/main/java/com/mallang/auth/config/AuthConfig.java +++ b/src/main/java/com/mallang/auth/config/AuthConfig.java @@ -54,6 +54,7 @@ private AuthInterceptor setUpAuthInterceptor() { .uriPatterns(Set.of( "/members/*", "/blogs", + "/blogs/duplicate", "/posts/**", "/categories", "/comments", diff --git a/src/main/java/com/mallang/blog/presentation/BlogController.java b/src/main/java/com/mallang/blog/presentation/BlogController.java index 186dbb5f..c7ddfe50 100644 --- a/src/main/java/com/mallang/blog/presentation/BlogController.java +++ b/src/main/java/com/mallang/blog/presentation/BlogController.java @@ -5,8 +5,10 @@ import com.mallang.blog.presentation.request.OpenBlogRequest; import com.mallang.blog.query.BlogQueryService; import com.mallang.blog.query.response.BlogResponse; +import com.mallang.blog.query.response.CheckDuplicateResponse; import java.net.URI; import lombok.RequiredArgsConstructor; +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.PostMapping; @@ -45,4 +47,12 @@ public ResponseEntity findMyBlog( ) { return ResponseEntity.ok(blogQueryService.findByOwnerId(memberId)); } + + @GetMapping("/duplicate") + public ResponseEntity checkDuplicate( + @Param("blogName") String blogName + ) { + boolean duplicated = blogQueryService.checkDuplicatedBlogName(blogName); + return ResponseEntity.ok(new CheckDuplicateResponse(duplicated)); + } } diff --git a/src/test/java/com/mallang/acceptance/blog/BlogAcceptanceSteps.java b/src/test/java/com/mallang/acceptance/blog/BlogAcceptanceSteps.java index d225074c..73826792 100644 --- a/src/test/java/com/mallang/acceptance/blog/BlogAcceptanceSteps.java +++ b/src/test/java/com/mallang/acceptance/blog/BlogAcceptanceSteps.java @@ -28,6 +28,14 @@ public class BlogAcceptanceSteps { .extract(); } + public static ExtractableResponse 블로그_이름_중복_확인_요청(String 이름) { + return given() + .queryParam("blogName", 이름) + .get("/blogs/duplicate") + .then() + .extract(); + } + public static ExtractableResponse 블로그_정보_조회_요청(String 블로그_이름) { return given() .queryParam("blogName", 블로그_이름) diff --git a/src/test/java/com/mallang/acceptance/blog/BlogAcceptanceTest.java b/src/test/java/com/mallang/acceptance/blog/BlogAcceptanceTest.java index 65cbea40..6e13c61d 100644 --- a/src/test/java/com/mallang/acceptance/blog/BlogAcceptanceTest.java +++ b/src/test/java/com/mallang/acceptance/blog/BlogAcceptanceTest.java @@ -11,12 +11,14 @@ import static com.mallang.acceptance.auth.AuthAcceptanceSteps.회원가입과_로그인_후_세션_ID_반환; import static com.mallang.acceptance.blog.BlogAcceptanceSteps.내_블로그_정보_조회_요청; import static com.mallang.acceptance.blog.BlogAcceptanceSteps.블로그_개설_요청; +import static com.mallang.acceptance.blog.BlogAcceptanceSteps.블로그_이름_중복_확인_요청; import static com.mallang.acceptance.blog.BlogAcceptanceSteps.블로그_정보_조회_요청; import static org.assertj.core.api.Assertions.assertThat; import com.mallang.acceptance.AcceptanceTest; import com.mallang.blog.query.response.BlogResponse; import com.mallang.blog.query.response.BlogResponse.OwnerResponse; +import com.mallang.blog.query.response.CheckDuplicateResponse; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; @@ -29,7 +31,35 @@ class BlogAcceptanceTest extends AcceptanceTest { @Nested - class 블로그_조회_API { + class 블로그_이름_중복_체크_API { + + @Test + void 주어진_이름이_이미_사용중이면_중복됨() { + // given + var 말랑_세션_ID = 회원가입과_로그인_후_세션_ID_반환("말랑"); + 블로그_개설_요청(말랑_세션_ID, "mallang-blog"); + + // when + var 응답 = 블로그_이름_중복_확인_요청("mallang-blog"); + + // then + CheckDuplicateResponse response = 응답.as(CheckDuplicateResponse.class); + assertThat(response.duplicated()).isTrue(); + } + + @Test + void 주어진_이름이_사용중이지_않으면_중복되지_않음() { + // when + var 응답 = 블로그_이름_중복_확인_요청("mallang-blog"); + + // then + CheckDuplicateResponse response = 응답.as(CheckDuplicateResponse.class); + assertThat(response.duplicated()).isFalse(); + } + } + + @Nested + class 블로그_개설_API { @Test void 블로그를_개설한다() { From 2b4b42bb5c3c730d57aa2cf9954cc8aa85798ba1 Mon Sep 17 00:00:00 2001 From: shin-mallang Date: Tue, 2 Jan 2024 08:21:11 +0900 Subject: [PATCH 3/3] =?UTF-8?q?test:=20=EB=A1=9C=EA=B7=B8=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0,=20=EA=B3=B5=EB=B0=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mallang/acceptance/auth/MemberAcceptanceSteps.java | 1 - .../java/com/mallang/acceptance/auth/MemberAcceptanceTest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/test/java/com/mallang/acceptance/auth/MemberAcceptanceSteps.java b/src/test/java/com/mallang/acceptance/auth/MemberAcceptanceSteps.java index 53558c44..2b3d29f0 100644 --- a/src/test/java/com/mallang/acceptance/auth/MemberAcceptanceSteps.java +++ b/src/test/java/com/mallang/acceptance/auth/MemberAcceptanceSteps.java @@ -35,7 +35,6 @@ public class MemberAcceptanceSteps { return given(세션) .get("/members/logout") .then() - .log().all() .extract(); } diff --git a/src/test/java/com/mallang/acceptance/auth/MemberAcceptanceTest.java b/src/test/java/com/mallang/acceptance/auth/MemberAcceptanceTest.java index 39981de6..a6c49968 100644 --- a/src/test/java/com/mallang/acceptance/auth/MemberAcceptanceTest.java +++ b/src/test/java/com/mallang/acceptance/auth/MemberAcceptanceTest.java @@ -133,7 +133,6 @@ void setUp() { } } - @Nested class 로그아웃_API {