-
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.
- Loading branch information
Showing
30 changed files
with
732 additions
and
164 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
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
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) | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
...in/kotlin/com/dobby/backend/application/usecase/experiment/UpdateExperimentPostUseCase.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,127 @@ | ||
package com.dobby.backend.application.usecase.experiment | ||
|
||
import com.dobby.backend.application.mapper.ExperimentMapper | ||
import com.dobby.backend.application.usecase.UseCase | ||
import com.dobby.backend.domain.exception.ErrorCode | ||
import com.dobby.backend.domain.exception.ExperimentPostException | ||
import com.dobby.backend.domain.gateway.experiment.ExperimentPostGateway | ||
import com.dobby.backend.domain.model.experiment.ExperimentPost | ||
import com.dobby.backend.infrastructure.database.entity.enums.GenderType | ||
import com.dobby.backend.infrastructure.database.entity.enums.MatchType | ||
import com.dobby.backend.infrastructure.database.entity.enums.TimeSlot | ||
import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area | ||
import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region | ||
import java.time.LocalDate | ||
|
||
class UpdateExperimentPostUseCase ( | ||
private val experimentPostGateway: ExperimentPostGateway | ||
) : UseCase<UpdateExperimentPostUseCase.Input, UpdateExperimentPostUseCase.Output> { | ||
data class Input( | ||
val experimentPostId: Long, | ||
val memberId: Long, | ||
val targetGroupInfo: TargetGroupInfo?, | ||
val applyMethodInfo: ApplyMethodInfo?, | ||
val imageListInfo: ImageListInfo?, | ||
|
||
val startDate: LocalDate?, | ||
val endDate: LocalDate?, | ||
val matchType: MatchType?, | ||
val count: Int?, | ||
val timeRequired: TimeSlot?, | ||
|
||
val leadResearcher: String?, | ||
val univName: String?, | ||
val region: Region?, | ||
val area: Area?, | ||
val detailedAddress : String?, | ||
|
||
val reward: String?, | ||
val title: String?, | ||
val content: String? | ||
) | ||
|
||
data class TargetGroupInfo( | ||
val startAge: Int?, | ||
val endAge: Int?, | ||
val genderType: GenderType, | ||
val otherCondition: String? | ||
) | ||
|
||
data class ApplyMethodInfo( | ||
val content: String, | ||
val formUrl: String?, | ||
val phoneNum: String? | ||
) | ||
|
||
data class ImageListInfo( | ||
val images: List<String> = mutableListOf() | ||
) | ||
|
||
data class Output( | ||
val postInfo: PostInfo | ||
) | ||
|
||
data class PostInfo( | ||
val postId: Long, | ||
val title: String, | ||
val views: Int, | ||
val univName: String?, | ||
val reward: String?, | ||
val durationInfo: DurationInfo?, | ||
) | ||
|
||
data class DurationInfo( | ||
val startDate: LocalDate?, | ||
val endDate: LocalDate? | ||
) | ||
|
||
override fun execute(input: Input): Output { | ||
val existingPost = validate(input) | ||
val experimentPost = ExperimentMapper.toDomain(input, existingPost) | ||
val updatedPost = experimentPostGateway.updateExperimentPost(experimentPost) | ||
|
||
return Output( | ||
postInfo = PostInfo( | ||
postId = updatedPost.id, | ||
title = updatedPost.title, | ||
views = updatedPost.views, | ||
univName = updatedPost.univName, | ||
reward = updatedPost.reward, | ||
durationInfo = DurationInfo( | ||
startDate = updatedPost.startDate, | ||
endDate = updatedPost.endDate | ||
) | ||
) | ||
) | ||
} | ||
|
||
private fun validate(input: Input): ExperimentPost { | ||
val existingPost = validateExistingPost(input) | ||
validatePermission(existingPost, input) | ||
validateNotExpired(existingPost) | ||
validateImageCount(input) | ||
return existingPost | ||
} | ||
|
||
private fun validateExistingPost(input: Input): ExperimentPost { | ||
return experimentPostGateway.findExperimentPostByMemberIdAndPostId(input.memberId, input.experimentPostId) | ||
?: throw ExperimentPostException(ErrorCode.EXPERIMENT_POST_NOT_FOUND) | ||
} | ||
|
||
private fun validatePermission(existingPost: ExperimentPost, input: Input) { | ||
if(existingPost.member.id != input.memberId) throw ExperimentPostException(ErrorCode.PERMISSION_DENIED) | ||
} | ||
|
||
|
||
private fun validateNotExpired(existingPost: ExperimentPost){ | ||
if (!existingPost.recruitStatus) throw ExperimentPostException(ErrorCode.EXPERIMENT_POST_CANNOT_UPDATE_DATE) | ||
} | ||
|
||
private fun validateImageCount(input: Input) { | ||
input.imageListInfo?.let { | ||
if(it.images.size > 3) { | ||
throw ExperimentPostException(ErrorCode.EXPERIMENT_POST_IMAGE_SIZE_LIMIT) | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.