-
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-179] feat: 실험자가 작성한 공고 게시글 수정 API 구현 (#51)
* feat: add update ExperimentPost API logic * fix: resolve merge conflicts from dev * fix: resolve merge conflicts from dev * refact: add exception case for update post image and fix typo * refact: refactor update logic for using ExperimentPostGateway and querydsl - `querydsl` 이용하여 update 로직 개선 - 기존 유즈케이스에서 처리하던 update 로직Gateway에 위임 - 유즈케이스는 비즈니스 로직에만 집중할 수 있게 리팩터링 - 예외처리 로직 메서드 단위로 분리
- Loading branch information
Showing
27 changed files
with
610 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
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
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.