From 02557d1c9ebae91aef01745dcb3abab15eac4f23 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Wed, 24 May 2023 20:28:53 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EA=B7=B8=EB=A6=AC=EB=93=9C=20API=20?= =?UTF-8?q?=EB=AC=B8=EC=84=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/Grid-API.adoc | 14 + src/docs/asciidoc/index.adoc | 4 +- src/main/resources/static/docs/Album-API.html | 2 +- .../resources/static/docs/Comment-API.html | 2 +- .../resources/static/docs/Empathy-API.html | 2 +- src/main/resources/static/docs/Enum.html | 2 +- .../static/docs/FuneralShop-API.html | 2 +- src/main/resources/static/docs/Grid-API.html | 635 ++++++++++++++++++ src/main/resources/static/docs/Overview.html | 2 +- .../resources/static/docs/Question-API.html | 2 +- src/main/resources/static/docs/User-API.html | 2 +- src/main/resources/static/docs/index.html | 192 +++++- .../samsion/common/consts/TestConst.java | 4 + .../grid/presentation/GridControllerTest.java | 98 +++ 14 files changed, 953 insertions(+), 10 deletions(-) create mode 100644 src/docs/asciidoc/Grid-API.adoc create mode 100644 src/main/resources/static/docs/Grid-API.html create mode 100644 src/test/java/com/kusitms/samsion/domain/grid/presentation/GridControllerTest.java diff --git a/src/docs/asciidoc/Grid-API.adoc b/src/docs/asciidoc/Grid-API.adoc new file mode 100644 index 0000000..67930f2 --- /dev/null +++ b/src/docs/asciidoc/Grid-API.adoc @@ -0,0 +1,14 @@ +[[Grid-API]] +== Grid-API + +[[Grid-정보-조회]] +=== Grid 정보 조회 +operation::grid-controller-test/그리드_조회[snippets='http-request,request-headers,http-response,response-fields'] + +--- + +[[Stamp-정보-조회]] +=== Stamp 정보 조회 +operation::grid-controller-test/스탬프_조회[snippets='http-request,request-headers,http-response,response-fields'] + +--- diff --git a/src/docs/asciidoc/index.adoc b/src/docs/asciidoc/index.adoc index baf25e6..e1f851d 100644 --- a/src/docs/asciidoc/index.adoc +++ b/src/docs/asciidoc/index.adoc @@ -20,4 +20,6 @@ include::Comment-API.adoc[] include::Album-API.adoc[] -include::FuneralShop-API.adoc[] \ No newline at end of file +include::FuneralShop-API.adoc[] + +include::Grid-API.adoc[] \ No newline at end of file diff --git a/src/main/resources/static/docs/Album-API.html b/src/main/resources/static/docs/Album-API.html index de27699..c2511ae 100644 --- a/src/main/resources/static/docs/Album-API.html +++ b/src/main/resources/static/docs/Album-API.html @@ -1540,7 +1540,7 @@

Response fields

diff --git a/src/main/resources/static/docs/Comment-API.html b/src/main/resources/static/docs/Comment-API.html index c3833cf..a155a9d 100644 --- a/src/main/resources/static/docs/Comment-API.html +++ b/src/main/resources/static/docs/Comment-API.html @@ -1292,7 +1292,7 @@

Response fields

diff --git a/src/main/resources/static/docs/Empathy-API.html b/src/main/resources/static/docs/Empathy-API.html index d565246..68f0616 100644 --- a/src/main/resources/static/docs/Empathy-API.html +++ b/src/main/resources/static/docs/Empathy-API.html @@ -605,7 +605,7 @@

Response fields

diff --git a/src/main/resources/static/docs/Enum.html b/src/main/resources/static/docs/Enum.html index 6f090db..08c410c 100644 --- a/src/main/resources/static/docs/Enum.html +++ b/src/main/resources/static/docs/Enum.html @@ -579,7 +579,7 @@

공개여부

diff --git a/src/main/resources/static/docs/FuneralShop-API.html b/src/main/resources/static/docs/FuneralShop-API.html index 8a98819..36a2928 100644 --- a/src/main/resources/static/docs/FuneralShop-API.html +++ b/src/main/resources/static/docs/FuneralShop-API.html @@ -620,7 +620,7 @@

Response fields

diff --git a/src/main/resources/static/docs/Grid-API.html b/src/main/resources/static/docs/Grid-API.html new file mode 100644 index 0000000..02d482f --- /dev/null +++ b/src/main/resources/static/docs/Grid-API.html @@ -0,0 +1,635 @@ + + + + + + + +Grid-API + + + + + +
+
+

Grid-API

+
+
+

Grid 정보 조회

+
+

HTTP request

+
+
+
GET /grid HTTP/1.1
+Content-Type: application/json;charset=UTF-8
+Authorization: access token
+Host: localhost:8080
+
+
+
+
+

Request headers

+ ++++ + + + + + + + + + + + + +
NameDescription

Authorization

access token

+
+
+

HTTP response

+
+
+
HTTP/1.1 200 OK
+Content-Type: application/json;charset=UTF-8
+Content-Length: 252
+
+{
+  "gridCheckList" : [ {
+    "gridNum" : 1,
+    "check" : true
+  }, {
+    "gridNum" : 2,
+    "check" : true
+  }, {
+    "gridNum" : 3,
+    "check" : true
+  }, {
+    "gridNum" : 4,
+    "check" : true
+  } ],
+  "gridImageUrl" : "imageurl"
+}
+
+
+
+
+

Response fields

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
PathTypeDescription

gridCheckList[].check

Boolean

그리드 체크 여부

gridCheckList[].gridNum

Number

그리드 번호

gridImageUrl

String

그리드 이미지 링크

+
+
+
+
+

Stamp 정보 조회

+
+

HTTP request

+
+
+
GET /grid/stamp HTTP/1.1
+Content-Type: application/json;charset=UTF-8
+Authorization: access token
+Host: localhost:8080
+
+
+
+
+

Request headers

+ ++++ + + + + + + + + + + + + +
NameDescription

Authorization

access token

+
+
+

HTTP response

+
+
+
HTTP/1.1 200 OK
+Content-Type: application/json;charset=UTF-8
+Content-Length: 79
+
+{
+  "content" : [ {
+    "stampId" : 1,
+    "imageUrl" : "imageurl"
+  } ]
+}
+
+
+
+
+

Response fields

+ +++++ + + + + + + + + + + + + + + + + + + + +
PathTypeDescription

content[].stampId

Number

스탬프 아이디

content[].imageUrl

String

스탬프 이미지 링크

+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/src/main/resources/static/docs/Overview.html b/src/main/resources/static/docs/Overview.html index e7f4447..a09eeae 100644 --- a/src/main/resources/static/docs/Overview.html +++ b/src/main/resources/static/docs/Overview.html @@ -667,7 +667,7 @@

Grid Status Codes

diff --git a/src/main/resources/static/docs/Question-API.html b/src/main/resources/static/docs/Question-API.html index ff252a6..7c752b5 100644 --- a/src/main/resources/static/docs/Question-API.html +++ b/src/main/resources/static/docs/Question-API.html @@ -768,7 +768,7 @@

HTTP response

diff --git a/src/main/resources/static/docs/User-API.html b/src/main/resources/static/docs/User-API.html index 703104f..9ff2756 100644 --- a/src/main/resources/static/docs/User-API.html +++ b/src/main/resources/static/docs/User-API.html @@ -724,7 +724,7 @@

Response fields

diff --git a/src/main/resources/static/docs/index.html b/src/main/resources/static/docs/index.html index 7937d41..1c510fc 100644 --- a/src/main/resources/static/docs/index.html +++ b/src/main/resources/static/docs/index.html @@ -504,6 +504,12 @@

Samsion API Doc

  • FuneralShop 가게 정보 조회
  • +
  • Grid-API + +
  • @@ -3751,11 +3757,195 @@

    +

    Grid-API

    +
    +
    +

    Grid 정보 조회

    +
    +

    HTTP request

    +
    +
    +
    GET /grid HTTP/1.1
    +Content-Type: application/json;charset=UTF-8
    +Authorization: access token
    +Host: localhost:8080
    +
    +
    +
    +
    +

    Request headers

    + ++++ + + + + + + + + + + + + +
    NameDescription

    Authorization

    access token

    +
    +
    +

    HTTP response

    +
    +
    +
    HTTP/1.1 200 OK
    +Content-Type: application/json;charset=UTF-8
    +Content-Length: 252
    +
    +{
    +  "gridCheckList" : [ {
    +    "gridNum" : 1,
    +    "check" : true
    +  }, {
    +    "gridNum" : 2,
    +    "check" : true
    +  }, {
    +    "gridNum" : 3,
    +    "check" : true
    +  }, {
    +    "gridNum" : 4,
    +    "check" : true
    +  } ],
    +  "gridImageUrl" : "imageurl"
    +}
    +
    +
    +
    +
    +

    Response fields

    + +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
    PathTypeDescription

    gridCheckList[].check

    Boolean

    그리드 체크 여부

    gridCheckList[].gridNum

    Number

    그리드 번호

    gridImageUrl

    String

    그리드 이미지 링크

    +
    +
    +
    +
    +

    Stamp 정보 조회

    +
    +

    HTTP request

    +
    +
    +
    GET /grid/stamp HTTP/1.1
    +Content-Type: application/json;charset=UTF-8
    +Authorization: access token
    +Host: localhost:8080
    +
    +
    +
    +
    +

    Request headers

    + ++++ + + + + + + + + + + + + +
    NameDescription

    Authorization

    access token

    +
    +
    +

    HTTP response

    +
    +
    +
    HTTP/1.1 200 OK
    +Content-Type: application/json;charset=UTF-8
    +Content-Length: 79
    +
    +{
    +  "content" : [ {
    +    "stampId" : 1,
    +    "imageUrl" : "imageurl"
    +  } ]
    +}
    +
    +
    +
    +
    +

    Response fields

    + +++++ + + + + + + + + + + + + + + + + + + + +
    PathTypeDescription

    content[].stampId

    Number

    스탬프 아이디

    content[].imageUrl

    String

    스탬프 이미지 링크

    +
    +
    +
    +
    + diff --git a/src/test/java/com/kusitms/samsion/common/consts/TestConst.java b/src/test/java/com/kusitms/samsion/common/consts/TestConst.java index fd2741f..13c53f6 100644 --- a/src/test/java/com/kusitms/samsion/common/consts/TestConst.java +++ b/src/test/java/com/kusitms/samsion/common/consts/TestConst.java @@ -98,4 +98,8 @@ public class TestConst { // 앨범 이미지 public static final Long TEST_ALBUM_IMAGE_ID = 1L; + + //그리드 + public static final Long TEST_GRID_ID = 1L; + public static final String TEST_GRID_IMG_URL = "imageurl"; } \ No newline at end of file diff --git a/src/test/java/com/kusitms/samsion/domain/grid/presentation/GridControllerTest.java b/src/test/java/com/kusitms/samsion/domain/grid/presentation/GridControllerTest.java new file mode 100644 index 0000000..9285358 --- /dev/null +++ b/src/test/java/com/kusitms/samsion/domain/grid/presentation/GridControllerTest.java @@ -0,0 +1,98 @@ +package com.kusitms.samsion.domain.grid.presentation; + +import com.kusitms.samsion.common.config.CommonRestDocs; +import com.kusitms.samsion.common.consts.ApplicationConst; +import com.kusitms.samsion.common.consts.TestConst; +import com.kusitms.samsion.common.slice.ListResponse; +import com.kusitms.samsion.domain.grid.application.dto.GridCheck; +import com.kusitms.samsion.domain.grid.application.dto.response.GridInfoResponse; +import com.kusitms.samsion.domain.grid.application.dto.response.StampResponse; +import com.kusitms.samsion.domain.grid.application.service.GridGetUseCase; +import com.kusitms.samsion.domain.grid.application.service.StampGetUseCase; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.mockito.BDDMockito.given; +import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; +import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(GridController.class) +@DisplayName("GridController 테스트") +public class GridControllerTest extends CommonRestDocs { + + @MockBean + GridGetUseCase gridGetUseCase; + + @MockBean + StampGetUseCase stampGetUseCase; + + @Test + void 그리드_조회() throws Exception { + List gridCheckList = new ArrayList<>(Arrays.asList(new GridCheck(true, 1), + new GridCheck(true, 2), new GridCheck(true, 3), new GridCheck(true, 4))); + GridInfoResponse gridInfoResponse = new GridInfoResponse(gridCheckList, TestConst.TEST_GRID_IMG_URL); + given(gridGetUseCase.getGrid()).willReturn(gridInfoResponse); + + //when + ResultActions result = mockMvc.perform( + get("/grid") + .header(ApplicationConst.ACCESS_TOKEN_HEADER, "access token") + .contentType(MediaType.APPLICATION_JSON) + ); + + //then + result.andExpect(status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("access token") + ), + responseFields( + fieldWithPath("gridCheckList[].check").description("그리드 체크 여부"), + fieldWithPath("gridCheckList[].gridNum").description("그리드 번호"), + fieldWithPath("gridImageUrl").description("그리드 이미지 링크") + ) + ) + ); + } + + @Test + void 스탬프_조회() throws Exception { + List stampResponseList = new ArrayList<>(Arrays.asList(new StampResponse(TestConst.TEST_GRID_ID, TestConst.TEST_GRID_IMG_URL))); + ListResponse stampResponseListResponse = ListResponse.of(stampResponseList); + given(stampGetUseCase.getStampList()).willReturn(stampResponseListResponse); + + //when + ResultActions result = mockMvc.perform( + get("/grid/stamp") + .header(ApplicationConst.ACCESS_TOKEN_HEADER, "access token") + .contentType(MediaType.APPLICATION_JSON) + ); + + //then + result.andExpect(status().isOk()) + .andDo( + restDocs.document( + requestHeaders( + headerWithName("Authorization").description("access token") + ), + responseFields( + fieldWithPath("content[].stampId").description("스탬프 아이디"), + fieldWithPath("content[].imageUrl").description("스탬프 이미지 링크") + ) + ) + ); + } +}