From 0427fb8e2b6640c3af030033c1ffcc8916a3513f Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 1 Apr 2024 11:52:42 +0900 Subject: [PATCH 1/9] =?UTF-8?q?:memo:=20DetailRecyclablesDto=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../port/input/dto/DetailRecyclablesDto.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/dto/DetailRecyclablesDto.kt diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/dto/DetailRecyclablesDto.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/dto/DetailRecyclablesDto.kt new file mode 100644 index 00000000..5055cdd0 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/dto/DetailRecyclablesDto.kt @@ -0,0 +1,28 @@ +package andreas311.miso.domain.recyclables.application.port.input.dto + +import andreas311.miso.domain.recyclables.domain.Recyclables +import andreas311.miso.domain.recyclables.domain.RecyclablesType + +data class DetailRecyclablesDto( + val id: Long, + val title: String, + val subTitle: String, + val recycleMethod: String, + val recycleTip: String, + val recycleCaution: String, + val imageUrl: String?, + val recyclablesType: RecyclablesType, + val recycleMark: String +) { + constructor(recyclables: Recyclables) : this( + id = recyclables.id, + title = recyclables.title, + subTitle = recyclables.subTitle, + recycleMethod = recyclables.recycleMethod, + recycleTip = recyclables.recycleTip, + recycleCaution = recyclables.recycleCaution, + imageUrl = recyclables.imageUrl, + recyclablesType = recyclables.recyclablesType, + recycleMark = recyclables.recycleMark + ) +} From 1c9e215ef0f7e48f94bc4dda7916a934185e30bb Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 1 Apr 2024 11:52:49 +0900 Subject: [PATCH 2/9] =?UTF-8?q?:memo:=20DetailRecyclablesResponse=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/response/DetailRecyclablesResponse.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/data/response/DetailRecyclablesResponse.kt diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/data/response/DetailRecyclablesResponse.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/data/response/DetailRecyclablesResponse.kt new file mode 100644 index 00000000..2110cc4b --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/data/response/DetailRecyclablesResponse.kt @@ -0,0 +1,15 @@ +package andreas311.miso.domain.recyclables.adapter.input.data.response + +import andreas311.miso.domain.recyclables.domain.RecyclablesType + +data class DetailRecyclablesResponse( + val id: Long, + val title: String, + val subTitle: String, + val recycleMethod: String, + val recycleTip: String, + val recycleCaution: String, + val imageUrl: String?, + val recyclablesType: RecyclablesType, + val recycleMark: String +) From 30d1acf98e7ab93ad18e6eb720523bb7acab52bc Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 1 Apr 2024 12:18:18 +0900 Subject: [PATCH 3/9] =?UTF-8?q?:memo:=20QueryRecyclablesPort=20=EC=97=90?= =?UTF-8?q?=20findByRecyclablesTypeOrNull=20=ED=95=A8=EC=88=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recyclables/application/port/output/QueryRecyclablesPort.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/output/QueryRecyclablesPort.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/output/QueryRecyclablesPort.kt index 3b5873d8..356da42d 100644 --- a/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/output/QueryRecyclablesPort.kt +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/output/QueryRecyclablesPort.kt @@ -1,7 +1,9 @@ package andreas311.miso.domain.recyclables.application.port.output import andreas311.miso.domain.recyclables.domain.Recyclables +import andreas311.miso.domain.recyclables.domain.RecyclablesType interface QueryRecyclablesPort { fun findByIdOrNull(id: Long): Recyclables? + fun findByRecyclablesTypeOrNull(recyclablesType: RecyclablesType): Recyclables? } \ No newline at end of file From cb472a5ef7e8a0e27c696452d9cc8647793fc20f Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 1 Apr 2024 12:18:35 +0900 Subject: [PATCH 4/9] =?UTF-8?q?:memo:=20QueryRecyclablesPersistenceAdapter?= =?UTF-8?q?=20=EC=97=90=20findByRecyclablesTypeOrNull=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/QueryRecyclablesPersistenceAdapter.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/QueryRecyclablesPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/QueryRecyclablesPersistenceAdapter.kt index 506e57ee..cc2d3eab 100644 --- a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/QueryRecyclablesPersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/QueryRecyclablesPersistenceAdapter.kt @@ -4,6 +4,7 @@ import andreas311.miso.domain.recyclables.adapter.output.persistence.mapper.Recy import andreas311.miso.domain.recyclables.adapter.output.persistence.repository.RecyclablesRepository import andreas311.miso.domain.recyclables.application.port.output.QueryRecyclablesPort import andreas311.miso.domain.recyclables.domain.Recyclables +import andreas311.miso.domain.recyclables.domain.RecyclablesType import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Component @@ -16,4 +17,9 @@ class QueryRecyclablesPersistenceAdapter( val recyclablesEntity = recyclablesRepository.findByIdOrNull(id) return recyclablesMapper toDomain recyclablesEntity } + + override fun findByRecyclablesTypeOrNull(recyclablesType: RecyclablesType): Recyclables? { + val recyclablesEntity = recyclablesRepository.findByRecyclablesType(recyclablesType) + return recyclablesMapper toDomain recyclablesEntity + } } \ No newline at end of file From 0726495000f6102a057bac3bf62773f53ed9cbcf Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 1 Apr 2024 12:18:54 +0900 Subject: [PATCH 5/9] =?UTF-8?q?:memo:=20RecyclablesRepository=20=EC=97=90?= =?UTF-8?q?=20findByRecyclablesType=20=ED=95=A8=EC=88=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../output/persistence/repository/RecyclablesRepository.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/repository/RecyclablesRepository.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/repository/RecyclablesRepository.kt index 430e4172..cfa9df9f 100644 --- a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/repository/RecyclablesRepository.kt +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/repository/RecyclablesRepository.kt @@ -1,7 +1,9 @@ package andreas311.miso.domain.recyclables.adapter.output.persistence.repository import andreas311.miso.domain.recyclables.adapter.output.persistence.entity.RecyclablesEntity +import andreas311.miso.domain.recyclables.domain.RecyclablesType import org.springframework.data.repository.CrudRepository interface RecyclablesRepository : CrudRepository { + fun findByRecyclablesType(recyclablesType: RecyclablesType): RecyclablesEntity? } \ No newline at end of file From 7265693584d70c6123e3f3d86bba1dfd2eec69b6 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 1 Apr 2024 12:19:09 +0900 Subject: [PATCH 6/9] =?UTF-8?q?:memo:=20RecyclablesDataMapper=20=EC=97=90?= =?UTF-8?q?=20toResponse=20=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/input/mapper/RecyclablesDataMapper.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/mapper/RecyclablesDataMapper.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/mapper/RecyclablesDataMapper.kt index 78484277..61ec683e 100644 --- a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/mapper/RecyclablesDataMapper.kt +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/mapper/RecyclablesDataMapper.kt @@ -2,7 +2,9 @@ package andreas311.miso.domain.recyclables.adapter.input.mapper import andreas311.miso.domain.recyclables.adapter.input.data.request.CreateRecyclablesRequest import andreas311.miso.domain.recyclables.adapter.input.data.request.EditRecyclablesRequest +import andreas311.miso.domain.recyclables.adapter.input.data.response.DetailRecyclablesResponse import andreas311.miso.domain.recyclables.application.port.input.dto.CreateRecyclablesDto +import andreas311.miso.domain.recyclables.application.port.input.dto.DetailRecyclablesDto import andreas311.miso.domain.recyclables.application.port.input.dto.EditRecyclablesDto import org.springframework.stereotype.Component @@ -29,4 +31,17 @@ class RecyclablesDataMapper { recyclablesType = editRecyclablesRequest.recyclablesType, recycleMark = editRecyclablesRequest.recycleMark ) + + fun toResponse(detailRecyclablesDto: DetailRecyclablesDto): DetailRecyclablesResponse = + DetailRecyclablesResponse( + id = detailRecyclablesDto.id, + title = detailRecyclablesDto.title, + subTitle = detailRecyclablesDto.subTitle, + recycleMethod = detailRecyclablesDto.recycleMethod, + recycleTip = detailRecyclablesDto.recycleTip, + recycleCaution = detailRecyclablesDto.recycleCaution, + imageUrl = detailRecyclablesDto.imageUrl, + recyclablesType = detailRecyclablesDto.recyclablesType, + recycleMark = detailRecyclablesDto.recycleMark + ) } \ No newline at end of file From cc6a0388a056eb080e8d07f9bde5121c3036297f Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 1 Apr 2024 12:19:39 +0900 Subject: [PATCH 7/9] =?UTF-8?q?:sparkles:=20=EC=9E=AC=ED=99=9C=EC=9A=A9?= =?UTF-8?q?=ED=92=88=20=EB=B0=A9=EB=B2=95=20=EA=B8=80=20=EC=83=81=EC=84=B8?= =?UTF-8?q?=EB=B3=B4=EA=B8=B0=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../port/input/DetailRecyclablesUseCase.kt | 8 ++++++++ .../service/DetailRecyclablesService.kt | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/DetailRecyclablesUseCase.kt create mode 100644 src/main/kotlin/andreas311/miso/domain/recyclables/application/service/DetailRecyclablesService.kt diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/DetailRecyclablesUseCase.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/DetailRecyclablesUseCase.kt new file mode 100644 index 00000000..66e33d8c --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/DetailRecyclablesUseCase.kt @@ -0,0 +1,8 @@ +package andreas311.miso.domain.recyclables.application.port.input + +import andreas311.miso.domain.recyclables.application.port.input.dto.DetailRecyclablesDto +import andreas311.miso.domain.recyclables.domain.RecyclablesType + +interface DetailRecyclablesUseCase { + fun execute(recyclablesType: RecyclablesType): DetailRecyclablesDto +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/DetailRecyclablesService.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/DetailRecyclablesService.kt new file mode 100644 index 00000000..4650fb7d --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/DetailRecyclablesService.kt @@ -0,0 +1,20 @@ +package andreas311.miso.domain.recyclables.application.service + +import andreas311.miso.common.annotation.ReadOnlyRollbackService +import andreas311.miso.domain.recyclables.application.exception.RecyclablesNotFoundException +import andreas311.miso.domain.recyclables.application.port.input.DetailRecyclablesUseCase +import andreas311.miso.domain.recyclables.application.port.input.dto.DetailRecyclablesDto +import andreas311.miso.domain.recyclables.application.port.output.QueryRecyclablesPort +import andreas311.miso.domain.recyclables.domain.RecyclablesType + +@ReadOnlyRollbackService +class DetailRecyclablesService( + private val queryRecyclablesPort: QueryRecyclablesPort +) : DetailRecyclablesUseCase { + override fun execute(recyclablesType: RecyclablesType): DetailRecyclablesDto { + val recyclables = queryRecyclablesPort.findByRecyclablesTypeOrNull(recyclablesType) + ?: throw RecyclablesNotFoundException() + + return DetailRecyclablesDto(recyclables) + } +} \ No newline at end of file From a45e95f9647fce8321247a493706eec62a8efc83 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 1 Apr 2024 12:20:16 +0900 Subject: [PATCH 8/9] =?UTF-8?q?:sparkles:=20RecyclablesAdapter=20=EC=97=90?= =?UTF-8?q?=20=EC=9E=AC=ED=99=9C=EC=9A=A9=ED=92=88=20=EB=B0=A9=EB=B2=95=20?= =?UTF-8?q?=EA=B8=80=20=EC=83=81=EC=84=B8=EB=B3=B4=EA=B8=B0=20api=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/input/RecyclablesAdapter.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/RecyclablesAdapter.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/RecyclablesAdapter.kt index 23014ba3..e026507b 100644 --- a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/RecyclablesAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/RecyclablesAdapter.kt @@ -3,13 +3,17 @@ package andreas311.miso.domain.recyclables.adapter.input import andreas311.miso.common.annotation.RequestController import andreas311.miso.domain.recyclables.adapter.input.data.request.CreateRecyclablesRequest import andreas311.miso.domain.recyclables.adapter.input.data.request.EditRecyclablesRequest +import andreas311.miso.domain.recyclables.adapter.input.data.response.DetailRecyclablesResponse import andreas311.miso.domain.recyclables.adapter.input.mapper.RecyclablesDataMapper import andreas311.miso.domain.recyclables.application.port.input.CreateRecyclablesUseCase import andreas311.miso.domain.recyclables.application.port.input.DeleteRecyclablesUseCase +import andreas311.miso.domain.recyclables.application.port.input.DetailRecyclablesUseCase import andreas311.miso.domain.recyclables.application.port.input.EditRecyclablesUseCase +import andreas311.miso.domain.recyclables.domain.RecyclablesType import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PatchMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping @@ -22,7 +26,8 @@ class RecyclablesAdapter( private val recyclablesDataMapper: RecyclablesDataMapper, private val editRecyclablesUseCase: EditRecyclablesUseCase, private val createRecyclablesUseCase: CreateRecyclablesUseCase, - private val deleteRecyclablesUseCase: DeleteRecyclablesUseCase + private val detailRecyclablesUseCase: DetailRecyclablesUseCase, + private val deleteRecyclablesUseCase: DeleteRecyclablesUseCase, ) { @PostMapping fun create( @@ -32,10 +37,11 @@ class RecyclablesAdapter( createRecyclablesUseCase.execute(recyclablesDataMapper toDto createRecyclablesRequest, multipartFile) .let { ResponseEntity.status(HttpStatus.CREATED).build() } - @DeleteMapping("/{id}") - fun delete(@PathVariable id: Long): ResponseEntity = - deleteRecyclablesUseCase.execute(id) - .let { ResponseEntity.status(HttpStatus.OK).build() } + @GetMapping("/{type}") + fun detail(@PathVariable(name = "type") recyclablesType: RecyclablesType): ResponseEntity = + detailRecyclablesUseCase.execute(recyclablesType) + .let { recyclablesDataMapper.toResponse(it) } + .let { ResponseEntity.status(HttpStatus.OK).body(it) } @PatchMapping("/{id}") fun edit( @@ -45,4 +51,10 @@ class RecyclablesAdapter( ): ResponseEntity = editRecyclablesUseCase.execute(id, recyclablesDataMapper toDto editRecyclablesRequest, multipartFile) .let { ResponseEntity.status(HttpStatus.OK).build() } + + @DeleteMapping("/{id}") + fun delete(@PathVariable id: Long): ResponseEntity = + deleteRecyclablesUseCase.execute(id) + .let { ResponseEntity.status(HttpStatus.OK).build() } + } \ No newline at end of file From c654a8b5d90bbe27b391a0d57a212c0df6d49c05 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 1 Apr 2024 12:20:38 +0900 Subject: [PATCH 9/9] =?UTF-8?q?:memo:=20SecurityConfig=20=EC=97=90=20?= =?UTF-8?q?=EC=9E=AC=ED=99=9C=EC=9A=A9=ED=92=88=20=EB=B0=A9=EB=B2=95=20?= =?UTF-8?q?=EA=B8=80=20=EC=83=81=EC=84=B8=EB=B3=B4=EA=B8=B0=20api=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../andreas311/miso/global/security/config/SecurityConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt b/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt index 32781407..94fa42a9 100644 --- a/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt +++ b/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt @@ -67,7 +67,7 @@ class SecurityConfig( .antMatchers(HttpMethod.POST, "/recyclables").hasAuthority("ROLE_ADMIN") .antMatchers(HttpMethod.POST, "/recyclables/process").authenticated() - .antMatchers(HttpMethod.GET, "/recyclables").authenticated() + .antMatchers(HttpMethod.GET, "/recyclables/{type}").authenticated() .antMatchers(HttpMethod.GET, "/recyclables/search").authenticated() .antMatchers(HttpMethod.GET, "/recyclables/all").authenticated() .antMatchers(HttpMethod.PATCH, "/recyclables/{id}").hasAuthority("ROLE_ADMIN")