-
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-97] feat: 피험자 모집 실험 공고 상세 정보 조회 API 구현 및 자잘한 리팩터링 (#27)
* refactor: Update region and area's values to English for consistency * feat: add ExperimentPostDetailResponse * refactor: Update timeSlot's values to English for consistency * refact: rename Signup to Member for consistency * refact: remove AuditingEntity and manually set createdAt * refact: refactor ExperimentPostDetailResponse * feat: add getExperimentPostDetail Api * refact: rename state field's name * feat: add increment views * test: add GetExperimentPostDetailUseCase test code * refact: change field types to enum in response and request DTOs * refact: add `@PreAuthorize` for researcher's api * refact: Handle nullable fields for CreateExperimentPost in the flow * feat: add annotation to appropriate api
- Loading branch information
Showing
51 changed files
with
860 additions
and
577 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
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
78 changes: 78 additions & 0 deletions
78
...kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostDetailUseCase.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,78 @@ | ||
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.ExperimentPostGateway | ||
import com.dobby.backend.domain.model.experiment.ExperimentPost | ||
import com.dobby.backend.domain.model.experiment.TargetGroup | ||
import com.dobby.backend.presentation.api.dto.response.expirement.ExperimentPostDetailResponse | ||
|
||
class GetExperimentPostDetailUseCase( | ||
private val experimentPostGateway: ExperimentPostGateway | ||
) : UseCase<GetExperimentPostDetailUseCase.Input, GetExperimentPostDetailUseCase.Output> { | ||
|
||
data class Input( | ||
val experimentPostId: Long | ||
) | ||
|
||
data class Output( | ||
val experimentPostDetailResponse: ExperimentPostDetailResponse | ||
) | ||
|
||
override fun execute(input: Input): Output { | ||
val experimentPost = experimentPostGateway.findById(input.experimentPostId) | ||
?: throw ExperimentPostNotFoundException() | ||
experimentPost.incrementViews() | ||
experimentPostGateway.save(experimentPost) | ||
|
||
return Output( | ||
experimentPostDetailResponse = experimentPost.toDetailResponse() | ||
) | ||
} | ||
} | ||
|
||
fun ExperimentPost.toDetailResponse(): ExperimentPostDetailResponse { | ||
return ExperimentPostDetailResponse( | ||
experimentPostId = this.id, | ||
title = this.title, | ||
uploadDate = this.createdAt.toLocalDate(), | ||
uploaderName = this.member.name, | ||
views = this.views, | ||
recruitDone = this.recruitDone, | ||
summary = this.toSummaryResponse(), | ||
targetGroup = this.targetGroup.toResponse(), | ||
address = this.toAddressResponse(), | ||
content = this.content, | ||
imageList = this.images.map { it.imageUrl } | ||
) | ||
} | ||
|
||
fun ExperimentPost.toSummaryResponse(): ExperimentPostDetailResponse.SummaryResponse { | ||
return ExperimentPostDetailResponse.SummaryResponse( | ||
startDate = this.startDate, | ||
endDate = this.endDate, | ||
leadResearcher = this.leadResearcher, | ||
matchType = this.matchType, | ||
reward = this.reward, | ||
count = this.count, | ||
timeRequired = this.timeRequired | ||
) | ||
} | ||
|
||
fun TargetGroup.toResponse(): ExperimentPostDetailResponse.TargetGroupResponse { | ||
return ExperimentPostDetailResponse.TargetGroupResponse( | ||
startAge = this.startAge, | ||
endAge = this.endAge, | ||
genderType = this.genderType, | ||
otherCondition = this.otherCondition | ||
) | ||
} | ||
|
||
fun ExperimentPost.toAddressResponse(): ExperimentPostDetailResponse.AddressResponse { | ||
return ExperimentPostDetailResponse.AddressResponse( | ||
univName = this.univName, | ||
region = this.region, | ||
area = this.area, | ||
detailedAddress = this.detailedAddress | ||
) | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/dobby/backend/domain/exception/ExperimentPostException.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,7 @@ | ||
package com.dobby.backend.domain.exception | ||
|
||
open class ExperimentPostException( | ||
errorCode: ErrorCode, | ||
) : DomainException(errorCode) | ||
|
||
class ExperimentPostNotFoundException : ExperimentPostException(ErrorCode.EXPERIMENT_POST_NOT_FOUND) |
Oops, something went wrong.