From e66c55e832c5cbb956b4dfe7429bbe4cfce28483 Mon Sep 17 00:00:00 2001 From: Donggi Lee Date: Mon, 9 Oct 2023 00:22:31 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EB=A1=9C=20=EC=A7=88=EB=AC=B8=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EC=B6=94=EA=B0=80=20/=20RestDocs=20?= =?UTF-8?q?=EB=AC=B8=EC=84=9C=20=EC=B6=94=EA=B0=80=20(#93)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 카테고리로 질문 리스트 조회 API 추가 / RestDocs 문서 추가 * docs: API 문서 최신화 --- src/docs/asciidoc/question/question-read.adoc | 20 +- .../question/application/QuestionFinder.java | 10 +- .../question/application/QuestionService.java | 17 +- .../question/domain/QuestionRepository.java | 9 + .../infrastructure/QuestionJpaRepository.java | 3 + .../web/question/QuestionRestController.java | 19 +- src/main/resources/static/docs/index.html | 590 +++++++++++++----- ...uestionReadRestControllerRestDocsTest.java | 42 ++ 8 files changed, 536 insertions(+), 174 deletions(-) diff --git a/src/docs/asciidoc/question/question-read.adoc b/src/docs/asciidoc/question/question-read.adoc index e2f3801..973986d 100644 --- a/src/docs/asciidoc/question/question-read.adoc +++ b/src/docs/asciidoc/question/question-read.adoc @@ -1,4 +1,4 @@ -=== 카테고리 질문 조회 +=== 카테고리로 질문 id 리스트 조회 API : `GET /api/golrabas/category/{category}` @@ -28,6 +28,24 @@ include::{snippets}/questions-read-invalid-category/response-body.adoc[] ===== HTTP Response include::{snippets}/questions-read-invalid-category/http-response.adoc[] +=== 카테고리로 질문 리스트 조회 + +API : `GET /api/golrabas/category/{category}/question` + +==== 성공 +===== Path Parameters +include::{snippets}/question-list-read-by-category/path-parameters.adoc[] +===== HTTP Request +include::{snippets}/question-list-read-by-category/http-request.adoc[] + +==== Response +===== Response Fields +include::{snippets}/question-list-read-by-category/response-fields.adoc[] +===== Response Body +include::{snippets}/question-list-read-by-category/response-body.adoc[] +===== HTTP Response +include::{snippets}/question-list-read-by-category/http-response.adoc[] + === 특정 질문 조회 API : `GET /api/golrabas/{questionId}` diff --git a/src/main/java/donggi/dev/kkeuroolryo/core/question/application/QuestionFinder.java b/src/main/java/donggi/dev/kkeuroolryo/core/question/application/QuestionFinder.java index 6ea0868..d2f2741 100644 --- a/src/main/java/donggi/dev/kkeuroolryo/core/question/application/QuestionFinder.java +++ b/src/main/java/donggi/dev/kkeuroolryo/core/question/application/QuestionFinder.java @@ -30,7 +30,7 @@ public interface QuestionFinder { * @param noOffsetPageCommand 페이징 정보가 담긴 객체 * @return 페이징된 질문 객체 */ - QuestionPaginationDto findAllBy(NoOffsetPageCommand noOffsetPageCommand); + QuestionPaginationDto findAllIdsByCategory(NoOffsetPageCommand noOffsetPageCommand); /** * 질문을 키워드로 검색하여 리스트로 조회합니다. @@ -39,4 +39,12 @@ public interface QuestionFinder { * @return 페이징된 질문 객체 */ QuestionPaginationDto search(String keyword, NoOffsetPageCommand noOffsetPageCommand); + + /** + * 어드민에서 카테고리로 질문 리스트를 조회합니다. + * @param category 조회할 카테고리 + * @param pageCommand 페이징 정보가 담긴 객체 + * @return 페이징된 질문 객체 + */ + QuestionPaginationDto findAllByCategory(Category category, NoOffsetPageCommand pageCommand); } diff --git a/src/main/java/donggi/dev/kkeuroolryo/core/question/application/QuestionService.java b/src/main/java/donggi/dev/kkeuroolryo/core/question/application/QuestionService.java index 949d51a..90b7f42 100644 --- a/src/main/java/donggi/dev/kkeuroolryo/core/question/application/QuestionService.java +++ b/src/main/java/donggi/dev/kkeuroolryo/core/question/application/QuestionService.java @@ -129,7 +129,7 @@ public QuestionDto getQuestion(Long questionId) { @Override @Transactional(readOnly = true) - public QuestionPaginationDto findAllBy(NoOffsetPageCommand pageCommand) { + public QuestionPaginationDto findAllIdsByCategory(NoOffsetPageCommand pageCommand) { checkNoOffsetPageSize(pageCommand.getSize()); Long searchAfterId = pageCommand.getSearchAfterId() == 0 @@ -157,6 +157,21 @@ public QuestionPaginationDto search(String keyword, NoOffsetPageCommand pageComm return QuestionPaginationDto.ofEntity(sliceQuestions); } + @Override + @Transactional(readOnly = true) + public QuestionPaginationDto findAllByCategory(Category category, NoOffsetPageCommand pageCommand) { + checkNoOffsetPageSize(pageCommand.getSize()); + + Long searchAfterId = pageCommand.getSearchAfterId() == 0 + ? questionRepository.getMaxId() + : pageCommand.getSearchAfterId(); + + Slice sliceQuestions = questionRepository.findAllByCategoryAndSearchAfterIdAndPageable(category, searchAfterId, + Pageable.ofSize(Math.toIntExact(pageCommand.getSize()))); + + return QuestionPaginationDto.ofEntity(sliceQuestions); + } + private void checkNoOffsetPageSize(Long size) { if (size > QUESTION_PAGE_LIMIT_SIZE) { throw new NoOffsetPageInvalidException(); diff --git a/src/main/java/donggi/dev/kkeuroolryo/core/question/domain/QuestionRepository.java b/src/main/java/donggi/dev/kkeuroolryo/core/question/domain/QuestionRepository.java index 77eb8b8..5a1ac72 100644 --- a/src/main/java/donggi/dev/kkeuroolryo/core/question/domain/QuestionRepository.java +++ b/src/main/java/donggi/dev/kkeuroolryo/core/question/domain/QuestionRepository.java @@ -47,6 +47,15 @@ public interface QuestionRepository { */ Slice findAllBySearchAfterIdAndPageable(Long searchAfterId, Pageable ofSize); + /** + * 카테고리로 저장소에서 질문 리스트를 검색 id 기준 이후의 페이지만큼 조회합니다. + * @param category 조회할 카테고리 + * @param searchAfterId 검색 기준 대상 + * @param ofSize 페이지 크기 + * @return 페이징 된 질문 객체 + */ + Slice findAllByCategoryAndSearchAfterIdAndPageable(Category category, Long searchAfterId, Pageable ofSize); + /** * 저장소에서 질문을 키워드로 검색하고 페이지만큼 조회합니다. * @param keyword 검색할 키워드 diff --git a/src/main/java/donggi/dev/kkeuroolryo/core/question/infrastructure/QuestionJpaRepository.java b/src/main/java/donggi/dev/kkeuroolryo/core/question/infrastructure/QuestionJpaRepository.java index 8d91a0c..f33ce03 100644 --- a/src/main/java/donggi/dev/kkeuroolryo/core/question/infrastructure/QuestionJpaRepository.java +++ b/src/main/java/donggi/dev/kkeuroolryo/core/question/infrastructure/QuestionJpaRepository.java @@ -26,6 +26,9 @@ public interface QuestionJpaRepository extends QuestionRepository, JpaRepository @Query(value = "select q from Question q where q.content.content like %:keyword% and q.id <= :searchAfterId order by q.id desc") Slice findAllByContentContainingAndSearchAfterIdAndPageable(@Param("keyword") String keyword, @Param("searchAfterId") Long searchAfterId, Pageable ofSize); + @Query(value = "select q from Question q where q.category = :category and q.id <= :searchAfterId order by q.id desc") + Slice findAllByCategoryAndSearchAfterIdAndPageable(@Param("category") Category category, @Param("searchAfterId") Long searchAfterId, Pageable ofSize); + @Override default Question getById(Long questionId) { return findById(questionId).orElseThrow(QuestionNotFoundException::new); diff --git a/src/main/java/donggi/dev/kkeuroolryo/web/question/QuestionRestController.java b/src/main/java/donggi/dev/kkeuroolryo/web/question/QuestionRestController.java index 20c423c..c5d5a38 100644 --- a/src/main/java/donggi/dev/kkeuroolryo/web/question/QuestionRestController.java +++ b/src/main/java/donggi/dev/kkeuroolryo/web/question/QuestionRestController.java @@ -49,15 +49,28 @@ public ApiResponse register(@RequestBody QuestionResultCommand resultComma } /** - * 카테고리 이름으로 해당 카테고리의 질문을 조회합니다. + * 카테고리 이름으로 해당 카테고리의 질문 id를 조회합니다. * 질문은 랜덤한 순서로 조회합니다. */ @GetMapping("/category/{category}") - public ApiResponse getQuestionsByCategory(@PathVariable("category") Category category) { + public ApiResponse getQuestionIdsByCategory(@PathVariable("category") Category category) { RandomQuestionsDto randomQuestionsDto = questionFinder.getRandomQuestionsByCategory(category); return ApiResponse.success(randomQuestionsDto); } + /** + * 어드민에서 카테고리로 질문 리스트를 조회합니다. + */ + @GetMapping("/category/{category}/question") + public ApiResponse getQuestionsByCategory( + @PathVariable("category") Category category, + @RequestParam(required = false, defaultValue = "0") String searchAfterId, + @RequestParam(required = false, defaultValue = "20") String size + ) { + QuestionPaginationDto questionPaginationDto = questionFinder.findAllByCategory(category, new NoOffsetPageCommand(searchAfterId, size)); + return ApiResponse.success(questionPaginationDto); + } + @GetMapping("/question/{questionId}") public ApiResponse getQuestion(@PathVariable("questionId") Long questionId) { QuestionDto questionDto = questionFinder.getQuestion(questionId); @@ -69,7 +82,7 @@ public ApiResponse getAll( @RequestParam(required = false, defaultValue = "0") String searchAfterId, @RequestParam(required = false, defaultValue = "20") String size ) { - QuestionPaginationDto questionPaginationDto = questionFinder.findAllBy(new NoOffsetPageCommand(searchAfterId, size)); + QuestionPaginationDto questionPaginationDto = questionFinder.findAllIdsByCategory(new NoOffsetPageCommand(searchAfterId, size)); return ApiResponse.success(questionPaginationDto); } diff --git a/src/main/resources/static/docs/index.html b/src/main/resources/static/docs/index.html index 0989b7c..af1fb5f 100644 --- a/src/main/resources/static/docs/index.html +++ b/src/main/resources/static/docs/index.html @@ -457,10 +457,11 @@

골라바(Golraba) 애플리케이션

  • 1.2. 질문 수정
  • 1.3. 질문 상태 변경
  • 1.4. 질문 선택 결과 반영
  • -
  • 1.5. 카테고리 질문 조회
  • -
  • 1.6. 특정 질문 조회
  • -
  • 1.7. 질문 리스트 조회
  • -
  • 1.8. 질문 키워드 검색
  • +
  • 1.5. 카테고리로 질문 id 리스트 조회
  • +
  • 1.6. 카테고리로 질문 리스트 조회
  • +
  • 1.7. 특정 질문 조회
  • +
  • 1.8. 질문 리스트 조회
  • +
  • 1.9. 질문 키워드 검색
  • 2. 댓글 API @@ -537,7 +538,7 @@
    HTTP RequestPOST /api/golrabas/question HTTP/1.1 Accept: application/json Content-Type: application/json -Host: localhost:60147 +Host: localhost:57510 Content-Length: 118 { @@ -624,7 +625,7 @@
    Response Body "code" : "G001", "message" : "요청이 정상적으로 처리되었습니다.", "data" : { - "id" : 135, + "id" : 151, "content" : "요청한 질문 본문", "active" : true, "choiceA" : "선택 A", @@ -646,7 +647,7 @@
    HTTP Response Vary: Access-Control-Request-Headers Content-Type: application/json Transfer-Encoding: chunked -Date: Sat, 07 Oct 2023 10:01:07 GMT +Date: Sun, 08 Oct 2023 15:18:50 GMT Keep-Alive: timeout=60 Connection: keep-alive Content-Length: 290 @@ -655,7 +656,7 @@
    HTTP Response "code" : "G001", "message" : "요청이 정상적으로 처리되었습니다.", "data" : { - "id" : 135, + "id" : 151, "content" : "요청한 질문 본문", "active" : true, "choiceA" : "선택 A", @@ -741,10 +742,10 @@
    Path Paramete
    HTTP Request
    -
    PUT /api/golrabas/question/137 HTTP/1.1
    +
    PUT /api/golrabas/question/153 HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
     Content-Length: 118
     
     {
    @@ -781,7 +782,7 @@ 
    HTTP Response Vary: Access-Control-Request-Headers Content-Type: application/json Transfer-Encoding: chunked -Date: Sat, 07 Oct 2023 10:01:07 GMT +Date: Sun, 08 Oct 2023 15:18:50 GMT Keep-Alive: timeout=60 Connection: keep-alive Content-Length: 104 @@ -833,10 +834,10 @@
    Path Para
    HTTP Request
    -
    PATCH /api/golrabas/question/136/active/false HTTP/1.1
    +
    PATCH /api/golrabas/question/152/active/false HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
    @@ -865,7 +866,7 @@
    HTTP Response Vary: Access-Control-Request-Headers Content-Type: application/json Transfer-Encoding: chunked -Date: Sat, 07 Oct 2023 10:01:07 GMT +Date: Sun, 08 Oct 2023 15:18:50 GMT Keep-Alive: timeout=60 Connection: keep-alive Content-Length: 104 @@ -893,22 +894,22 @@
    Request Body
    {
       "results" : [ {
    -    "questionId" : 138,
    +    "questionId" : 154,
         "choice" : "a"
       }, {
    -    "questionId" : 138,
    +    "questionId" : 154,
         "choice" : "a"
       }, {
    -    "questionId" : 138,
    +    "questionId" : 154,
         "choice" : "a"
       }, {
    -    "questionId" : 138,
    +    "questionId" : 154,
         "choice" : "a"
       }, {
    -    "questionId" : 138,
    +    "questionId" : 154,
         "choice" : "b"
       }, {
    -    "questionId" : 138,
    +    "questionId" : 154,
         "choice" : "b"
       } ]
     }
    @@ -922,27 +923,27 @@
    HTTP RequestPOST /api/golrabas/result HTTP/1.1 Accept: application/json Content-Type: application/json -Host: localhost:60147 +Host: localhost:57510 Content-Length: 320 { "results" : [ { - "questionId" : 138, + "questionId" : 154, "choice" : "a" }, { - "questionId" : 138, + "questionId" : 154, "choice" : "a" }, { - "questionId" : 138, + "questionId" : 154, "choice" : "a" }, { - "questionId" : 138, + "questionId" : 154, "choice" : "a" }, { - "questionId" : 138, + "questionId" : 154, "choice" : "b" }, { - "questionId" : 138, + "questionId" : 154, "choice" : "b" } ] } @@ -962,7 +963,7 @@
    HTTP Response Vary: Access-Control-Request-Headers Content-Type: application/json Transfer-Encoding: chunked -Date: Sat, 07 Oct 2023 10:01:07 GMT +Date: Sun, 08 Oct 2023 15:18:50 GMT Keep-Alive: timeout=60 Connection: keep-alive Content-Length: 104 @@ -978,7 +979,7 @@
    HTTP Response
    -

    1.5. 카테고리 질문 조회

    +

    1.5. 카테고리로 질문 id 리스트 조회

    API : GET /api/golrabas/category/{category}

    @@ -1013,7 +1014,7 @@
    HTTP RequestGET /api/golrabas/category/SELF HTTP/1.1 Accept: application/json Content-Type: application/json -Host: localhost:60147 +Host: localhost:57510
    @@ -1068,7 +1069,7 @@
    Response Body "message" : "요청이 정상적으로 처리되었습니다.", "data" : { "category" : "SELF", - "questionIds" : [ 56, 57, 55, 59, 60, 63, 58, 62, 68, 64, 54, 61, 67, 69, 65 ] + "questionIds" : [ 63, 64, 65, 56, 58, 54, 66, 67, 69, 55, 61, 59, 62, 60, 57 ] } } @@ -1084,7 +1085,7 @@
    HTTP Response Vary: Access-Control-Request-Headers Content-Type: application/json Transfer-Encoding: chunked -Date: Sat, 07 Oct 2023 10:01:05 GMT +Date: Sun, 08 Oct 2023 15:18:49 GMT Keep-Alive: timeout=60 Connection: keep-alive Content-Length: 213 @@ -1094,7 +1095,7 @@
    HTTP Response "message" : "요청이 정상적으로 처리되었습니다.", "data" : { "category" : "SELF", - "questionIds" : [ 56, 57, 55, 59, 60, 63, 58, 62, 68, 64, 54, 61, 67, 69, 65 ] + "questionIds" : [ 63, 64, 65, 56, 58, 54, 66, 67, 69, 55, 61, 59, 62, 60, 57 ] } } @@ -1132,7 +1133,7 @@
    HTTP RequestGET /api/golrabas/category/haha HTTP/1.1 Accept: application/json Content-Type: application/json -Host: localhost:60147 +Host: localhost:57510 @@ -1161,7 +1162,7 @@
    HTTP Response Vary: Access-Control-Request-Headers Content-Type: application/json Transfer-Encoding: chunked -Date: Sat, 07 Oct 2023 10:01:05 GMT +Date: Sun, 08 Oct 2023 15:18:49 GMT Connection: close Content-Length: 400 @@ -1176,16 +1177,16 @@
    HTTP Response
    -

    1.6. 특정 질문 조회

    +

    1.6. 카테고리로 질문 리스트 조회

    -

    API : GET /api/golrabas/{questionId}

    +

    API : GET /api/golrabas/category/{category}/question

    +
    +
    Response Body
    +
    +
    +
    {
    +  "code" : "G001",
    +  "message" : "요청이 정상적으로 처리되었습니다.",
    +  "data" : {
    +    "questions" : [ {
    +      "id" : 101,
    +      "content" : "질문 본문16",
    +      "active" : true,
    +      "choiceA" : "선택A 16",
    +      "choiceB" : "선택B 16",
    +      "choiceAResult" : 0,
    +      "choiceBResult" : 0
    +    }, {
    +      "id" : 100,
    +      "content" : "질문 본문15",
    +      "active" : true,
    +      "choiceA" : "선택A 15",
    +      "choiceB" : "선택B 15",
    +      "choiceAResult" : 0,
    +      "choiceBResult" : 0
    +    }, {
    +      "id" : 99,
    +      "content" : "질문 본문14",
    +      "active" : true,
    +      "choiceA" : "선택A 14",
    +      "choiceB" : "선택B 14",
    +      "choiceAResult" : 0,
    +      "choiceBResult" : 0
    +    }, {
    +      "id" : 98,
    +      "content" : "질문 본문13",
    +      "active" : true,
    +      "choiceA" : "선택A 13",
    +      "choiceB" : "선택B 13",
    +      "choiceAResult" : 0,
    +      "choiceBResult" : 0
    +    }, {
    +      "id" : 97,
    +      "content" : "질문 본문12",
    +      "active" : true,
    +      "choiceA" : "선택A 12",
    +      "choiceB" : "선택B 12",
    +      "choiceAResult" : 0,
    +      "choiceBResult" : 0
    +    } ],
    +    "page" : {
    +      "size" : 5,
    +      "nextId" : 97,
    +      "last" : false
    +    }
    +  }
    +}
    +
    +
    +
    +
    +
    HTTP Response
    +
    +
    +
    HTTP/1.1 200 OK
    +Vary: Origin
    +Vary: Access-Control-Request-Method
    +Vary: Access-Control-Request-Headers
    +Content-Type: application/json
    +Transfer-Encoding: chunked
    +Date: Sun, 08 Oct 2023 15:18:49 GMT
    +Keep-Alive: timeout=60
    +Connection: keep-alive
    +Content-Length: 1225
    +
    +{
    +  "code" : "G001",
    +  "message" : "요청이 정상적으로 처리되었습니다.",
    +  "data" : {
    +    "questions" : [ {
    +      "id" : 101,
    +      "content" : "질문 본문16",
    +      "active" : true,
    +      "choiceA" : "선택A 16",
    +      "choiceB" : "선택B 16",
    +      "choiceAResult" : 0,
    +      "choiceBResult" : 0
    +    }, {
    +      "id" : 100,
    +      "content" : "질문 본문15",
    +      "active" : true,
    +      "choiceA" : "선택A 15",
    +      "choiceB" : "선택B 15",
    +      "choiceAResult" : 0,
    +      "choiceBResult" : 0
    +    }, {
    +      "id" : 99,
    +      "content" : "질문 본문14",
    +      "active" : true,
    +      "choiceA" : "선택A 14",
    +      "choiceB" : "선택B 14",
    +      "choiceAResult" : 0,
    +      "choiceBResult" : 0
    +    }, {
    +      "id" : 98,
    +      "content" : "질문 본문13",
    +      "active" : true,
    +      "choiceA" : "선택A 13",
    +      "choiceB" : "선택B 13",
    +      "choiceAResult" : 0,
    +      "choiceBResult" : 0
    +    }, {
    +      "id" : 97,
    +      "content" : "질문 본문12",
    +      "active" : true,
    +      "choiceA" : "선택A 12",
    +      "choiceB" : "선택B 12",
    +      "choiceAResult" : 0,
    +      "choiceBResult" : 0
    +    } ],
    +    "page" : {
    +      "size" : 5,
    +      "nextId" : 97,
    +      "last" : false
    +    }
    +  }
    +}
    +
    +
    +
    +
    + +
    +

    1.7. 특정 질문 조회

    +
    +

    API : GET /api/golrabas/{questionId}

    +
    +
    +

    1.7.1. 성공

    +
    +
    Path Parameters
    + + ++++ + + + + + + + + + + + + +
    Table 6. /api/golrabas/question/{questionId}
    ParameterDescription

    questionId

    질문 id

    +
    +
    +
    HTTP Request
    +
    +
    +
    GET /api/golrabas/question/85 HTTP/1.1
    +Accept: application/json
    +Content-Type: application/json
    +Host: localhost:57510
    +
    +
    +
    +
    +
    +

    1.7.2. Response

    +
    +
    Response Fields
    + +++++ + + + + + + + + + + + + + + + + + + + @@ -1283,7 +1537,7 @@
    Response
    PathTypeDescription

    code

    String

    응답 코드

    message

    String

    응답 메세지

    data.id

    Number

    질문 id

    -
    Response Body
    +
    Response Body
    {
    @@ -1303,7 +1557,7 @@ 
    Response Body
    -
    HTTP Response
    +
    HTTP Response
    -

    1.6.3. 실패

    +

    1.7.3. 실패

    -
    Path Parameters
    +
    Path Parameters
    - +@@ -1359,21 +1613,21 @@
    Path Para
    Table 6. /api/golrabas/question/{questionId}Table 7. /api/golrabas/question/{questionId}
    -
    HTTP Request
    +
    HTTP Request
    GET /api/golrabas/question/-1 HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
    -

    1.6.4. Response

    +

    1.7.4. Response

    -
    Response Body
    +
    Response Body
    {
    @@ -1385,7 +1639,7 @@ 
    Response Body
    -
    HTTP Response
    +
    HTTP Response
    -

    1.7. 질문 리스트 조회

    +

    1.8. 질문 리스트 조회

    API : GET /api/golrabas/question

    -

    1.7.1. 성공

    +

    1.8.1. 성공

    -
    HTTP Request
    +
    HTTP Request
    -
    GET /api/golrabas/question?searchAfterId=101&size=5 HTTP/1.1
    +
    GET /api/golrabas/question?searchAfterId=117&size=5 HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
    @@ -1453,9 +1707,9 @@
    Query Param
    -

    1.7.2. Response

    +

    1.8.2. Response

    -
    Response Body
    +
    Response Body
    -
    HTTP Response
    +
    HTTP Response
    -

    1.8. 질문 키워드 검색

    +

    1.9. 질문 키워드 검색

    API : GET /api/golrabas/question/search

    -

    1.8.1. 성공

    +

    1.9.1. 성공

    -
    HTTP Request
    +
    HTTP Request
    -
    GET /api/golrabas/question/search?keyword=%EC%A7%88%EB%AC%B8&searchAfterId=133&size=5 HTTP/1.1
    +
    GET /api/golrabas/question/search?keyword=%EC%A7%88%EB%AC%B8&searchAfterId=149&size=5 HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
    @@ -1713,9 +1967,9 @@
    Query P
    -

    1.8.2. Response

    +

    1.9.2. Response

    -
    Response Body
    +
    Response Body
    -
    HTTP Response
    +
    HTTP Response
    -

    2.1.1. 성공

    +

    2.1.1. 성공

    Path Parameter
    - +@@ -1993,13 +2247,13 @@
    Request Fie
    Table 7. /api/golrabas/{questionId}/commentsTable 8. /api/golrabas/{questionId}/comments
    -
    HTTP Request
    +
    HTTP Request
    POST /api/golrabas/37/comments HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
     Content-Length: 98
     
     {
    @@ -2011,7 +2265,7 @@ 
    HTTP Request<
    -
    Response Body
    +
    Response Body
    {
    @@ -2071,7 +2325,7 @@ 
    Response Bo
    -
    HTTP Response
    +
    HTTP Response
    HTTP/1.1 200 OK
    @@ -2080,7 +2334,7 @@ 
    HTTP Respon Vary: Access-Control-Request-Headers Content-Type: application/json Transfer-Encoding: chunked -Date: Sat, 07 Oct 2023 10:01:05 GMT +Date: Sun, 08 Oct 2023 15:18:49 GMT Keep-Alive: timeout=60 Connection: keep-alive Content-Length: 185 @@ -2103,7 +2357,7 @@

    2.1.2. 실패

    Path Parameter
    - +@@ -2157,13 +2411,13 @@
    Request Fie
    Table 8. /api/golrabas/{questionId}/commentsTable 9. /api/golrabas/{questionId}/comments
    -
    HTTP Request
    +
    HTTP Request
    POST /api/golrabas/33/comments HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
     Content-Length: 86
     
     {
    @@ -2175,7 +2429,7 @@ 
    HTTP Request<
    -
    Response Body
    +
    Response Body
    {
    @@ -2187,7 +2441,7 @@ 
    Response Bo
    -
    HTTP Response
    +
    HTTP Response
    -

    2.2.1. 성공

    +

    2.2.1. 성공

    Path Parameter
    - +@@ -2278,13 +2532,13 @@
    Request Fie
    Table 9. /api/golrabas/{questionId}/comments/{commentId}Table 10. /api/golrabas/{questionId}/comments/{commentId}
    -
    HTTP Request
    +
    HTTP Request
    PUT /api/golrabas/36/comments/21 HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
     Content-Length: 81
     
     {
    @@ -2296,7 +2550,7 @@ 
    HTTP Request<
    -
    Response Body
    +
    Response Body
    {
    @@ -2308,7 +2562,7 @@ 
    Response Bo
    -
    HTTP Response
    +
    HTTP Response
    -

    2.3.1. 성공

    +

    2.3.1. 성공

    Path Parameter
    - +@@ -2390,13 +2644,13 @@
    Request Fie
    Table 10. /api/golrabas/{questionId}/comments/{commentId}Table 11. /api/golrabas/{questionId}/comments/{commentId}
    -
    HTTP Request
    +
    HTTP Request
    DELETE /api/golrabas/34/comments/19 HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
     Content-Length: 36
     
     {
    @@ -2407,9 +2661,9 @@ 
    HTTP Request<
    -

    2.3.2. Response

    +

    2.3.2. Response

    -
    HTTP Response
    +
    HTTP Response
    -
    HTTP Request
    +
    HTTP Request
    DELETE /api/golrabas/31/comments/-1 HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
     Content-Length: 36
     
     {
    @@ -2502,9 +2756,9 @@ 
    HTTP Request<
    -

    2.3.4. Response

    +

    2.3.4. Response

    -
    HTTP Response
    +
    HTTP Response
    HTTP/1.1 400 Bad Request
    @@ -2513,7 +2767,7 @@ 
    HTTP Respon Vary: Access-Control-Request-Headers Content-Type: application/json Transfer-Encoding: chunked -Date: Sat, 07 Oct 2023 10:01:05 GMT +Date: Sun, 08 Oct 2023 15:18:49 GMT Connection: close Content-Length: 92 @@ -2531,7 +2785,7 @@

    Path Parameter
    - +@@ -2579,13 +2833,13 @@
    Request Fie
    Table 12. /api/golrabas/{questionId}/comments/{commentId}Table 13. /api/golrabas/{questionId}/comments/{commentId}

    -
    HTTP Request
    +
    HTTP Request
    DELETE /api/golrabas/-1/comments/17 HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
     Content-Length: 36
     
     {
    @@ -2596,9 +2850,9 @@ 
    HTTP Request<
    -

    2.3.6. Response

    +

    2.3.6. Response

    -
    HTTP Response
    +
    HTTP Response
    HTTP/1.1 400 Bad Request
    @@ -2607,7 +2861,7 @@ 
    HTTP Respon Vary: Access-Control-Request-Headers Content-Type: application/json Transfer-Encoding: chunked -Date: Sat, 07 Oct 2023 10:01:05 GMT +Date: Sun, 08 Oct 2023 15:18:49 GMT Connection: close Content-Length: 92 @@ -2625,7 +2879,7 @@

    Path Parameter
    - +@@ -2673,13 +2927,13 @@
    Request Fie
    Table 13. /api/golrabas/{questionId}/comments/{commentId}Table 14. /api/golrabas/{questionId}/comments/{commentId}

    -
    HTTP Request
    +
    HTTP Request
    DELETE /api/golrabas/35/comments/20 HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
     Content-Length: 35
     
     {
    @@ -2690,9 +2944,9 @@ 
    HTTP Request<
    -

    2.3.8. Response

    +

    2.3.8. Response

    -
    HTTP Response
    +
    HTTP Response
    -

    2.4.1. 성공

    +

    2.4.1. 성공

    Path Parameter
    - +@@ -2745,21 +2999,21 @@
    Path Parame
    Table 14. /api/golrabas/{questionId}/commentsTable 15. /api/golrabas/{questionId}/comments
    -
    HTTP Request
    +
    HTTP Request
    GET /api/golrabas/30/comments?searchAfterId=15&size=5 HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
    -

    2.4.2. Response

    +

    2.4.2. Response

    -
    HTTP Response
    +
    HTTP Response
    -
    HTTP Request
    +
    HTTP Request
    POST /api/golrabas/shortUrl HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510
     Content-Length: 35
     
     {
    @@ -2865,9 +3119,9 @@ 
    HTTP Request<
    -

    3.1.2. Response

    +

    3.1.2. Response

    -
    Response Body
    +
    Response Body
    {
    @@ -2915,7 +3169,7 @@ 
    Response Bo
    -
    HTTP Response
    +
    HTTP Response
    HTTP/1.1 200 OK
    @@ -2924,7 +3178,7 @@ 
    HTTP Respon Vary: Access-Control-Request-Headers Content-Type: application/json Transfer-Encoding: chunked -Date: Sat, 07 Oct 2023 10:01:07 GMT +Date: Sun, 08 Oct 2023 15:18:50 GMT Keep-Alive: timeout=60 Connection: keep-alive Content-Length: 131 @@ -2949,9 +3203,9 @@

    3.2. 원

    3.2.1. Request

    -
    Path Parameters
    +
    Path Parameters
    - +@@ -2971,21 +3225,21 @@
    Path Para
    Table 15. /api/golrabas/shortUrl/{shortUrl}Table 16. /api/golrabas/shortUrl/{shortUrl}
    -
    HTTP Request
    +
    HTTP Request
    GET /api/golrabas/shortUrl/Sq3pFB HTTP/1.1
     Accept: application/json
     Content-Type: application/json
    -Host: localhost:60147
    +Host: localhost:57510

    -

    3.2.2. Response

    +

    3.2.2. Response

    -
    Response Body
    +
    Response Body
    {
    @@ -3033,7 +3287,7 @@ 
    Response Bo
    -
    HTTP Response
    +
    HTTP Response
    HTTP/1.1 200 OK
    @@ -3042,7 +3296,7 @@ 
    HTTP Respon Vary: Access-Control-Request-Headers Content-Type: application/json Transfer-Encoding: chunked -Date: Sat, 07 Oct 2023 10:01:07 GMT +Date: Sun, 08 Oct 2023 15:18:50 GMT Keep-Alive: timeout=60 Connection: keep-alive Content-Length: 139 diff --git a/src/test/java/donggi/dev/kkeuroolryo/web/question/QuestionReadRestControllerRestDocsTest.java b/src/test/java/donggi/dev/kkeuroolryo/web/question/QuestionReadRestControllerRestDocsTest.java index 9a50ecf..09d77db 100644 --- a/src/test/java/donggi/dev/kkeuroolryo/web/question/QuestionReadRestControllerRestDocsTest.java +++ b/src/test/java/donggi/dev/kkeuroolryo/web/question/QuestionReadRestControllerRestDocsTest.java @@ -206,6 +206,48 @@ void question_list_read() { .statusCode(HttpStatus.OK.value()); } + @Test + @DisplayName("카테고리로 질문 리스트 조회 요청이 정상적이면 질문 리스트를 반환하고 정상 상태코드를 반환한다.") + void question_list_read_by_category() { + given(this.spec) + .filter( + document("question-list-read-by-category", + pathParameters(parameterWithName("category").description("조회할 카테고리")), + queryParameters( + parameterWithName("searchAfterId").description("검색 시작할 댓글 id"), + parameterWithName("size").description("조회할 데이터 개수") + ), + responseFields( + fieldWithPath("code").description("응답 코드").type(JsonFieldType.STRING), + fieldWithPath("message").description("응답 메세지").type(JsonFieldType.STRING), + fieldWithPath("data.questions[].id").description("질문 id").type(JsonFieldType.NUMBER), + fieldWithPath("data.questions[].content").description("질문 본문").type(JsonFieldType.STRING), + fieldWithPath("data.questions[].choiceA").description("선택지 A").type(JsonFieldType.STRING), + fieldWithPath("data.questions[].choiceB").description("선택지 B").type(JsonFieldType.STRING), + fieldWithPath("data.questions[].active").description("활성화 상태").type(JsonFieldType.BOOLEAN), + fieldWithPath("data.questions[].choiceAResult").description("선택지 A의 득표율").type(JsonFieldType.NUMBER), + fieldWithPath("data.questions[].choiceBResult").description("선택지 B의 득표율").type(JsonFieldType.NUMBER), + + fieldWithPath("data.page.size").description("조회된 데이터 개수").type(JsonFieldType.NUMBER), + fieldWithPath("data.page.nextId").description("다음 데이터 id").type(JsonFieldType.NUMBER), + fieldWithPath("data.page.last").description("마지막 여부").type(JsonFieldType.BOOLEAN) + ) + ) + ) + .log().all() + .accept(MediaType.APPLICATION_JSON_VALUE) + .header("Content-type", MediaType.APPLICATION_JSON_VALUE) + .queryParam("searchAfterId", question.getId()) + .queryParam("size", 5) + + .when() + .get("/api/golrabas/category/{category}/question", question.getCategory()) + + .then() + .log().all() + .statusCode(HttpStatus.OK.value()); + } + @Test @DisplayName("질문 키워드 검색 요청이 정상적이면 키워드로 검색한 질문 리스트를 반환하고 정상 상태코드를 반환한다.") void question_search() {