Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 블로그 이름 중복 확인 기능 #198

Merged
merged 3 commits into from
Jan 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[#197] feat: 블로그 이름 중복 확인 API 작성
  • Loading branch information
shin-mallang committed Jan 1, 2024
commit c8f7da4990a0f4ff9bd00c390c64ea96ceb6dcdf
1 change: 1 addition & 0 deletions src/main/java/com/mallang/auth/config/AuthConfig.java
Original file line number Diff line number Diff line change
@@ -54,6 +54,7 @@ private AuthInterceptor setUpAuthInterceptor() {
.uriPatterns(Set.of(
"/members/*",
"/blogs",
"/blogs/duplicate",
"/posts/**",
"/categories",
"/comments",
10 changes: 10 additions & 0 deletions src/main/java/com/mallang/blog/presentation/BlogController.java
Original file line number Diff line number Diff line change
@@ -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<BlogResponse> findMyBlog(
) {
return ResponseEntity.ok(blogQueryService.findByOwnerId(memberId));
}

@GetMapping("/duplicate")
public ResponseEntity<CheckDuplicateResponse> checkDuplicate(
@Param("blogName") String blogName
) {
boolean duplicated = blogQueryService.checkDuplicatedBlogName(blogName);
return ResponseEntity.ok(new CheckDuplicateResponse(duplicated));
}
}
Original file line number Diff line number Diff line change
@@ -28,6 +28,14 @@ public class BlogAcceptanceSteps {
.extract();
}

public static ExtractableResponse<Response> 블로그_이름_중복_확인_요청(String 이름) {
return given()
.queryParam("blogName", 이름)
.get("/blogs/duplicate")
.then()
.extract();
}

public static ExtractableResponse<Response> 블로그_정보_조회_요청(String 블로그_이름) {
return given()
.queryParam("blogName", 블로그_이름)
Original file line number Diff line number Diff line change
@@ -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 블로그를_개설한다() {