Skip to content

Commit

Permalink
Merge pull request #97 from TeamMiso/feat/environment-delete
Browse files Browse the repository at this point in the history
🔀 :: 환경 정보 글 삭제하기 API 구현
  • Loading branch information
uuuuuuuk authored Apr 9, 2024
2 parents 109d373 + bc35db7 commit f3b015c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -37,4 +40,9 @@ class EnvironmentAdapter(
): ResponseEntity<Void> =
editEnvironmentUseCase.execute(id, environmentDataMapper toDto editEnvironmentRequest, multipartFile)
.let { ResponseEntity.status(HttpStatus.OK).build() }

@DeleteMapping("/{id}")
fun delete(@PathVariable id: Long): ResponseEntity<Void> =
deleteEnvironmentUseCase.execute(id)
.let { ResponseEntity.status(HttpStatus.OK).build() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package andreas311.miso.domain.environment.application.port.input

interface DeleteEnvironmentUseCase {
fun execute(id: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import andreas311.miso.domain.environment.domain.Environment

interface CommandEnvironmentPort {
fun saveEnvironment(environment: Environment): Environment
fun deleteEnvironment(environment: Environment)
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f3b015c

Please sign in to comment.