🎨
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
package me.jiniworld.demohx.application.notice.port.input
|
package me.jiniworld.demohx.application.notice.port.input
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import me.jiniworld.demohx.application.notice.domain.NoticeDetail
|
import me.jiniworld.demohx.application.notice.domain.NoticeDetail
|
||||||
import me.jiniworld.demohx.application.notice.domain.NoticeSimple
|
import me.jiniworld.demohx.application.notice.domain.NoticeSimple
|
||||||
|
|
||||||
interface GetNoticeQuery {
|
interface GetNoticeQuery {
|
||||||
suspend fun getNoticeSimples(command: GetNoticesCommand): List<NoticeSimple>?
|
fun getNoticeSimples(command: GetNoticesCommand): Flow<NoticeSimple>
|
||||||
suspend fun getNoticeDetail(id: String): NoticeDetail?
|
suspend fun getNoticeDetail(id: String): NoticeDetail?
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package me.jiniworld.demohx.application.notice.service
|
package me.jiniworld.demohx.application.notice.service
|
||||||
|
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
import me.jiniworld.demohx.annotation.UseCase
|
import me.jiniworld.demohx.annotation.UseCase
|
||||||
import me.jiniworld.demohx.application.notice.domain.NoticeDetail
|
import me.jiniworld.demohx.application.notice.domain.NoticeDetail
|
||||||
import me.jiniworld.demohx.application.notice.port.input.GetNoticeQuery
|
import me.jiniworld.demohx.application.notice.port.input.GetNoticeQuery
|
||||||
@@ -16,10 +15,9 @@ internal class GetNoticeService(
|
|||||||
private val loadNoticePort: LoadNoticePort,
|
private val loadNoticePort: LoadNoticePort,
|
||||||
) : GetNoticeQuery {
|
) : GetNoticeQuery {
|
||||||
|
|
||||||
override suspend fun getNoticeSimples(command: GetNoticesCommand) =
|
override fun getNoticeSimples(command: GetNoticesCommand) =
|
||||||
loadNoticePort.loadNotices(PageRequest.of(command.page, command.size, Sort.by(
|
loadNoticePort.loadNotices(PageRequest.of(command.page, command.size, Sort.by(
|
||||||
Sort.Order.desc("id"))))
|
Sort.Order.desc("id"))))
|
||||||
.toList()
|
|
||||||
|
|
||||||
override suspend fun getNoticeDetail(id: String): NoticeDetail? =
|
override suspend fun getNoticeDetail(id: String): NoticeDetail? =
|
||||||
loadNoticePort.loadNotice(id)
|
loadNoticePort.loadNotice(id)
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package me.jiniworld.demohx.notice.adapter.input.web
|
||||||
|
|
||||||
|
import io.mockk.mockk
|
||||||
|
import me.jiniworld.demohx.notice.application.port.input.GetNoticeQuery
|
||||||
|
import org.hamcrest.Matchers
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
||||||
|
import org.springframework.http.MediaType
|
||||||
|
import org.springframework.test.web.servlet.MockMvc
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
|
||||||
|
import org.springframework.test.web.servlet.result.MockMvcResultHandlers
|
||||||
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
|
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
||||||
|
|
||||||
|
@AutoConfigureRestDocs
|
||||||
|
@AutoConfigureMockMvc
|
||||||
|
internal class GetNoticeControllerTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private lateinit var mockMvc: MockMvc
|
||||||
|
|
||||||
|
private lateinit var getNoticeController: GetNoticeController
|
||||||
|
private lateinit var getNoticeQuery: GetNoticeQuery
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setUp() {
|
||||||
|
val registerNoticeUseCase = mockk<GetNoticeQuery>(relaxed = true)
|
||||||
|
this.getNoticeQuery = registerNoticeUseCase
|
||||||
|
val cont = GetNoticeController(registerNoticeUseCase)
|
||||||
|
this.getNoticeController = cont
|
||||||
|
this.mockMvc = MockMvcBuilders.standaloneSetup(cont).build()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getNotices() {
|
||||||
|
val resultActions = mockMvc.perform(
|
||||||
|
MockMvcRequestBuilders.get("/v1/notices")
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
)
|
||||||
|
|
||||||
|
// then
|
||||||
|
resultActions
|
||||||
|
.andExpect(MockMvcResultMatchers.status().isOk)
|
||||||
|
.andExpect(MockMvcResultMatchers.jsonPath("$.result", Matchers.`is`("success")))
|
||||||
|
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||||
|
.andDo(MockMvcResultHandlers.print())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getNotice() {
|
||||||
|
val resultActions = mockMvc.perform(
|
||||||
|
MockMvcRequestBuilders.get("/v1/notices/{id}", 1)
|
||||||
|
.accept(MediaType.APPLICATION_JSON)
|
||||||
|
)
|
||||||
|
|
||||||
|
// then
|
||||||
|
resultActions
|
||||||
|
.andExpect(MockMvcResultMatchers.status().isOk)
|
||||||
|
.andExpect(MockMvcResultMatchers.jsonPath("$.result", Matchers.`is`("success")))
|
||||||
|
.andExpect(MockMvcResultMatchers.jsonPath("$.data").exists())
|
||||||
|
.andExpect(MockMvcResultMatchers.jsonPath("$.data.id").isNotEmpty)
|
||||||
|
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||||
|
.andDo(MockMvcResultHandlers.print())
|
||||||
|
//
|
||||||
|
// resultActions.andDo(document("notice-search/success",
|
||||||
|
// requestFields(
|
||||||
|
// fieldWithPath("id").description("notice id")
|
||||||
|
// )
|
||||||
|
// ));
|
||||||
|
// prepa
|
||||||
|
// resource(
|
||||||
|
// ResourceSnippetParameters.builder()
|
||||||
|
// .description("v1 test")
|
||||||
|
// .pathParameters(
|
||||||
|
// parameterWithName("name").description("이름"))
|
||||||
|
// .responseFields(
|
||||||
|
// fieldWithPath("data").description("입력한 이름")
|
||||||
|
//// fieldWithPath("products").description("The product line item of the cart."),
|
||||||
|
//// subsectionWithPath("products[]._links.product").description("Link to the product."),
|
||||||
|
//// fieldWithPath("products[].quantity").description("The quantity of the line item."),
|
||||||
|
//// subsectionWithPath("products[].product").description("The product the line item relates to."),
|
||||||
|
//// subsectionWithPath("_links").description("Links section.")
|
||||||
|
// )
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun test1() {
|
||||||
|
val resultActions = mockMvc.perform(
|
||||||
|
MockMvcRequestBuilders.get("/v1/notices/test")
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
)
|
||||||
|
|
||||||
|
// then
|
||||||
|
resultActions
|
||||||
|
.andExpect(MockMvcResultMatchers.status().isOk)
|
||||||
|
.andExpect(MockMvcResultMatchers.jsonPath("$.result", Matchers.`is`("success")))
|
||||||
|
.andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.`is`("test")))
|
||||||
|
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||||
|
.andDo(MockMvcResultHandlers.print())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import io.swagger.v3.oas.annotations.tags.Tag
|
|||||||
import me.jiniworld.demohx.annotation.WebAdapter
|
import me.jiniworld.demohx.annotation.WebAdapter
|
||||||
import me.jiniworld.demohx.application.notice.port.input.GetNoticeQuery
|
import me.jiniworld.demohx.application.notice.port.input.GetNoticeQuery
|
||||||
import me.jiniworld.demohx.application.notice.port.input.GetNoticesCommand
|
import me.jiniworld.demohx.application.notice.port.input.GetNoticesCommand
|
||||||
import me.jiniworld.demohx.model.DataResponse
|
|
||||||
import me.jiniworld.demohx.model.NotFoundException
|
import me.jiniworld.demohx.model.NotFoundException
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
|
|
||||||
@@ -23,18 +22,16 @@ internal class GetNoticeController(
|
|||||||
@RequestParam(value = "page", required = false, defaultValue = "0") page: Int,
|
@RequestParam(value = "page", required = false, defaultValue = "0") page: Int,
|
||||||
@RequestParam(value = "size", required = false, defaultValue = "10") size: Int,
|
@RequestParam(value = "size", required = false, defaultValue = "10") size: Int,
|
||||||
) = getNoticeQuery.getNoticeSimples(GetNoticesCommand(page = page, size = size))
|
) = getNoticeQuery.getNoticeSimples(GetNoticesCommand(page = page, size = size))
|
||||||
?.let { DataResponse(data = it) }
|
|
||||||
?: throw NotFoundException("공지사항이 없습니다.")
|
?: throw NotFoundException("공지사항이 없습니다.")
|
||||||
|
|
||||||
@Operation(summary = "공지사항 상세조회")
|
@Operation(summary = "공지사항 상세조회")
|
||||||
@GetMapping("/{notice_id}")
|
@GetMapping("/{notice_id}")
|
||||||
fun getNotice(@PathVariable("notice_id") noticeId: Long,
|
fun getNotice(@PathVariable("notice_id") noticeId: Long,
|
||||||
) = getNoticeQuery.getNoticeDetail(noticeId)
|
) = getNoticeQuery.getNoticeDetail(noticeId)
|
||||||
?.let { DataResponse(data = it) }
|
|
||||||
?: throw NotFoundException("조회되는 공지사항이 없습니다.")
|
?: throw NotFoundException("조회되는 공지사항이 없습니다.")
|
||||||
|
|
||||||
@Operation(summary = "test")
|
@Operation(summary = "test")
|
||||||
@GetMapping("/test")
|
@GetMapping("/test")
|
||||||
fun test() = DataResponse(data = "test")
|
fun test() = "test"
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -19,12 +19,10 @@ internal class GetNoticeController(
|
|||||||
|
|
||||||
@Operation(summary = "공지사항 목록")
|
@Operation(summary = "공지사항 목록")
|
||||||
@GetMapping("")
|
@GetMapping("")
|
||||||
suspend fun getNotices(
|
fun getNotices(
|
||||||
@RequestParam(value = "page", required = false, defaultValue = "0") page: Int,
|
@RequestParam(value = "page", required = false, defaultValue = "0") page: Int,
|
||||||
@RequestParam(value = "size", required = false, defaultValue = "10") size: Int,
|
@RequestParam(value = "size", required = false, defaultValue = "10") size: Int,
|
||||||
) = getNoticeQuery.getNoticeSimples(GetNoticesCommand(page = page, size = size))
|
) = getNoticeQuery.getNoticeSimples(GetNoticesCommand(page = page, size = size))
|
||||||
?.let { DataResponse(data = it) }
|
|
||||||
?: throw NotFoundException("공지사항이 없습니다.")
|
|
||||||
|
|
||||||
@Operation(summary = "공지사항 상세조회")
|
@Operation(summary = "공지사항 상세조회")
|
||||||
@GetMapping("/{notice_id}")
|
@GetMapping("/{notice_id}")
|
||||||
|
|||||||
Reference in New Issue
Block a user