Skip to content

Commit

Permalink
[FEATURE] #105 : GetSurveyFormList 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Jan 17, 2024
1 parent 903aa11 commit 2e12230
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface SurveyFormRepository {

suspend fun getSurveyFormList(): Result<List<SurveyForm>>

suspend fun getSurveyFormList(eventId: String): Result<List<SurveyForm>>

suspend fun deleteSurveyForm(surveyFormId: String): Result<Unit>

suspend fun postSurveyForm(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class SurveyFormRepositoryImpl @Inject constructor(
override suspend fun deleteSurveyForm(surveyFormId: String): Result<Unit> =
surveyFormDataSource.deleteSurveyForm(surveyFormId)

override suspend fun getSurveyFormList(eventId: String): Result<List<SurveyForm>> =
surveyFormDataSource.getSurveyFormList(eventId).mapCatching { surveyFormResponseList ->
surveyFormResponseList.map { surveyFormResponse ->
surveyFormResponse.toDomain()
}
}

override suspend fun postSurveyForm(
eventId: String,
title: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ class GetSurveyFormListUseCase @Inject constructor(
private val surveyFormRepository: SurveyFormRepository,
) {
suspend operator fun invoke() = surveyFormRepository.getSurveyFormList()

suspend operator fun invoke(eventId: String) = surveyFormRepository.getSurveyFormList(eventId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface SurveyFormDataSource {

suspend fun getSurveyFormList(): Result<List<SurveyFormResponse>>

suspend fun getSurveyFormList(eventId: String): Result<List<SurveyFormResponse>>

suspend fun deleteSurveyForm(surveyFormId: String): Result<Unit>

suspend fun updateSurveyForm(surveyFormRequest: SurveyFormRequest): Result<Unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ class SurveyFormDataSourceImpl @Inject constructor(
result
}

override suspend fun getSurveyFormList(eventId: String): Result<List<SurveyFormResponse>> =
runCatching {
val result: MutableList<SurveyFormResponse> = mutableListOf()

val task = firebaseFirestore.collection(SURVEY_FORM_COLLECTION)
.whereEqualTo("eventId", eventId)
.get()
.await()

for (document in task.documents) {
val surveyFormResponse = document.toObject(SurveyFormResponse::class.java)
checkNotNull(surveyFormResponse)

result.add(surveyFormResponse)
}

result
}

override suspend fun deleteSurveyForm(surveyFormId: String): Result<Unit> = runCatching {
firebaseFirestore.collection(SURVEY_FORM_COLLECTION)
.document(surveyFormId)
Expand Down

0 comments on commit 2e12230

Please sign in to comment.