From 824dfc4669c0e9182477541f145718deda257681 Mon Sep 17 00:00:00 2001 From: Hyeonjun Park Date: Tue, 21 Nov 2023 21:32:50 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20image=20=EC=83=9D=EC=84=B1=20API?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qbox/qboxserver/domain/image/ImageCtrl.kt | 17 +++++++++ .../qboxserver/config/WebClientDocsTest.kt | 4 +- .../qboxserver/domain/image/ImageCtrlTest.kt | 38 +++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/site/qbox/qboxserver/domain/image/ImageCtrl.kt create mode 100644 src/test/kotlin/site/qbox/qboxserver/domain/image/ImageCtrlTest.kt diff --git a/src/main/kotlin/site/qbox/qboxserver/domain/image/ImageCtrl.kt b/src/main/kotlin/site/qbox/qboxserver/domain/image/ImageCtrl.kt new file mode 100644 index 0000000..ccf1697 --- /dev/null +++ b/src/main/kotlin/site/qbox/qboxserver/domain/image/ImageCtrl.kt @@ -0,0 +1,17 @@ +package site.qbox.qboxserver.domain.image + +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.* +import org.springframework.web.multipart.MultipartFile +import site.qbox.qboxserver.domain.image.dto.ImageRes + +@RestController +@RequestMapping("images") +class ImageCtrl( + private val imageSvc: ImageSvc, +) { + @PostMapping + @ResponseStatus(HttpStatus.CREATED) + fun save(@RequestPart file: MultipartFile): ImageRes = + imageSvc.save(file) +} \ No newline at end of file diff --git a/src/test/kotlin/site/qbox/qboxserver/config/WebClientDocsTest.kt b/src/test/kotlin/site/qbox/qboxserver/config/WebClientDocsTest.kt index 39ddd48..9cf7fec 100644 --- a/src/test/kotlin/site/qbox/qboxserver/config/WebClientDocsTest.kt +++ b/src/test/kotlin/site/qbox/qboxserver/config/WebClientDocsTest.kt @@ -63,10 +63,10 @@ abstract class WebClientDocsTest : DescribeSpec() { return mockMvc.perform(get(endpoint, *urlValue).params(params)) } - protected fun performFormData(method: HttpMethod, endpoint: String, filename: String): ResultActions { + protected fun performFormData(method: HttpMethod, endpoint: String, requestPartKey: String): ResultActions { return mockMvc.perform( multipart(method, endpoint) - .file(filename, ByteArray(0)) + .file(requestPartKey, ByteArray(0)) .with(csrf()) .contentType(MediaType.MULTIPART_FORM_DATA) .characterEncoding(StandardCharsets.UTF_8) diff --git a/src/test/kotlin/site/qbox/qboxserver/domain/image/ImageCtrlTest.kt b/src/test/kotlin/site/qbox/qboxserver/domain/image/ImageCtrlTest.kt new file mode 100644 index 0000000..e997cb8 --- /dev/null +++ b/src/test/kotlin/site/qbox/qboxserver/domain/image/ImageCtrlTest.kt @@ -0,0 +1,38 @@ +package site.qbox.qboxserver.domain.image + +import com.ninjasquad.springmockk.MockkBean +import io.kotest.core.annotation.DisplayName +import io.mockk.every +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest +import org.springframework.http.HttpMethod +import org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath +import org.springframework.restdocs.payload.PayloadDocumentation.responseFields +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status +import site.qbox.qboxserver.config.WebClientDocsTest +import site.qbox.qboxserver.domain.image.dto.ImageRes + +@WebMvcTest(ImageCtrl::class) +@DisplayName("ImageCtrl") +class ImageCtrlTest : WebClientDocsTest() { + @MockkBean + lateinit var imageSvc: ImageSvc + + init { + it("inage 저장을 수행한다") { + every { imageSvc.save(any()) } returns ImageRes("https://q-box.site/images/asdf-asdf-asdf-asdf.jpg") + + val action = performFormData(HttpMethod.POST, "/images", "file"); + + action.andExpect(status().isCreated) + + action.andDo( + print( + "save-image", + responseFields( + fieldWithPath("location").description("이미지 파일 경로") + ) + ) + ) + } + } +} From ee5d8995d728a77c3e94f39f7a4d693ba3f65184 Mon Sep 17 00:00:00 2001 From: Hyeonjun Park Date: Tue, 21 Nov 2023 21:43:12 +0900 Subject: [PATCH 2/2] =?UTF-8?q?docs=20:=20API=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20docs=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api-docs.adoc | 36 ++ src/main/resources/templates/api-docs.html | 491 ++++++++++++++++++--- 2 files changed, 457 insertions(+), 70 deletions(-) diff --git a/src/docs/asciidoc/api-docs.adoc b/src/docs/asciidoc/api-docs.adoc index 77c234d..ad11aec 100644 --- a/src/docs/asciidoc/api-docs.adoc +++ b/src/docs/asciidoc/api-docs.adoc @@ -21,6 +21,32 @@ include::{snippets}/create-answer/request-fields.adoc[] include::{snippets}/create-answer/http-response.adoc[] +== 답변 목록 조회 + +=== HTTP request + +include::{snippets}/find-all-answers/http-request.adoc[] +include::{snippets}/find-all-answers/query-parameters.adoc[] + +=== HTTP response + +include::{snippets}/find-all-answers/http-response.adoc[] +include::{snippets}/find-all-answers/response-fields.adoc[] + + += answer-comments +== 답변 댓글 생성 + +=== HTTP request + +include::{snippets}/create-answer-comment/http-request.adoc[] +include::{snippets}/create-answer-comment/request-fields.adoc[] + +=== HTTP response + +include::{snippets}/create-answer/http-response.adoc[] + + = departs == 학과 생성 @@ -63,6 +89,16 @@ include::{snippets}/authenticate-email/query-parameters.adoc[] === HTTP response include::{snippets}/authenticate-email/http-response.adoc[] += image +== image 생성 +=== HTTP request +include::{snippets}/save-image/http-request.adoc[] +include::{snippets}/save-image/request-fields.adoc[] + +=== HTTP response +include::{snippets}/save-image/http-response.adoc[] +include::{snippets}/save-image/response-fields.adoc[] + = lectures == 강의 생성 diff --git a/src/main/resources/templates/api-docs.html b/src/main/resources/templates/api-docs.html index 0de60ad..1ae9e2d 100644 --- a/src/main/resources/templates/api-docs.html +++ b/src/main/resources/templates/api-docs.html @@ -561,17 +561,17 @@

Q BOX

  • HTTP response
  • - - -
  • departs - +
  • +
  • answer-comments +