From 0f3e60a2a0739cfeb0425afb3fad3eeeebbad5e7 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Thu, 21 Mar 2024 09:12:33 +0900 Subject: [PATCH 1/5] =?UTF-8?q?:memo:=20CommandItemPersistenceAdapter=20?= =?UTF-8?q?=EC=97=90=20deleteItem=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/CommandItemPersistenceAdapter.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/kotlin/andreas311/miso/domain/item/adapter/output/persistence/CommandItemPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/item/adapter/output/persistence/CommandItemPersistenceAdapter.kt index fcb2a15d..dfd1dc2e 100644 --- a/src/main/kotlin/andreas311/miso/domain/item/adapter/output/persistence/CommandItemPersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/item/adapter/output/persistence/CommandItemPersistenceAdapter.kt @@ -15,4 +15,9 @@ class CommandItemPersistenceAdapter( val itemEntity = itemRepository.save(itemMapper toEntity item) return itemMapper.toDomain(itemEntity)!! } + + override fun deleteItem(item: Item) { + val itemEntity = itemMapper toEntity item + return itemRepository.delete(itemEntity) + } } \ No newline at end of file From f93a857f1db0c01b8643c0f19b3c382ab422efde Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Thu, 21 Mar 2024 09:12:38 +0900 Subject: [PATCH 2/5] =?UTF-8?q?:memo:=20CommandItemPersistenceAdapter=20?= =?UTF-8?q?=EC=97=90=20deleteItem=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 --- .../miso/domain/item/application/port/output/CommandItemPort.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/andreas311/miso/domain/item/application/port/output/CommandItemPort.kt b/src/main/kotlin/andreas311/miso/domain/item/application/port/output/CommandItemPort.kt index 34c9e8b7..59cef789 100644 --- a/src/main/kotlin/andreas311/miso/domain/item/application/port/output/CommandItemPort.kt +++ b/src/main/kotlin/andreas311/miso/domain/item/application/port/output/CommandItemPort.kt @@ -4,4 +4,6 @@ import andreas311.miso.domain.item.domain.Item interface CommandItemPort { fun saveItem(item: Item): Item + + fun deleteItem(item: Item) } \ No newline at end of file From 54a84d6d281cd34ca32918a7a3ba105a084ef1e4 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Thu, 21 Mar 2024 09:13:16 +0900 Subject: [PATCH 3/5] =?UTF-8?q?:sparkles:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20?= =?UTF-8?q?=EC=83=81=EC=A0=90=20=EB=AC=BC=ED=92=88=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../port/input/DeleteItemUseCase.kt | 5 +++++ .../application/service/DeleteItemService.kt | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/item/application/port/input/DeleteItemUseCase.kt create mode 100644 src/main/kotlin/andreas311/miso/domain/item/application/service/DeleteItemService.kt diff --git a/src/main/kotlin/andreas311/miso/domain/item/application/port/input/DeleteItemUseCase.kt b/src/main/kotlin/andreas311/miso/domain/item/application/port/input/DeleteItemUseCase.kt new file mode 100644 index 00000000..98ca54ab --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/item/application/port/input/DeleteItemUseCase.kt @@ -0,0 +1,5 @@ +package andreas311.miso.domain.item.application.port.input + +interface DeleteItemUseCase { + fun execute(id: Long) +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/item/application/service/DeleteItemService.kt b/src/main/kotlin/andreas311/miso/domain/item/application/service/DeleteItemService.kt new file mode 100644 index 00000000..81c07ef2 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/item/application/service/DeleteItemService.kt @@ -0,0 +1,20 @@ +package andreas311.miso.domain.item.application.service + +import andreas311.miso.common.annotation.RollbackService +import andreas311.miso.domain.item.application.exception.ItemNotFoundException +import andreas311.miso.domain.item.application.port.input.DeleteItemUseCase +import andreas311.miso.domain.item.application.port.output.CommandItemPort +import andreas311.miso.domain.item.application.port.output.QueryItemPort + +@RollbackService +class DeleteItemService( + private val queryItemPort: QueryItemPort, + private val commandItemPort: CommandItemPort +): DeleteItemUseCase { + override fun execute(id: Long) { + val itemEntity = queryItemPort.findByIdOrNull(id) + ?: throw ItemNotFoundException() + + commandItemPort.deleteItem(itemEntity) + } +} \ No newline at end of file From 50a60064d34d1a68f0ad99226eb79f8a034c896a Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Thu, 21 Mar 2024 09:13:33 +0900 Subject: [PATCH 4/5] =?UTF-8?q?:sparkles:=20ItemAdapter=20=EC=97=90=20?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=83=81=EC=A0=90=20=EB=AC=BC?= =?UTF-8?q?=ED=92=88=20=EC=82=AD=EC=A0=9C=20api=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=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 --- .../miso/domain/item/adapter/input/ItemAdapter.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/andreas311/miso/domain/item/adapter/input/ItemAdapter.kt b/src/main/kotlin/andreas311/miso/domain/item/adapter/input/ItemAdapter.kt index 7b28a630..0059d194 100644 --- a/src/main/kotlin/andreas311/miso/domain/item/adapter/input/ItemAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/item/adapter/input/ItemAdapter.kt @@ -5,9 +5,11 @@ import andreas311.miso.domain.item.adapter.input.data.request.CreateItemRequest import andreas311.miso.domain.item.adapter.input.data.request.EditItemRequest import andreas311.miso.domain.item.adapter.input.mapper.ItemDataMapper import andreas311.miso.domain.item.application.port.input.CreateItemUseCase +import andreas311.miso.domain.item.application.port.input.DeleteItemUseCase import andreas311.miso.domain.item.application.port.input.EditItemUseCase import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.DeleteMapping import org.springframework.web.bind.annotation.PatchMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping @@ -19,6 +21,7 @@ class ItemAdapter( private val itemDataMapper: ItemDataMapper, private val editItemUseCase: EditItemUseCase, private val createItemUseCase: CreateItemUseCase, + private val deleteItemUseCase: DeleteItemUseCase ) { @PostMapping fun create( @@ -28,6 +31,11 @@ class ItemAdapter( createItemUseCase.execute(itemDataMapper toDto createItemRequest, multipartFile) .let { ResponseEntity.status(HttpStatus.CREATED).build() } + @DeleteMapping("/{id}") + fun delete(@PathVariable id: Long): ResponseEntity = + deleteItemUseCase.execute(id) + .let { ResponseEntity.status(HttpStatus.NO_CONTENT).build() } + @PatchMapping("/{id}") fun edit ( @PathVariable id: Long, From f782a33a3e144791cf02fc50d9815c3e665fb0dd Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Thu, 21 Mar 2024 09:14:35 +0900 Subject: [PATCH 5/5] =?UTF-8?q?:memo:=20SecurityConfig=20=EC=97=90=20?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=83=81=EC=A0=90=20=EB=AC=BC?= =?UTF-8?q?=ED=92=88=20=EC=82=AD=EC=A0=9C=20api=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=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 --- .../miso/global/security/config/SecurityConfig.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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 dc126054..49ef8df6 100644 --- a/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt +++ b/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt @@ -41,22 +41,23 @@ class SecurityConfig( .antMatchers(HttpMethod.POST, "/auth").permitAll() .antMatchers(HttpMethod.POST, "/auth/signIn").permitAll() - .antMatchers(HttpMethod.DELETE, "/auth").permitAll() .antMatchers(HttpMethod.PATCH, "/auth").permitAll() + .antMatchers(HttpMethod.DELETE, "/auth").permitAll() .antMatchers(HttpMethod.POST, "/email").permitAll() + .antMatchers(HttpMethod.POST, "/item").hasAuthority("ROLE_ADMIN") .antMatchers(HttpMethod.GET, "/item").authenticated() .antMatchers(HttpMethod.GET, "/item/{id}").authenticated() - .antMatchers(HttpMethod.POST, "/item").authenticated() - .antMatchers(HttpMethod.PATCH, "/item/{id}").authenticated() + .antMatchers(HttpMethod.PATCH, "/item/{id}").hasAuthority("ROLE_ADMIN") + .antMatchers(HttpMethod.DELETE, "/item/{id}").hasAuthority("ROLE_ADMIN") + .antMatchers(HttpMethod.POST, "/user/give").authenticated() .antMatchers(HttpMethod.GET, "/user").authenticated() .antMatchers(HttpMethod.GET, "/user/point").authenticated() - .antMatchers(HttpMethod.POST, "/user/give").authenticated() - .antMatchers(HttpMethod.GET, "/purchase").authenticated() .antMatchers(HttpMethod.POST, "/purchase/{id}").authenticated() + .antMatchers(HttpMethod.GET, "/purchase").authenticated() .antMatchers(HttpMethod.POST, "/inquiry").authenticated() .antMatchers(HttpMethod.GET, "/inquiry").authenticated() @@ -66,10 +67,10 @@ class SecurityConfig( .antMatchers(HttpMethod.GET, "/inquiry/{id}").authenticated() .antMatchers(HttpMethod.PATCH, "/inquiry/respond/{id}").hasAuthority("ROLE_ADMIN") + .antMatchers(HttpMethod.POST, "/recyclables/process").authenticated() .antMatchers(HttpMethod.GET, "/recyclables").authenticated() .antMatchers(HttpMethod.GET, "/recyclables/search").authenticated() .antMatchers(HttpMethod.GET, "/recyclables/all").authenticated() - .antMatchers(HttpMethod.POST, "/recyclables/process").authenticated() .antMatchers(HttpMethod.POST, "/notification/save/{deviceToken}").authenticated() .antMatchers(HttpMethod.GET, "/notification/{id}").authenticated()