From 5ae48721ea5468beed4372262dd15eba41ce085d Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Tue, 9 Apr 2024 11:23:42 +0900 Subject: [PATCH 1/5] =?UTF-8?q?:memo:=20CommandEnvironmentPort=20=EC=97=90?= =?UTF-8?q?=20deleteEnvironment=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 --- .../application/port/output/CommandEnvironmentPort.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/andreas311/miso/domain/environment/application/port/output/CommandEnvironmentPort.kt b/src/main/kotlin/andreas311/miso/domain/environment/application/port/output/CommandEnvironmentPort.kt index 3868699b..dc2898b0 100644 --- a/src/main/kotlin/andreas311/miso/domain/environment/application/port/output/CommandEnvironmentPort.kt +++ b/src/main/kotlin/andreas311/miso/domain/environment/application/port/output/CommandEnvironmentPort.kt @@ -4,4 +4,5 @@ import andreas311.miso.domain.environment.domain.Environment interface CommandEnvironmentPort { fun saveEnvironment(environment: Environment): Environment + fun deleteEnvironment(environment: Environment) } \ No newline at end of file From cbd6b411d24dbb0b89fbd4055d74e4f255dc6159 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Tue, 9 Apr 2024 11:23:51 +0900 Subject: [PATCH 2/5] =?UTF-8?q?:memo:=20CommandEnvironmentPersistenceAdapt?= =?UTF-8?q?er=20=EC=97=90=20deleteEnvironment=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/CommandEnvironmentPersistenceAdapter.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/CommandEnvironmentPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/CommandEnvironmentPersistenceAdapter.kt index c882ae8a..a130f4ec 100644 --- a/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/CommandEnvironmentPersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/CommandEnvironmentPersistenceAdapter.kt @@ -15,4 +15,9 @@ class CommandEnvironmentPersistenceAdapter( val environmentEntity = environmentRepository.save(environmentMapper toEntity environment) return environmentMapper.toDomain(environmentEntity)!! } + + override fun deleteEnvironment(environment: Environment) { + val environmentEntity = environmentMapper toEntity environment + return environmentRepository.delete(environmentEntity) + } } \ No newline at end of file From 83696644ea057bf6398148e4723bf748fca61b59 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Tue, 9 Apr 2024 11:24:13 +0900 Subject: [PATCH 3/5] =?UTF-8?q?:sparkles:=20=ED=99=98=EA=B2=BD=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EA=B8=80=20=EC=82=AD=EC=A0=9C=ED=95=98=EA=B8=B0=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/DeleteEnvironmentUseCase.kt | 5 +++++ .../service/DeleteEnvironmentService.kt | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/application/port/input/DeleteEnvironmentUseCase.kt create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/application/service/DeleteEnvironmentService.kt diff --git a/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/DeleteEnvironmentUseCase.kt b/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/DeleteEnvironmentUseCase.kt new file mode 100644 index 00000000..2089e07b --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/DeleteEnvironmentUseCase.kt @@ -0,0 +1,5 @@ +package andreas311.miso.domain.environment.application.port.input + +interface DeleteEnvironmentUseCase { + fun execute(id: Long) +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/environment/application/service/DeleteEnvironmentService.kt b/src/main/kotlin/andreas311/miso/domain/environment/application/service/DeleteEnvironmentService.kt new file mode 100644 index 00000000..ca959d00 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/application/service/DeleteEnvironmentService.kt @@ -0,0 +1,20 @@ +package andreas311.miso.domain.environment.application.service + +import andreas311.miso.common.annotation.RollbackService +import andreas311.miso.domain.environment.application.exception.EnvironmentNotFoundException +import andreas311.miso.domain.environment.application.port.input.DeleteEnvironmentUseCase +import andreas311.miso.domain.environment.application.port.output.CommandEnvironmentPort +import andreas311.miso.domain.environment.application.port.output.QueryEnvironmentPort + +@RollbackService +class DeleteEnvironmentService( + private val queryEnvironmentPort: QueryEnvironmentPort, + private val commandEnvironmentPort: CommandEnvironmentPort +) : DeleteEnvironmentUseCase { + override fun execute(id: Long) { + val environment = queryEnvironmentPort.findByIdOrNull(id) + ?: throw EnvironmentNotFoundException() + + commandEnvironmentPort.deleteEnvironment(environment) + } +} \ No newline at end of file From 5086766faf0888f6f3cf924e3949d4a8b41402b2 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Tue, 9 Apr 2024 11:24:32 +0900 Subject: [PATCH 4/5] =?UTF-8?q?:sparkles:=20EnvironmentAdapter=20=EC=97=90?= =?UTF-8?q?=20=ED=99=98=EA=B2=BD=20=EC=A0=95=EB=B3=B4=20=EA=B8=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=ED=95=98=EA=B8=B0=20api=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=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 --- .../environment/adapter/input/EnvironmentAdapter.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/EnvironmentAdapter.kt b/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/EnvironmentAdapter.kt index bd394ac6..171f8d0d 100644 --- a/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/EnvironmentAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/EnvironmentAdapter.kt @@ -5,9 +5,11 @@ import andreas311.miso.domain.environment.adapter.input.data.request.CreateEnvir import andreas311.miso.domain.environment.adapter.input.data.request.EditEnvironmentRequest import andreas311.miso.domain.environment.adapter.input.mapper.EnvironmentDataMapper import andreas311.miso.domain.environment.application.port.input.CreateEnvironmentUseCase +import andreas311.miso.domain.environment.application.port.input.DeleteEnvironmentUseCase import andreas311.miso.domain.environment.application.port.input.EditEnvironmentUseCase 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,7 +21,8 @@ import javax.validation.Valid class EnvironmentAdapter( private val environmentDataMapper: EnvironmentDataMapper, private val editEnvironmentUseCase: EditEnvironmentUseCase, - private val createEnvironmentUseCase: CreateEnvironmentUseCase + private val createEnvironmentUseCase: CreateEnvironmentUseCase, + private val deleteEnvironmentUseCase: DeleteEnvironmentUseCase ) { @PostMapping fun create( @@ -37,4 +40,9 @@ class EnvironmentAdapter( ): ResponseEntity = editEnvironmentUseCase.execute(id, environmentDataMapper toDto editEnvironmentRequest, multipartFile) .let { ResponseEntity.status(HttpStatus.OK).build() } + + @DeleteMapping("/{id}") + fun delete(@PathVariable id: Long): ResponseEntity = + deleteEnvironmentUseCase.execute(id) + .let { ResponseEntity.status(HttpStatus.OK).build() } } \ No newline at end of file From bc35db71a0df7153083d471888225c15f4c837c9 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Tue, 9 Apr 2024 11:24:49 +0900 Subject: [PATCH 5/5] =?UTF-8?q?:memo:=20SecurityConfig=20=EC=97=90=20?= =?UTF-8?q?=ED=99=98=EA=B2=BD=20=EC=A0=95=EB=B3=B4=20=EA=B8=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=ED=95=98=EA=B8=B0=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 --- .../andreas311/miso/global/security/config/SecurityConfig.kt | 1 + 1 file changed, 1 insertion(+) 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 3031b9d5..751708ee 100644 --- a/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt +++ b/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt @@ -79,6 +79,7 @@ class SecurityConfig( .antMatchers(HttpMethod.GET, "/environment").authenticated() .antMatchers(HttpMethod.POST, "/environment").hasAuthority("ROLE_ADMIN") .antMatchers(HttpMethod.PATCH, "/environment/{id}").hasAuthority("ROLE_ADMIN") + .antMatchers(HttpMethod.DELETE, "/environment/{id}").hasAuthority("ROLE_ADMIN") .anyRequest().denyAll() .and()