Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔀 :: 환경 정보 글 삭제하기 API 구현 #97

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading