-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[YS-178] feat: 실험자가 작성한 공고 게시글 삭제 API 구현 (#52)
* feat: add DefaultResponse * feat: add delete repository method * feat: add DeleteExperimentPost API * test: add DeleteExperimentPostUseCase test code * refact: refactor delete method in repository impl * refact: add `@Transactional` to delete method
- Loading branch information
Showing
8 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...in/kotlin/com/dobby/backend/application/usecase/experiment/DeleteExperimentPostUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.dobby.backend.application.usecase.experiment | ||
|
||
import com.dobby.backend.application.usecase.UseCase | ||
import com.dobby.backend.domain.exception.ExperimentPostNotFoundException | ||
import com.dobby.backend.domain.gateway.experiment.ExperimentPostGateway | ||
|
||
class DeleteExperimentPostUseCase( | ||
private val experimentPostGateway: ExperimentPostGateway | ||
): UseCase<DeleteExperimentPostUseCase.Input, Unit> { | ||
data class Input( | ||
val memberId: Long, | ||
val postId: Long | ||
) | ||
|
||
override fun execute(input: Input) { | ||
val post = experimentPostGateway.findExperimentPostByMemberIdAndPostId( | ||
memberId = input.memberId, | ||
postId = input.postId | ||
) ?: throw ExperimentPostNotFoundException() | ||
|
||
experimentPostGateway.delete(post) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/dobby/backend/presentation/api/dto/response/member/DefaultResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.dobby.backend.presentation.api.dto.response.member | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
@Schema(description = "기본 Operation 응답") | ||
data class DefaultResponse( | ||
@Schema(description = "성공 유무", example = "true") | ||
val success: Boolean | ||
) { | ||
companion object { | ||
fun ok(): DefaultResponse = DefaultResponse(true) | ||
fun fail(): DefaultResponse = DefaultResponse(false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...otlin/com/dobby/backend/application/usecase/experiment/DeleteExperimentPostUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.dobby.backend.application.usecase.experiment | ||
|
||
import com.dobby.backend.domain.exception.ExperimentPostNotFoundException | ||
import com.dobby.backend.domain.gateway.experiment.ExperimentPostGateway | ||
import com.dobby.backend.domain.model.experiment.ExperimentPost | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
|
||
class DeleteExperimentPostUseCaseTest : BehaviorSpec({ | ||
|
||
val experimentPostGateway = mockk<ExperimentPostGateway>() | ||
val deleteExperimentPostUseCase = DeleteExperimentPostUseCase(experimentPostGateway) | ||
|
||
given("게시글을 삭제할 때") { | ||
val memberId = 1L | ||
val postId = 2L | ||
val input = DeleteExperimentPostUseCase.Input(memberId, postId) | ||
|
||
val existingPost = mockk<ExperimentPost>() | ||
every { experimentPostGateway.findExperimentPostByMemberIdAndPostId(memberId, postId) } returns existingPost | ||
|
||
`when`("게시글이 존재하면") { | ||
every { experimentPostGateway.delete(existingPost) } returns Unit | ||
|
||
then("게시글을 삭제하고 아무 값도 반환하지 않아야 한다") { | ||
deleteExperimentPostUseCase.execute(input) | ||
verify(exactly = 1) { experimentPostGateway.findExperimentPostByMemberIdAndPostId(memberId, postId) } | ||
verify(exactly = 1) { experimentPostGateway.delete(existingPost) } | ||
} | ||
} | ||
} | ||
|
||
given("게시글을 삭제하려는데 게시글이 존재하지 않는 경우") { | ||
val memberId = 1L | ||
val postId = 999L | ||
val input = DeleteExperimentPostUseCase.Input(memberId, postId) | ||
|
||
every { experimentPostGateway.findExperimentPostByMemberIdAndPostId(memberId, postId) } returns null | ||
|
||
`when`("게시글을 찾지 못하면") { | ||
then("ExperimentPostNotFoundException 예외가 발생해야 한다") { | ||
shouldThrow<ExperimentPostNotFoundException> { | ||
deleteExperimentPostUseCase.execute(input) | ||
} | ||
verify(exactly = 1) { experimentPostGateway.findExperimentPostByMemberIdAndPostId(memberId, postId) } | ||
} | ||
} | ||
} | ||
}) |