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 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 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/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 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 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()