From 622c893a8491309ccc91e4cd78c9f90eb0029626 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 14:19:41 +0900 Subject: [PATCH 01/22] =?UTF-8?q?[REFACTOR]=20#65=20:=20SurveyFormDataSour?= =?UTF-8?q?ce=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20=EC=84=A4=EB=AC=B8?= =?UTF-8?q?=EC=A1=B0=EC=82=AC=20=ED=98=95=EC=8B=9D=20=ED=8F=BC=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EB=B0=8F=20=EB=B6=88=EB=9F=AC=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=AA=A8=EB=91=90=20Migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wap/wapp/core/network/di/NetworkModule.kt | 8 +++ .../source/management/ManagementDataSource.kt | 4 -- .../management/ManagementDataSourceImpl.kt | 15 ----- .../network/source/survey/SurveyDataSource.kt | 6 +- .../source/survey/SurveyDataSourceImpl.kt | 37 ++++-------- .../source/survey/SurveyFormDataSource.kt | 12 ++++ .../source/survey/SurveyFormDataSourceImpl.kt | 57 +++++++++++++++++++ 7 files changed, 89 insertions(+), 50 deletions(-) create mode 100644 core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSource.kt create mode 100644 core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSourceImpl.kt diff --git a/core/network/src/main/java/com/wap/wapp/core/network/di/NetworkModule.kt b/core/network/src/main/java/com/wap/wapp/core/network/di/NetworkModule.kt index a0907b9b..7fc8605e 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/di/NetworkModule.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/di/NetworkModule.kt @@ -6,6 +6,8 @@ import com.wap.wapp.core.network.source.management.ManagementDataSource import com.wap.wapp.core.network.source.management.ManagementDataSourceImpl import com.wap.wapp.core.network.source.survey.SurveyDataSource import com.wap.wapp.core.network.source.survey.SurveyDataSourceImpl +import com.wap.wapp.core.network.source.survey.SurveyFormDataSource +import com.wap.wapp.core.network.source.survey.SurveyFormDataSourceImpl import com.wap.wapp.core.network.source.user.UserDataSource import com.wap.wapp.core.network.source.user.UserDataSourceImpl import dagger.Binds @@ -36,6 +38,12 @@ abstract class NetworkModule { surveyDataSourceImpl: SurveyDataSourceImpl, ): SurveyDataSource + @Binds + @Singleton + abstract fun bindsSurveyFormDateSource( + surveyFormDataSourceImpl: SurveyFormDataSourceImpl + ): SurveyFormDataSource + @Binds @Singleton abstract fun bindsEventDataSource( diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/management/ManagementDataSource.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/management/ManagementDataSource.kt index 7025d728..20a26f06 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/source/management/ManagementDataSource.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/management/ManagementDataSource.kt @@ -1,13 +1,9 @@ package com.wap.wapp.core.network.source.management -import com.wap.wapp.core.network.model.management.SurveyFormRequest - interface ManagementDataSource { suspend fun getManager(userId: String): Result suspend fun postManager(userId: String): Result suspend fun getManagementCode(code: String): Result - - suspend fun postSurveyForm(surveyFormRequest: SurveyFormRequest, eventId: Int): Result } diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/management/ManagementDataSourceImpl.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/management/ManagementDataSourceImpl.kt index a1aadd15..adbcb187 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/source/management/ManagementDataSourceImpl.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/management/ManagementDataSourceImpl.kt @@ -4,8 +4,6 @@ import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.SetOptions import com.wap.wapp.core.network.constant.CODES_COLLECTION import com.wap.wapp.core.network.constant.MANAGER_COLLECTION -import com.wap.wapp.core.network.constant.SURVEY_FORM_COLLECTION -import com.wap.wapp.core.network.model.management.SurveyFormRequest import com.wap.wapp.core.network.utils.await import javax.inject.Inject @@ -45,17 +43,4 @@ class ManagementDataSourceImpl @Inject constructor( result.isEmpty.not() } } - - override suspend fun postSurveyForm( - surveyFormRequest: SurveyFormRequest, - eventId: Int, - ): Result { - return runCatching { - val setOption = SetOptions.merge() - firebaseFirestore.collection(SURVEY_FORM_COLLECTION) - .document(eventId.toString()) - .set(surveyFormRequest, setOption) - .await() - } - } } diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSource.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSource.kt index c8f1bc10..b904467c 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSource.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSource.kt @@ -1,6 +1,6 @@ package com.wap.wapp.core.network.source.survey -import com.wap.wapp.core.network.model.survey.SurveyFormResponse +import com.wap.wapp.core.model.survey.Survey import com.wap.wapp.core.network.model.survey.SurveyResponse interface SurveyDataSource { @@ -8,7 +8,5 @@ interface SurveyDataSource { suspend fun getSurvey(surveyId: String): Result - suspend fun getSurveyFormList(): Result> - - suspend fun getSurveyForm(eventId: Int): Result + suspend fun postSurvey(survey: Survey): Result } diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSourceImpl.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSourceImpl.kt index 40e1cdaf..a7706b5f 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSourceImpl.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSourceImpl.kt @@ -1,9 +1,9 @@ package com.wap.wapp.core.network.source.survey import com.google.firebase.firestore.FirebaseFirestore +import com.google.firebase.firestore.SetOptions +import com.wap.wapp.core.model.survey.Survey import com.wap.wapp.core.network.constant.SURVEY_COLLECTION -import com.wap.wapp.core.network.constant.SURVEY_FORM_COLLECTION -import com.wap.wapp.core.network.model.survey.SurveyFormResponse import com.wap.wapp.core.network.model.survey.SurveyResponse import com.wap.wapp.core.network.utils.await import javax.inject.Inject @@ -42,34 +42,17 @@ class SurveyDataSourceImpl @Inject constructor( } } - override suspend fun getSurveyFormList(): Result> { + override suspend fun postSurvey(survey: Survey): Result { return runCatching { - val result: MutableList = mutableListOf() + val setOption = SetOptions.merge() + val documentId = firebaseFirestore.collection(SURVEY_COLLECTION) + .document() + .id - val task = firebaseFirestore.collection(SURVEY_FORM_COLLECTION) - .get() - .await() - - for (document in task.documents) { - val surveyFormResponse = document.toObject(SurveyFormResponse::class.java) - checkNotNull(surveyFormResponse) - - result.add(surveyFormResponse) - } - - result - } - } - - override suspend fun getSurveyForm(eventId: Int): Result { - return runCatching { - val result = firebaseFirestore.collection(SURVEY_FORM_COLLECTION) - .document(eventId.toString()) - .get() + val result = firebaseFirestore.collection(SURVEY_COLLECTION) + .document(documentId) + .set(survey, setOption) .await() - - val surveyFormResponse = result.toObject(SurveyFormResponse::class.java) - checkNotNull(surveyFormResponse) } } } diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSource.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSource.kt new file mode 100644 index 00000000..0d51792b --- /dev/null +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSource.kt @@ -0,0 +1,12 @@ +package com.wap.wapp.core.network.source.survey + +import com.wap.wapp.core.network.model.management.SurveyFormRequest +import com.wap.wapp.core.network.model.survey.SurveyFormResponse + +interface SurveyFormDataSource { + suspend fun postSurveyForm(surveyFormRequest: SurveyFormRequest, eventId: Int): Result + + suspend fun getSurveyForm(eventId: Int): Result + + suspend fun getSurveyFormList(): Result> +} diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSourceImpl.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSourceImpl.kt new file mode 100644 index 00000000..455bf669 --- /dev/null +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSourceImpl.kt @@ -0,0 +1,57 @@ +package com.wap.wapp.core.network.source.survey + +import com.google.firebase.firestore.FirebaseFirestore +import com.google.firebase.firestore.SetOptions +import com.wap.wapp.core.network.constant.SURVEY_FORM_COLLECTION +import com.wap.wapp.core.network.model.management.SurveyFormRequest +import com.wap.wapp.core.network.model.survey.SurveyFormResponse +import com.wap.wapp.core.network.utils.await +import javax.inject.Inject + +class SurveyFormDataSourceImpl @Inject constructor( + private val firebaseFirestore: FirebaseFirestore +): SurveyFormDataSource { + override suspend fun getSurveyForm(eventId: Int): Result { + return runCatching { + val result = firebaseFirestore.collection(SURVEY_FORM_COLLECTION) + .document(eventId.toString()) + .get() + .await() + + val surveyFormResponse = result.toObject(SurveyFormResponse::class.java) + checkNotNull(surveyFormResponse) + } + } + + override suspend fun getSurveyFormList(): Result> { + return runCatching { + val result: MutableList = mutableListOf() + + val task = firebaseFirestore.collection(SURVEY_FORM_COLLECTION) + .get() + .await() + + for (document in task.documents) { + val surveyFormResponse = document.toObject(SurveyFormResponse::class.java) + checkNotNull(surveyFormResponse) + + result.add(surveyFormResponse) + } + + result + } + } + + override suspend fun postSurveyForm( + surveyFormRequest: SurveyFormRequest, + eventId: Int, + ): Result { + return runCatching { + val setOption = SetOptions.merge() + firebaseFirestore.collection(SURVEY_FORM_COLLECTION) + .document(eventId.toString()) + .set(surveyFormRequest, setOption) + .await() + } + } +} From 6b720a2bfaaf94cfd63b788a1c4cf69ad77ee0e4 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 14:20:05 +0900 Subject: [PATCH 02/22] =?UTF-8?q?[REFACTOR]=20#65=20:=20SurveyFormReposito?= =?UTF-8?q?ry=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20=EC=84=A4=EB=AC=B8?= =?UTF-8?q?=EC=A1=B0=EC=82=AC=20=ED=98=95=EC=8B=9D=20=ED=8F=BC=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EB=B0=8F=20=EB=B6=88=EB=9F=AC=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20Migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/wap/wapp/core/data/di/DataModule.kt | 8 ++++ .../management/ManagementRepository.kt | 4 -- .../management/ManagementRepositoryImpl.kt | 16 -------- .../repository/survey/SurveyFormRepository.kt | 11 ++++++ .../survey/SurveyFormRepositoryImpl.kt | 38 +++++++++++++++++++ .../repository/survey/SurveyRepository.kt | 4 -- .../repository/survey/SurveyRepositoryImpl.kt | 15 -------- 7 files changed, 57 insertions(+), 39 deletions(-) create mode 100644 core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepository.kt create mode 100644 core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepositoryImpl.kt diff --git a/core/data/src/main/java/com/wap/wapp/core/data/di/DataModule.kt b/core/data/src/main/java/com/wap/wapp/core/data/di/DataModule.kt index 22d5897c..1eb5886e 100644 --- a/core/data/src/main/java/com/wap/wapp/core/data/di/DataModule.kt +++ b/core/data/src/main/java/com/wap/wapp/core/data/di/DataModule.kt @@ -4,6 +4,8 @@ import com.wap.wapp.core.data.repository.event.EventRepository import com.wap.wapp.core.data.repository.event.EventRepositoryImpl import com.wap.wapp.core.data.repository.management.ManagementRepository import com.wap.wapp.core.data.repository.management.ManagementRepositoryImpl +import com.wap.wapp.core.data.repository.survey.SurveyFormRepository +import com.wap.wapp.core.data.repository.survey.SurveyFormRepositoryImpl import com.wap.wapp.core.data.repository.survey.SurveyRepository import com.wap.wapp.core.data.repository.survey.SurveyRepositoryImpl import com.wap.wapp.core.data.repository.user.UserRepository @@ -35,6 +37,12 @@ abstract class DataModule { surveyRepositoryImpl: SurveyRepositoryImpl, ): SurveyRepository + @Binds + @Singleton + abstract fun bindsSurveyFormRepository( + surveyFormRepositoryImpl: SurveyFormRepositoryImpl + ): SurveyFormRepository + @Binds @Singleton abstract fun bindsEventRepository( diff --git a/core/data/src/main/java/com/wap/wapp/core/data/repository/management/ManagementRepository.kt b/core/data/src/main/java/com/wap/wapp/core/data/repository/management/ManagementRepository.kt index 65be86ef..9092de50 100644 --- a/core/data/src/main/java/com/wap/wapp/core/data/repository/management/ManagementRepository.kt +++ b/core/data/src/main/java/com/wap/wapp/core/data/repository/management/ManagementRepository.kt @@ -1,13 +1,9 @@ package com.wap.wapp.core.data.repository.management -import com.wap.wapp.core.model.survey.SurveyForm - interface ManagementRepository { suspend fun getManager(userId: String): Result suspend fun postManager(userId: String): Result suspend fun getManagementCode(code: String): Result - - suspend fun postSurveyForm(surveyForm: SurveyForm): Result } diff --git a/core/data/src/main/java/com/wap/wapp/core/data/repository/management/ManagementRepositoryImpl.kt b/core/data/src/main/java/com/wap/wapp/core/data/repository/management/ManagementRepositoryImpl.kt index 9d74961d..ee000570 100644 --- a/core/data/src/main/java/com/wap/wapp/core/data/repository/management/ManagementRepositoryImpl.kt +++ b/core/data/src/main/java/com/wap/wapp/core/data/repository/management/ManagementRepositoryImpl.kt @@ -1,9 +1,6 @@ package com.wap.wapp.core.data.repository.management -import com.wap.wapp.core.model.survey.SurveyForm -import com.wap.wapp.core.network.model.management.SurveyFormRequest import com.wap.wapp.core.network.source.management.ManagementDataSource -import java.time.format.DateTimeFormatter import javax.inject.Inject class ManagementRepositoryImpl @Inject constructor( @@ -20,17 +17,4 @@ class ManagementRepositoryImpl @Inject constructor( override suspend fun getManagementCode(code: String): Result { return managementDataSource.getManagementCode(code) } - - override suspend fun postSurveyForm(surveyForm: SurveyForm): Result { - return managementDataSource.postSurveyForm( - surveyFormRequest = SurveyFormRequest( - eventId = surveyForm.eventId, - title = surveyForm.title, - content = surveyForm.content, - surveyQuestionList = surveyForm.surveyQuestionList, - deadline = surveyForm.deadline.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME), - ), - eventId = surveyForm.eventId, - ) - } } diff --git a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepository.kt b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepository.kt new file mode 100644 index 00000000..1713a6f1 --- /dev/null +++ b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepository.kt @@ -0,0 +1,11 @@ +package com.wap.wapp.core.data.repository.survey + +import com.wap.wapp.core.model.survey.SurveyForm + +interface SurveyFormRepository { + suspend fun getSurveyForm(eventId: Int): Result + + suspend fun getSurveyFormList(): Result> + + suspend fun postSurveyForm(surveyForm: SurveyForm): Result +} diff --git a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepositoryImpl.kt b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepositoryImpl.kt new file mode 100644 index 00000000..7257870a --- /dev/null +++ b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepositoryImpl.kt @@ -0,0 +1,38 @@ +package com.wap.wapp.core.data.repository.survey + +import com.wap.wapp.core.model.survey.SurveyForm +import com.wap.wapp.core.network.model.management.SurveyFormRequest +import com.wap.wapp.core.network.source.survey.SurveyFormDataSource +import java.time.format.DateTimeFormatter +import javax.inject.Inject + +class SurveyFormRepositoryImpl @Inject constructor( + private val surveyFormDataSource: SurveyFormDataSource +): SurveyFormRepository { + override suspend fun getSurveyForm(eventId: Int): Result { + return surveyFormDataSource.getSurveyForm(eventId).mapCatching { surveyFormResponse -> + surveyFormResponse.toDomain() + } + } + + override suspend fun getSurveyFormList(): Result> { + return surveyFormDataSource.getSurveyFormList().mapCatching { surveyFormResponseList -> + surveyFormResponseList.map { surveyFormResponse -> + surveyFormResponse.toDomain() + } + } + } + + override suspend fun postSurveyForm(surveyForm: SurveyForm): Result { + return surveyFormDataSource.postSurveyForm( + surveyFormRequest = SurveyFormRequest( + eventId = surveyForm.eventId, + title = surveyForm.title, + content = surveyForm.content, + surveyQuestionList = surveyForm.surveyQuestionList, + deadline = surveyForm.deadline.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME), + ), + eventId = surveyForm.eventId, + ) + } +} diff --git a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepository.kt b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepository.kt index 73f3511f..3e643ceb 100644 --- a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepository.kt +++ b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepository.kt @@ -7,8 +7,4 @@ interface SurveyRepository { suspend fun getSurveyList(): Result> suspend fun getSurvey(surveyId: String): Result - - suspend fun getSurveyFormList(): Result> - - suspend fun getSurveyForm(eventId: Int): Result } diff --git a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepositoryImpl.kt b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepositoryImpl.kt index e0baa14b..5410d3b8 100644 --- a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepositoryImpl.kt +++ b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepositoryImpl.kt @@ -1,7 +1,6 @@ package com.wap.wapp.core.data.repository.survey import com.wap.wapp.core.model.survey.Survey -import com.wap.wapp.core.model.survey.SurveyForm import com.wap.wapp.core.network.source.survey.SurveyDataSource import com.wap.wapp.core.network.source.user.UserDataSource import javax.inject.Inject @@ -46,18 +45,4 @@ class SurveyRepositoryImpl @Inject constructor( // TODO 도메인 모델 구현을 위한 익스텐션, notice DataSource 구현 후 소거 private fun String.toDomain(): String = this - - override suspend fun getSurveyFormList(): Result> { - return surveyDataSource.getSurveyFormList().mapCatching { surveyFormResponseList -> - surveyFormResponseList.map { surveyFormResponse -> - surveyFormResponse.toDomain() - } - } - } - - override suspend fun getSurveyForm(eventId: Int): Result { - return surveyDataSource.getSurveyForm(eventId).mapCatching { surveyFormResponse -> - surveyFormResponse.toDomain() - } - } } From 2f5aaedf10f4928d3a08c7876921e32e01a8c11c Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 14:20:33 +0900 Subject: [PATCH 03/22] =?UTF-8?q?[CHORE]=20#65=20:=20managementRepository,?= =?UTF-8?q?=20surveyRepository=20->=20surveyFormRepository=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/domain/usecase/management/RegisterSurveyUseCase.kt | 6 +++--- .../core/domain/usecase/survey/GetSurveyFormListUseCase.kt | 6 +++--- .../wapp/core/domain/usecase/survey/GetSurveyFormUseCase.kt | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/management/RegisterSurveyUseCase.kt b/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/management/RegisterSurveyUseCase.kt index 4c996f84..de3693f1 100644 --- a/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/management/RegisterSurveyUseCase.kt +++ b/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/management/RegisterSurveyUseCase.kt @@ -1,6 +1,6 @@ package com.wap.wapp.core.domain.usecase.management -import com.wap.wapp.core.data.repository.management.ManagementRepository +import com.wap.wapp.core.data.repository.survey.SurveyFormRepository import com.wap.wapp.core.model.event.Event import com.wap.wapp.core.model.survey.SurveyForm import com.wap.wapp.core.model.survey.SurveyQuestion @@ -10,7 +10,7 @@ import java.time.LocalTime import javax.inject.Inject class RegisterSurveyUseCase @Inject constructor( - private val managementRepository: ManagementRepository, + private val surveyFormRepository: SurveyFormRepository, ) { suspend operator fun invoke( event: Event, @@ -21,7 +21,7 @@ class RegisterSurveyUseCase @Inject constructor( deadlineTime: LocalTime, ): Result { return runCatching { - managementRepository.postSurveyForm( + surveyFormRepository.postSurveyForm( SurveyForm( eventId = event.eventId, title = title, diff --git a/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/GetSurveyFormListUseCase.kt b/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/GetSurveyFormListUseCase.kt index 57ffb33d..a65c2bc2 100644 --- a/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/GetSurveyFormListUseCase.kt +++ b/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/GetSurveyFormListUseCase.kt @@ -1,10 +1,10 @@ package com.wap.wapp.core.domain.usecase.survey -import com.wap.wapp.core.data.repository.survey.SurveyRepository +import com.wap.wapp.core.data.repository.survey.SurveyFormRepository import javax.inject.Inject class GetSurveyFormListUseCase @Inject constructor( - private val surveyRepository: SurveyRepository, + private val surveyFormRepository: SurveyFormRepository, ) { - suspend operator fun invoke() = surveyRepository.getSurveyFormList() + suspend operator fun invoke() = surveyFormRepository.getSurveyFormList() } diff --git a/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/GetSurveyFormUseCase.kt b/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/GetSurveyFormUseCase.kt index 82616de8..b8075928 100644 --- a/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/GetSurveyFormUseCase.kt +++ b/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/GetSurveyFormUseCase.kt @@ -1,10 +1,10 @@ package com.wap.wapp.core.domain.usecase.survey -import com.wap.wapp.core.data.repository.survey.SurveyRepository +import com.wap.wapp.core.data.repository.survey.SurveyFormRepository import javax.inject.Inject class GetSurveyFormUseCase @Inject constructor( - private val surveyRepository: SurveyRepository, + private val surveyFormRepository: SurveyFormRepository, ) { - suspend operator fun invoke(eventId: Int) = surveyRepository.getSurveyForm(eventId) + suspend operator fun invoke(eventId: Int) = surveyFormRepository.getSurveyForm(eventId) } From e26381ad1aab64f4b2a876459f66bd1e10c49b6e Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 16:21:35 +0900 Subject: [PATCH 04/22] [CHORE] #65 : surveyForm network model move to survey/form --- .../repository/survey/SurveyFormRepositoryImpl.kt | 7 +++---- .../{management => survey/form}/SurveyFormRequest.kt | 2 +- .../model/survey/{ => form}/SurveyFormResponse.kt | 2 +- .../model/survey/{ => form}/SurveyQuestionResponse.kt | 4 +++- .../network/source/survey/SurveyFormDataSource.kt | 6 +++--- .../network/source/survey/SurveyFormDataSourceImpl.kt | 11 +++++------ 6 files changed, 16 insertions(+), 16 deletions(-) rename core/network/src/main/java/com/wap/wapp/core/network/model/{management => survey/form}/SurveyFormRequest.kt (86%) rename core/network/src/main/java/com/wap/wapp/core/network/model/survey/{ => form}/SurveyFormResponse.kt (93%) rename core/network/src/main/java/com/wap/wapp/core/network/model/survey/{ => form}/SurveyQuestionResponse.kt (68%) diff --git a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepositoryImpl.kt b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepositoryImpl.kt index 7257870a..6d0d5d8a 100644 --- a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepositoryImpl.kt +++ b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepositoryImpl.kt @@ -1,14 +1,14 @@ package com.wap.wapp.core.data.repository.survey import com.wap.wapp.core.model.survey.SurveyForm -import com.wap.wapp.core.network.model.management.SurveyFormRequest +import com.wap.wapp.core.network.model.survey.form.SurveyFormRequest import com.wap.wapp.core.network.source.survey.SurveyFormDataSource import java.time.format.DateTimeFormatter import javax.inject.Inject class SurveyFormRepositoryImpl @Inject constructor( - private val surveyFormDataSource: SurveyFormDataSource -): SurveyFormRepository { + private val surveyFormDataSource: SurveyFormDataSource, +) : SurveyFormRepository { override suspend fun getSurveyForm(eventId: Int): Result { return surveyFormDataSource.getSurveyForm(eventId).mapCatching { surveyFormResponse -> surveyFormResponse.toDomain() @@ -32,7 +32,6 @@ class SurveyFormRepositoryImpl @Inject constructor( surveyQuestionList = surveyForm.surveyQuestionList, deadline = surveyForm.deadline.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME), ), - eventId = surveyForm.eventId, ) } } diff --git a/core/network/src/main/java/com/wap/wapp/core/network/model/management/SurveyFormRequest.kt b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyFormRequest.kt similarity index 86% rename from core/network/src/main/java/com/wap/wapp/core/network/model/management/SurveyFormRequest.kt rename to core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyFormRequest.kt index 71c6fab3..864e7444 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/model/management/SurveyFormRequest.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyFormRequest.kt @@ -1,4 +1,4 @@ -package com.wap.wapp.core.network.model.management +package com.wap.wapp.core.network.model.survey.form import com.wap.wapp.core.model.survey.SurveyQuestion diff --git a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyFormResponse.kt b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyFormResponse.kt similarity index 93% rename from core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyFormResponse.kt rename to core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyFormResponse.kt index 1efe9df0..46befb9f 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyFormResponse.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyFormResponse.kt @@ -1,4 +1,4 @@ -package com.wap.wapp.core.network.model.survey +package com.wap.wapp.core.network.model.survey.form import com.wap.wapp.core.model.survey.SurveyForm import java.time.LocalDateTime diff --git a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyQuestionResponse.kt b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyQuestionResponse.kt similarity index 68% rename from core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyQuestionResponse.kt rename to core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyQuestionResponse.kt index 00b1a3bf..c919e8ab 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyQuestionResponse.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyQuestionResponse.kt @@ -1,6 +1,8 @@ -package com.wap.wapp.core.network.model.survey +package com.wap.wapp.core.network.model.survey.form import com.wap.wapp.core.model.survey.SurveyQuestion +import com.wap.wapp.core.network.model.survey.QuestionTypeResponse +import com.wap.wapp.core.network.model.survey.toDomain data class SurveyQuestionResponse( val questionTitle: String, diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSource.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSource.kt index 0d51792b..ea76918f 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSource.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSource.kt @@ -1,10 +1,10 @@ package com.wap.wapp.core.network.source.survey -import com.wap.wapp.core.network.model.management.SurveyFormRequest -import com.wap.wapp.core.network.model.survey.SurveyFormResponse +import com.wap.wapp.core.network.model.survey.form.SurveyFormRequest +import com.wap.wapp.core.network.model.survey.form.SurveyFormResponse interface SurveyFormDataSource { - suspend fun postSurveyForm(surveyFormRequest: SurveyFormRequest, eventId: Int): Result + suspend fun postSurveyForm(surveyFormRequest: SurveyFormRequest): Result suspend fun getSurveyForm(eventId: Int): Result diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSourceImpl.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSourceImpl.kt index 455bf669..6d11af78 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSourceImpl.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyFormDataSourceImpl.kt @@ -3,14 +3,14 @@ package com.wap.wapp.core.network.source.survey import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.SetOptions import com.wap.wapp.core.network.constant.SURVEY_FORM_COLLECTION -import com.wap.wapp.core.network.model.management.SurveyFormRequest -import com.wap.wapp.core.network.model.survey.SurveyFormResponse +import com.wap.wapp.core.network.model.survey.form.SurveyFormRequest +import com.wap.wapp.core.network.model.survey.form.SurveyFormResponse import com.wap.wapp.core.network.utils.await import javax.inject.Inject class SurveyFormDataSourceImpl @Inject constructor( - private val firebaseFirestore: FirebaseFirestore -): SurveyFormDataSource { + private val firebaseFirestore: FirebaseFirestore, +) : SurveyFormDataSource { override suspend fun getSurveyForm(eventId: Int): Result { return runCatching { val result = firebaseFirestore.collection(SURVEY_FORM_COLLECTION) @@ -44,12 +44,11 @@ class SurveyFormDataSourceImpl @Inject constructor( override suspend fun postSurveyForm( surveyFormRequest: SurveyFormRequest, - eventId: Int, ): Result { return runCatching { val setOption = SetOptions.merge() firebaseFirestore.collection(SURVEY_FORM_COLLECTION) - .document(eventId.toString()) + .document(surveyFormRequest.eventId.toString()) .set(surveyFormRequest, setOption) .await() } From 2786891c13006a8784f06b56ee7d09f3f2f656a0 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 16:22:55 +0900 Subject: [PATCH 05/22] [CHORE] #65 : surveyResponse field answerList to surveyAnswerList --- .../main/java/com/wap/wapp/core/model/survey/Survey.kt | 2 +- .../wap/wapp/core/network/model/survey/SurveyResponse.kt | 8 ++++---- .../wapp/feature/management/ManagementSurveyContent.kt | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/model/src/main/java/com/wap/wapp/core/model/survey/Survey.kt b/core/model/src/main/java/com/wap/wapp/core/model/survey/Survey.kt index c490ec6f..3ba1986b 100644 --- a/core/model/src/main/java/com/wap/wapp/core/model/survey/Survey.kt +++ b/core/model/src/main/java/com/wap/wapp/core/model/survey/Survey.kt @@ -12,6 +12,6 @@ data class Survey( val userName: String, val title: String, val content: String, - val answerList: List, + val surveyAnswerList: List, val surveyedAt: LocalDateTime, ) diff --git a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyResponse.kt b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyResponse.kt index 54bf5180..c65b0def 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyResponse.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyResponse.kt @@ -6,16 +6,16 @@ import java.time.format.DateTimeFormatter data class SurveyResponse( val surveyId: String, - val eventId: String, + val eventId: Int, val userId: String, val title: String, val content: String, - val answerList: List, + val surveyAnswerList: List, val surveyedAt: String, ) { constructor() : this( "", - "", + -1, "", "", "", @@ -29,7 +29,7 @@ data class SurveyResponse( userName = userName, title = this.title, content = this.content, - answerList = this.answerList.map { answer -> answer.toDomain() }, + surveyAnswerList = this.surveyAnswerList.map { answer -> answer.toDomain() }, surveyedAt = LocalDateTime.parse( this.surveyedAt, DateTimeFormatter.ISO_LOCAL_DATE_TIME, diff --git a/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementSurveyContent.kt b/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementSurveyContent.kt index 07e21960..adaa5d62 100644 --- a/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementSurveyContent.kt +++ b/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementSurveyContent.kt @@ -100,7 +100,7 @@ private fun ManagementSurveyItem( horizontalAlignment = Alignment.CenterHorizontally, ) { Text( - text = item.answerList.first().questionAnswer, + text = item.surveyAnswerList.first().questionAnswer, style = WappTheme.typography.contentMedium, color = WappTheme.colors.white, maxLines = 1, From 2a42c2eedb227839b0329e863203771c1240fb0c Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 16:26:35 +0900 Subject: [PATCH 06/22] =?UTF-8?q?[FEATURE]=20#65=20:=20Survey=20DTO=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wapp/core/network/model/survey/SurveyRequest.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyRequest.kt diff --git a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyRequest.kt b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyRequest.kt new file mode 100644 index 00000000..3e6bff84 --- /dev/null +++ b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyRequest.kt @@ -0,0 +1,13 @@ +package com.wap.wapp.core.network.model.survey + +import com.wap.wapp.core.model.survey.SurveyAnswer + +data class SurveyRequest( + val surveyId: String, + val eventId: Int, + val userId: String, + val title: String, + val content: String, + val surveyAnswerList: List, + val surveyedAt: String, +) From 826ee5f692b379a6ba6082e7896e2214fc79c48e Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 16:27:16 +0900 Subject: [PATCH 07/22] =?UTF-8?q?[FEATURE]=20#65=20:=20SurveyDataSource=20?= =?UTF-8?q?=EC=84=A4=EB=AC=B8=20=EC=A1=B0=EC=82=AC=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wap/wapp/core/network/di/NetworkModule.kt | 2 +- .../network/source/survey/SurveyDataSource.kt | 11 +++++-- .../source/survey/SurveyDataSourceImpl.kt | 30 ++++++++++++++----- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/core/network/src/main/java/com/wap/wapp/core/network/di/NetworkModule.kt b/core/network/src/main/java/com/wap/wapp/core/network/di/NetworkModule.kt index 7fc8605e..d31841db 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/di/NetworkModule.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/di/NetworkModule.kt @@ -41,7 +41,7 @@ abstract class NetworkModule { @Binds @Singleton abstract fun bindsSurveyFormDateSource( - surveyFormDataSourceImpl: SurveyFormDataSourceImpl + surveyFormDataSourceImpl: SurveyFormDataSourceImpl, ): SurveyFormDataSource @Binds diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSource.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSource.kt index b904467c..36644e12 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSource.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSource.kt @@ -1,6 +1,6 @@ package com.wap.wapp.core.network.source.survey -import com.wap.wapp.core.model.survey.Survey +import com.wap.wapp.core.model.survey.SurveyAnswer import com.wap.wapp.core.network.model.survey.SurveyResponse interface SurveyDataSource { @@ -8,5 +8,12 @@ interface SurveyDataSource { suspend fun getSurvey(surveyId: String): Result - suspend fun postSurvey(survey: Survey): Result + suspend fun postSurvey( + eventId: Int, + userId: String, + title: String, + content: String, + surveyAnswerList: List, + surveyedAt: String, + ): Result } diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSourceImpl.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSourceImpl.kt index a7706b5f..c393509b 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSourceImpl.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSourceImpl.kt @@ -2,8 +2,9 @@ package com.wap.wapp.core.network.source.survey import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.SetOptions -import com.wap.wapp.core.model.survey.Survey +import com.wap.wapp.core.model.survey.SurveyAnswer import com.wap.wapp.core.network.constant.SURVEY_COLLECTION +import com.wap.wapp.core.network.model.survey.SurveyRequest import com.wap.wapp.core.network.model.survey.SurveyResponse import com.wap.wapp.core.network.utils.await import javax.inject.Inject @@ -42,16 +43,31 @@ class SurveyDataSourceImpl @Inject constructor( } } - override suspend fun postSurvey(survey: Survey): Result { + override suspend fun postSurvey( + eventId: Int, + userId: String, + title: String, + content: String, + surveyAnswerList: List, + surveyedAt: String, + ): Result { return runCatching { + val documentId = firebaseFirestore.collection(SURVEY_COLLECTION).document().id + + val surveyRequest = SurveyRequest( + surveyId = documentId, + eventId = eventId, + userId = userId, + title = title, + content = content, + surveyAnswerList = surveyAnswerList, + surveyedAt = surveyedAt, + ) val setOption = SetOptions.merge() - val documentId = firebaseFirestore.collection(SURVEY_COLLECTION) - .document() - .id - val result = firebaseFirestore.collection(SURVEY_COLLECTION) + firebaseFirestore.collection(SURVEY_COLLECTION) .document(documentId) - .set(survey, setOption) + .set(surveyRequest, setOption) .await() } } From 7cd3aab1f96cbad13c556f29ae200b04f879ae12 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 16:27:46 +0900 Subject: [PATCH 08/22] =?UTF-8?q?[FEATURE]=20#65=20:=20SurveyDataRepositor?= =?UTF-8?q?y=20=EC=84=A4=EB=AC=B8=20=EC=A1=B0=EC=82=AC=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EB=AA=A8=EB=8D=B8=20DTO=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/wap/wapp/core/data/di/DataModule.kt | 2 +- .../repository/survey/SurveyRepository.kt | 12 ++++++++++- .../repository/survey/SurveyRepositoryImpl.kt | 21 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/core/data/src/main/java/com/wap/wapp/core/data/di/DataModule.kt b/core/data/src/main/java/com/wap/wapp/core/data/di/DataModule.kt index 1eb5886e..24325672 100644 --- a/core/data/src/main/java/com/wap/wapp/core/data/di/DataModule.kt +++ b/core/data/src/main/java/com/wap/wapp/core/data/di/DataModule.kt @@ -40,7 +40,7 @@ abstract class DataModule { @Binds @Singleton abstract fun bindsSurveyFormRepository( - surveyFormRepositoryImpl: SurveyFormRepositoryImpl + surveyFormRepositoryImpl: SurveyFormRepositoryImpl, ): SurveyFormRepository @Binds diff --git a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepository.kt b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepository.kt index 3e643ceb..25da4b2c 100644 --- a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepository.kt +++ b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepository.kt @@ -1,10 +1,20 @@ package com.wap.wapp.core.data.repository.survey import com.wap.wapp.core.model.survey.Survey -import com.wap.wapp.core.model.survey.SurveyForm +import com.wap.wapp.core.model.survey.SurveyAnswer +import java.time.LocalDateTime interface SurveyRepository { suspend fun getSurveyList(): Result> suspend fun getSurvey(surveyId: String): Result + + suspend fun postSurvey( + eventId: Int, + userId: String, + title: String, + content: String, + surveyAnswerList: List, + surveyedAt: LocalDateTime, + ): Result } diff --git a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepositoryImpl.kt b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepositoryImpl.kt index 5410d3b8..808b2b4e 100644 --- a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepositoryImpl.kt +++ b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepositoryImpl.kt @@ -1,8 +1,11 @@ package com.wap.wapp.core.data.repository.survey import com.wap.wapp.core.model.survey.Survey +import com.wap.wapp.core.model.survey.SurveyAnswer import com.wap.wapp.core.network.source.survey.SurveyDataSource import com.wap.wapp.core.network.source.user.UserDataSource +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter import javax.inject.Inject class SurveyRepositoryImpl @Inject constructor( @@ -41,6 +44,24 @@ class SurveyRepositoryImpl @Inject constructor( } } + override suspend fun postSurvey( + eventId: Int, + userId: String, + title: String, + content: String, + surveyAnswerList: List, + surveyedAt: LocalDateTime, + ): Result { + return surveyDataSource.postSurvey( + eventId = eventId, + userId = userId, + title = title, + content = content, + surveyAnswerList = surveyAnswerList, + surveyedAt = surveyedAt.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME), + ) + } + private val noticeNameResponse: Result = Result.success("notice datasource dummy data") // TODO 도메인 모델 구현을 위한 익스텐션, notice DataSource 구현 후 소거 From bd8c446fd8bd9ab63250792a490f2ca4a9c3d060 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 16:28:15 +0900 Subject: [PATCH 09/22] =?UTF-8?q?[FEATURE]=20#65=20:=20=EC=84=A4=EB=AC=B8?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=20=EB=93=B1=EB=A1=9D=20=EC=9C=A0=EC=8A=A4?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/survey/PostSurveyUseCase.kt | 32 +++++++++++++++++++ .../survey/answer/SurveyAnswerViewModel.kt | 20 ++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/PostSurveyUseCase.kt diff --git a/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/PostSurveyUseCase.kt b/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/PostSurveyUseCase.kt new file mode 100644 index 00000000..9fa2a1dd --- /dev/null +++ b/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/PostSurveyUseCase.kt @@ -0,0 +1,32 @@ +package com.wap.wapp.core.domain.usecase.survey + +import com.wap.wapp.core.data.repository.survey.SurveyRepository +import com.wap.wapp.core.data.repository.user.UserRepository +import com.wap.wapp.core.model.survey.SurveyAnswer +import java.time.LocalDateTime +import javax.inject.Inject + +class PostSurveyUseCase @Inject constructor( + private val userRepository: UserRepository, + private val surveyRepository: SurveyRepository, +) { + suspend operator fun invoke( + eventId: Int, + title: String, + content: String, + surveyAnswerList: List, + ): Result { + return runCatching { + val userId = userRepository.getUserId().getOrThrow() + + surveyRepository.postSurvey( + userId = userId, + eventId = eventId, + title = title, + content = content, + surveyAnswerList = surveyAnswerList, + surveyedAt = LocalDateTime.now(), + ) + } + } +} diff --git a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerViewModel.kt b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerViewModel.kt index 0ff9897b..121ded8b 100644 --- a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerViewModel.kt +++ b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerViewModel.kt @@ -3,6 +3,7 @@ package com.wap.wapp.feature.survey.answer import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.wap.wapp.core.domain.usecase.survey.GetSurveyFormUseCase +import com.wap.wapp.core.domain.usecase.survey.PostSurveyUseCase import com.wap.wapp.core.model.survey.QuestionType import com.wap.wapp.core.model.survey.Rating import com.wap.wapp.core.model.survey.SurveyAnswer @@ -18,6 +19,7 @@ import javax.inject.Inject @HiltViewModel class SurveyAnswerViewModel @Inject constructor( private val getSurveyFormUseCase: GetSurveyFormUseCase, + private val postSurveyUseCase: PostSurveyUseCase, ) : ViewModel() { private val _surveyFormUiState: MutableStateFlow = MutableStateFlow(SurveyFormUiState.Init) @@ -85,9 +87,9 @@ class SurveyAnswerViewModel @Inject constructor( fun setNextQuestion() { val currentQuestionNumber = _questionNumber.value - val lastQuestionNumber = surveyAnswerList.value.size + val lastQuestionNumber = _surveyForm.value.surveyQuestionList.lastIndex - if(currentQuestionNumber == lastQuestionNumber) { // 마지막 질문일 경우 제출 + if (currentQuestionNumber == lastQuestionNumber) { // 마지막 질문일 경우 제출 submitSurvey() return } @@ -96,8 +98,20 @@ class SurveyAnswerViewModel @Inject constructor( } private fun submitSurvey() { - viewModelScope.launch { + val surveyForm = _surveyForm.value + val surveyAnswerList = surveyAnswerList.value + viewModelScope.launch { + postSurveyUseCase( + eventId = surveyForm.eventId, + title = surveyForm.title, + content = surveyForm.content, + surveyAnswerList = surveyAnswerList, + ).onSuccess { + _surveyAnswerEvent.emit(SurveyAnswerUiEvent.SubmitSuccess) + }.onFailure { throwable -> + _surveyAnswerEvent.emit(SurveyAnswerUiEvent.Failure(throwable)) + } } } From 944ad026a7c18b0a8eda207f21e43dfc9814c82b Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 16:28:43 +0900 Subject: [PATCH 10/22] =?UTF-8?q?[FEATURE]=20#65=20:=20=EC=84=A4=EB=AC=B8?= =?UTF-8?q?=20=ED=99=95=EC=9D=B8=20=ED=99=94=EB=A9=B4=20NavArgument=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../check/navigation/SurveyCheckNavigation.kt | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/feature/management/src/main/java/com/wap/wapp/feature/management/check/navigation/SurveyCheckNavigation.kt b/feature/management/src/main/java/com/wap/wapp/feature/management/check/navigation/SurveyCheckNavigation.kt index c5321a3e..acb764d3 100644 --- a/feature/management/src/main/java/com/wap/wapp/feature/management/check/navigation/SurveyCheckNavigation.kt +++ b/feature/management/src/main/java/com/wap/wapp/feature/management/check/navigation/SurveyCheckNavigation.kt @@ -3,22 +3,38 @@ package com.wap.wapp.feature.management.check.navigation import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.NavOptions +import androidx.navigation.NavType import androidx.navigation.compose.composable +import androidx.navigation.navArgument import androidx.navigation.navOptions import com.wap.wapp.feature.management.check.SurveyCheckRoute -const val surveyCheckNavigationRoute = "survey_check_route" - -fun NavController.navigateToSurveyCheck(navOptions: NavOptions? = navOptions {}) { - this.navigate(surveyCheckNavigationRoute, navOptions) +fun NavController.navigateToSurveyCheck( + surveyId: String, + navOptions: NavOptions? = navOptions {}, +) { + this.navigate("survey/check/$surveyId", navOptions) } fun NavGraphBuilder.surveyCheckScreen( navigateToManagement: () -> Unit, ) { - composable(route = surveyCheckNavigationRoute) { + composable( + route = SurveyCheckRoute.route, + arguments = listOf( + navArgument("surveyId") { + type = NavType.StringType + }, + ), + ) { navBackStackEntry -> + val surveyId = navBackStackEntry.arguments?.getString("surveyId") ?: "" SurveyCheckRoute( navigateToManagement = navigateToManagement, + surveyId = surveyId, ) } } + +object SurveyCheckRoute { + const val route = "survey/check/{surveyId}" +} From cfce195d0ff6ef4fa45e616810925358363f7686 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 16:29:15 +0900 Subject: [PATCH 11/22] =?UTF-8?q?[FEATURE]=20#65=20:=20=EC=84=A4=EB=AC=B8?= =?UTF-8?q?=20=ED=99=95=EC=9D=B8=20=ED=99=94=EB=A9=B4=20NavArgument=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wap/wapp/feature/management/check/SurveyCheckScreen.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feature/management/src/main/java/com/wap/wapp/feature/management/check/SurveyCheckScreen.kt b/feature/management/src/main/java/com/wap/wapp/feature/management/check/SurveyCheckScreen.kt index 83c20c7b..875c66e7 100644 --- a/feature/management/src/main/java/com/wap/wapp/feature/management/check/SurveyCheckScreen.kt +++ b/feature/management/src/main/java/com/wap/wapp/feature/management/check/SurveyCheckScreen.kt @@ -53,7 +53,7 @@ import kotlinx.coroutines.flow.collectLatest @Composable internal fun SurveyCheckRoute( viewModel: SurveyCheckViewModel = hiltViewModel(), - surveyId: String = "", + surveyId: String, navigateToManagement: () -> Unit, ) { val surveyUiState by viewModel.surveyUiState.collectAsStateWithLifecycle() @@ -143,7 +143,7 @@ internal fun SurveyCheckScreen( Column( verticalArrangement = Arrangement.spacedBy(32.dp), ) { - surveyUiState.survey.answerList.forEach { surveyAnswer -> + surveyUiState.survey.surveyAnswerList.forEach { surveyAnswer -> when (surveyAnswer.questionType) { QuestionType.OBJECTIVE -> { ObjectiveQuestionCard(surveyAnswer) From cf67be950f0a94b5f840eeb5fabd2c1bb5188efd Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 16:29:32 +0900 Subject: [PATCH 12/22] =?UTF-8?q?[FEATURE]=20#65=20:=20=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=ED=99=94=EB=A9=B4=EC=97=90=EC=84=9C=20=EC=84=A4=EB=AC=B8=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=ED=99=94=EB=A9=B4=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=84=ED=99=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt | 8 +++++--- .../com/wap/wapp/feature/management/ManagementScreen.kt | 7 ++++--- .../feature/management/navigation/ManagementNavigation.kt | 2 ++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt b/app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt index 7c8d57e0..c1a53be6 100644 --- a/app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt +++ b/app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt @@ -12,6 +12,7 @@ import com.wap.wapp.feature.auth.signin.navigation.navigateToSignIn import com.wap.wapp.feature.auth.signin.navigation.signInScreen import com.wap.wapp.feature.auth.signup.navigation.navigateToSignUp import com.wap.wapp.feature.auth.signup.navigation.signUpScreen +import com.wap.wapp.feature.management.check.navigation.navigateToSurveyCheck import com.wap.wapp.feature.management.check.navigation.surveyCheckScreen import com.wap.wapp.feature.management.navigation.managementScreen import com.wap.wapp.feature.management.navigation.navigateToManagement @@ -61,7 +62,7 @@ fun WappNavHost( ) noticeScreen() surveyNavGraph( - navigateToSurvey = navController::navigateToSurvey , + navigateToSurvey = navController::navigateToSurvey, navigateToSurveyAnswer = navController::navigateToSurveyAnswer, ) surveyCheckScreen( @@ -77,8 +78,9 @@ fun WappNavHost( navigateToProfileSetting = { navController.navigateToProfileSetting() }, ) managementScreen( - navigateToSurveyRegistration = { navController.navigateToSurveyRegistration() }, - navigateToEventRegistration = { navController.navigateToEventRegistration() }, + navigateToSurveyRegistration = navController::navigateToSurveyRegistration, + navigateToEventRegistration = navController::navigateToEventRegistration, + navigateToSurveyCheck = navController::navigateToSurveyCheck, ) } } diff --git a/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementScreen.kt b/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementScreen.kt index 3422085b..d59825d5 100644 --- a/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementScreen.kt +++ b/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementScreen.kt @@ -37,6 +37,7 @@ internal fun ManagementRoute( viewModel: ManagementViewModel = hiltViewModel(), navigateToEventRegistration: () -> Unit, navigateToSurveyRegistration: () -> Unit, + navigateToSurveyCheck: (String) -> Unit, ) { var isShowDialog by rememberSaveable { mutableStateOf(false) } val context = LocalContext.current @@ -46,7 +47,7 @@ internal fun ManagementRoute( viewModel = viewModel, navigateToEventRegistration = navigateToEventRegistration, navigateToSurveyRegistration = navigateToSurveyRegistration, - onCardClicked = {}, + navigateToSurveyCheck = navigateToSurveyCheck, ) if (isShowDialog) { @@ -70,7 +71,7 @@ internal fun ManagementScreen( viewModel: ManagementViewModel, navigateToEventRegistration: () -> Unit, navigateToSurveyRegistration: () -> Unit, - onCardClicked: (String) -> Unit, + navigateToSurveyCheck: (String) -> Unit, ) { val snackBarHostState = remember { SnackbarHostState() } val surveyList = viewModel.surveyList.collectAsState().value @@ -132,7 +133,7 @@ internal fun ManagementScreen( ManagementSurveyContent( surveyList = surveyList, modifier = Modifier.padding(top = 20.dp), - onCardClicked = onCardClicked, + onCardClicked = navigateToSurveyCheck, onAddSurveyButtonClicked = navigateToSurveyRegistration, ) } diff --git a/feature/management/src/main/java/com/wap/wapp/feature/management/navigation/ManagementNavigation.kt b/feature/management/src/main/java/com/wap/wapp/feature/management/navigation/ManagementNavigation.kt index fefca368..2d1065ca 100644 --- a/feature/management/src/main/java/com/wap/wapp/feature/management/navigation/ManagementNavigation.kt +++ b/feature/management/src/main/java/com/wap/wapp/feature/management/navigation/ManagementNavigation.kt @@ -16,11 +16,13 @@ fun NavController.navigateToManagement(navOptions: NavOptions? = navOptions {}) fun NavGraphBuilder.managementScreen( navigateToEventRegistration: () -> Unit, navigateToSurveyRegistration: () -> Unit, + navigateToSurveyCheck: (String) -> Unit, ) { composable(route = managementNavigationRoute) { ManagementRoute( navigateToEventRegistration = navigateToEventRegistration, navigateToSurveyRegistration = navigateToSurveyRegistration, + navigateToSurveyCheck = navigateToSurveyCheck, ) } } From a2eb2e921738a223106a3892c4d8c7b28f6c06b9 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 16:29:40 +0900 Subject: [PATCH 13/22] =?UTF-8?q?[CHORE]=20#65=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=86=8C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/network/model/survey/RatingResponse.kt | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 core/network/src/main/java/com/wap/wapp/core/network/model/survey/RatingResponse.kt diff --git a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/RatingResponse.kt b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/RatingResponse.kt deleted file mode 100644 index 24759c37..00000000 --- a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/RatingResponse.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.wap.wapp.core.network.model.survey - -/* -enum class RatingResponse { - GOOD, MEDIOCRE, BAD -} - -internal fun RatingResponse.toDomain(): Rating = when (this) { - RatingResponse.GOOD -> Rating.GOOD - RatingResponse.MEDIOCRE -> Rating.MEDIOCRE - RatingResponse.BAD -> Rating.BAD -} -*/ From 0b63a5593ac1c679505542e09b944ec48063bb8f Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 20:34:54 +0900 Subject: [PATCH 14/22] =?UTF-8?q?[FEATURE]=20#66=20:=20=EC=A0=9C=EC=B6=9C?= =?UTF-8?q?=ED=95=9C=20=EC=84=A4=EB=AC=B8=EC=9D=B8=EC=A7=80=20=ED=8C=90?= =?UTF-8?q?=EB=8B=A8=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/data/repository/survey/SurveyRepository.kt | 2 ++ .../data/repository/survey/SurveyRepositoryImpl.kt | 4 ++++ .../core/network/source/survey/SurveyDataSource.kt | 2 ++ .../network/source/survey/SurveyDataSourceImpl.kt | 12 ++++++++++++ 4 files changed, 20 insertions(+) diff --git a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepository.kt b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepository.kt index 25da4b2c..b097c9e1 100644 --- a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepository.kt +++ b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepository.kt @@ -17,4 +17,6 @@ interface SurveyRepository { surveyAnswerList: List, surveyedAt: LocalDateTime, ): Result + + suspend fun isSubmittedSurvey(eventId: Int, userId: String): Result } diff --git a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepositoryImpl.kt b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepositoryImpl.kt index 808b2b4e..582dae76 100644 --- a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepositoryImpl.kt +++ b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyRepositoryImpl.kt @@ -62,6 +62,10 @@ class SurveyRepositoryImpl @Inject constructor( ) } + override suspend fun isSubmittedSurvey(eventId: Int, userId: String): Result { + return surveyDataSource.isSubmittedSurvey(eventId, userId) + } + private val noticeNameResponse: Result = Result.success("notice datasource dummy data") // TODO 도메인 모델 구현을 위한 익스텐션, notice DataSource 구현 후 소거 diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSource.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSource.kt index 36644e12..9a4f61c8 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSource.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSource.kt @@ -4,6 +4,8 @@ import com.wap.wapp.core.model.survey.SurveyAnswer import com.wap.wapp.core.network.model.survey.SurveyResponse interface SurveyDataSource { + suspend fun isSubmittedSurvey(eventId: Int, userId: String): Result + suspend fun getSurveyList(): Result> suspend fun getSurvey(surveyId: String): Result diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSourceImpl.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSourceImpl.kt index c393509b..774877d8 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSourceImpl.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/survey/SurveyDataSourceImpl.kt @@ -71,4 +71,16 @@ class SurveyDataSourceImpl @Inject constructor( .await() } } + + override suspend fun isSubmittedSurvey(eventId: Int, userId: String): Result { + return runCatching { + val result = firebaseFirestore.collection(SURVEY_COLLECTION) + .whereEqualTo("eventId", eventId) + .whereEqualTo("userId", userId) + .get() + .await() + + result.isEmpty.not() + } + } } From e1848f3005dd8a4e437140d25cdcf82ddefb6f15 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 20:35:10 +0900 Subject: [PATCH 15/22] =?UTF-8?q?[FEATURE]=20#66=20:=20=EC=A0=9C=EC=B6=9C?= =?UTF-8?q?=ED=95=9C=20=EC=84=A4=EB=AC=B8=EC=9D=B8=EC=A7=80=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=ED=95=98=EB=8A=94=20=EC=9C=A0=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../survey/IsSubmittedSurveyUseCase.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/IsSubmittedSurveyUseCase.kt diff --git a/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/IsSubmittedSurveyUseCase.kt b/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/IsSubmittedSurveyUseCase.kt new file mode 100644 index 00000000..dcf68040 --- /dev/null +++ b/core/domain/src/main/java/com/wap/wapp/core/domain/usecase/survey/IsSubmittedSurveyUseCase.kt @@ -0,0 +1,21 @@ +package com.wap.wapp.core.domain.usecase.survey + +import com.wap.wapp.core.data.repository.survey.SurveyRepository +import com.wap.wapp.core.data.repository.user.UserRepository +import javax.inject.Inject + +class IsSubmittedSurveyUseCase @Inject constructor( + private val userRepository: UserRepository, + private val surveyRepository: SurveyRepository, +) { + suspend operator fun invoke(eventId: Int): Result { + return runCatching { + val userId = userRepository.getUserId().getOrThrow() + + surveyRepository.isSubmittedSurvey( + userId = userId, + eventId = eventId, + ).getOrThrow() + } + } +} From 7ca9e3fe3505a8ba92becfd0aee389862299b21c Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 20:36:15 +0900 Subject: [PATCH 16/22] =?UTF-8?q?[FEATURE]=20#66=20:=20=EC=A0=9C=EC=B6=9C?= =?UTF-8?q?=20=EA=B8=B0=EB=A1=9D=EC=97=90=20=EB=94=B0=EB=9D=BC,=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=ED=99=94=EB=A9=B4=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=84=ED=99=98=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wap/wapp/feature/survey/SurveyScreen.kt | 16 ++++++++++++-- .../wapp/feature/survey/SurveyViewModel.kt | 22 +++++++++++++++++++ .../survey/navigation/SurveyNavigation.kt | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyScreen.kt b/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyScreen.kt index 87986be4..23bbd144 100644 --- a/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyScreen.kt +++ b/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyScreen.kt @@ -21,6 +21,7 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp @@ -36,8 +37,9 @@ import java.time.LocalDateTime @Composable internal fun SurveyScreen( viewModel: SurveyViewModel, - selectedSurveyForm: (Int) -> Unit, + navigateToSurveyAnswer: (Int) -> Unit, ) { + val context = LocalContext.current val surveyFormListUiState = viewModel.surveyFormListUiState.collectAsState().value val snackBarHostState = remember { SnackbarHostState() } @@ -47,6 +49,16 @@ internal fun SurveyScreen( is SurveyViewModel.SurveyUiEvent.Failure -> { snackBarHostState.showSnackbar(it.throwable.toSupportingText()) } + + is SurveyViewModel.SurveyUiEvent.AlreadySubmitted -> { + snackBarHostState.showSnackbar( + context.getString(R.string.alreay_submitted_description), + ) + } + + is SurveyViewModel.SurveyUiEvent.NotSubmitted -> { + navigateToSurveyAnswer(it.eventId) + } } } } @@ -57,7 +69,7 @@ internal fun SurveyScreen( SurveyContent( surveyFormList = surveyFormListUiState.surveyFormList, snackBarHostState = snackBarHostState, - selectedSurveyForm = selectedSurveyForm, + selectedSurveyForm = viewModel::isSubmittedSurvey, ) } } diff --git a/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyViewModel.kt b/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyViewModel.kt index 562d2629..d18096d7 100644 --- a/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyViewModel.kt +++ b/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyViewModel.kt @@ -3,6 +3,7 @@ package com.wap.wapp.feature.survey import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.wap.wapp.core.domain.usecase.survey.GetSurveyFormListUseCase +import com.wap.wapp.core.domain.usecase.survey.IsSubmittedSurveyUseCase import com.wap.wapp.core.model.survey.SurveyForm import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow @@ -15,6 +16,7 @@ import javax.inject.Inject @HiltViewModel class SurveyViewModel @Inject constructor( private val getSurveyFormListUseCase: GetSurveyFormListUseCase, + private val isSubmittedSurveyUseCase: IsSubmittedSurveyUseCase, ) : ViewModel() { private val _surveyFormListUiState: MutableStateFlow = MutableStateFlow(SurveyFormListUiState.Init) @@ -39,6 +41,22 @@ class SurveyViewModel @Inject constructor( } } + fun isSubmittedSurvey(eventId: Int) { + viewModelScope.launch { + isSubmittedSurveyUseCase(eventId) + .onSuccess { isSubmittedSurvey -> + if (isSubmittedSurvey) { + _surveyEvent.emit(SurveyUiEvent.AlreadySubmitted) + } else { + _surveyEvent.emit(SurveyUiEvent.NotSubmitted(eventId)) + } + } + .onFailure { throwable -> + _surveyEvent.emit(SurveyUiEvent.Failure(throwable)) + } + } + } + sealed class SurveyFormListUiState { data object Init : SurveyFormListUiState() data class Success(val surveyFormList: List) : SurveyFormListUiState() @@ -46,5 +64,9 @@ class SurveyViewModel @Inject constructor( sealed class SurveyUiEvent { data class Failure(val throwable: Throwable) : SurveyUiEvent() + + data object AlreadySubmitted : SurveyUiEvent() + + data class NotSubmitted(val eventId: Int) : SurveyUiEvent() } } diff --git a/feature/survey/src/main/java/com/wap/wapp/feature/survey/navigation/SurveyNavigation.kt b/feature/survey/src/main/java/com/wap/wapp/feature/survey/navigation/SurveyNavigation.kt index 24afd078..b674d47a 100644 --- a/feature/survey/src/main/java/com/wap/wapp/feature/survey/navigation/SurveyNavigation.kt +++ b/feature/survey/src/main/java/com/wap/wapp/feature/survey/navigation/SurveyNavigation.kt @@ -26,7 +26,7 @@ fun NavGraphBuilder.surveyNavGraph( composable(route = SurveyRoute.route) { SurveyScreen( viewModel = hiltViewModel(), - selectedSurveyForm = { eventId -> + navigateToSurveyAnswer = { eventId -> navigateToSurveyAnswer(eventId) }, ) From e15c55913b93f171d0f929370aa7e5ca853eea95 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 20:36:25 +0900 Subject: [PATCH 17/22] =?UTF-8?q?[FEATURE]=20#66=20:=20=EC=A0=9C=EC=B6=9C?= =?UTF-8?q?=20=EA=B8=B0=EB=A1=9D=EC=97=90=20=EB=94=B0=EB=9D=BC,=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=ED=99=94=EB=A9=B4=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=84=ED=99=98=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- feature/survey/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/feature/survey/src/main/res/values/strings.xml b/feature/survey/src/main/res/values/strings.xml index 8ac185b5..6f82b662 100644 --- a/feature/survey/src/main/res/values/strings.xml +++ b/feature/survey/src/main/res/values/strings.xml @@ -9,4 +9,5 @@ 참가한 행사에 대해 설문에 응답하세요! 설문 응답 /10자 이상 + 이미 작성한 설문입니다. From 964db3eee515fdeaaec6066d5d71f0c3d1024940 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 20:36:45 +0900 Subject: [PATCH 18/22] =?UTF-8?q?[FEATURE]=20#66=20:=20=EC=A3=BC=EA=B4=80?= =?UTF-8?q?=EC=8B=9D=20=EC=9D=91=EB=8B=B5=EC=9D=B4=2010=EA=B8=80=EC=9E=90?= =?UTF-8?q?=20=EC=9D=B4=EC=83=81=EC=9D=BC=20=EA=B2=BD=EC=9A=B0,=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=EC=9D=B4=20=ED=99=9C=EC=84=B1=ED=99=94=20?= =?UTF-8?q?=EB=90=98=EB=8F=84=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/survey/answer/SurveyAnswerScreen.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerScreen.kt b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerScreen.kt index acaadf29..e805354e 100644 --- a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerScreen.kt +++ b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerScreen.kt @@ -147,6 +147,7 @@ private fun SurveyAnswerForm( SurveyAnswerButton( isLastQuestion = isLastQuestion, onButtonClicked = onNextButtonClicked, + isEnabled = isButtonEnabled(surveyQuestion.questionType, subjectiveAnswer), ) } } @@ -188,16 +189,28 @@ private fun SurveyAnswerTopBar( private fun SurveyAnswerButton( isLastQuestion: Boolean, onButtonClicked: () -> Unit, + isEnabled: Boolean, ) { if (isLastQuestion) { WappButton( textRes = R.string.submit, onClick = { onButtonClicked() }, + isEnabled = isEnabled, ) } else { WappButton( textRes = R.string.next, onClick = { onButtonClicked() }, + isEnabled = isEnabled, ) } } + +private fun isButtonEnabled( + questionType: QuestionType, + subjectiveAnswer: String, +): Boolean { + if (questionType == QuestionType.SUBJECTIVE) return subjectiveAnswer.length >= 10 + + return true +} From f2477ec4ab57490943b4faac1e4627209459806a Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Sat, 23 Dec 2023 13:17:53 +0900 Subject: [PATCH 19/22] [CHORE] #67 : Survey Check Route Object to const val --- .../management/check/navigation/SurveyCheckNavigation.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/feature/management/src/main/java/com/wap/wapp/feature/management/check/navigation/SurveyCheckNavigation.kt b/feature/management/src/main/java/com/wap/wapp/feature/management/check/navigation/SurveyCheckNavigation.kt index acb764d3..bfe2c0d6 100644 --- a/feature/management/src/main/java/com/wap/wapp/feature/management/check/navigation/SurveyCheckNavigation.kt +++ b/feature/management/src/main/java/com/wap/wapp/feature/management/check/navigation/SurveyCheckNavigation.kt @@ -9,6 +9,8 @@ import androidx.navigation.navArgument import androidx.navigation.navOptions import com.wap.wapp.feature.management.check.SurveyCheckRoute +const val SURVEY_CHECK_ROUTE = "survey/check/{surveyId}" + fun NavController.navigateToSurveyCheck( surveyId: String, navOptions: NavOptions? = navOptions {}, @@ -20,7 +22,7 @@ fun NavGraphBuilder.surveyCheckScreen( navigateToManagement: () -> Unit, ) { composable( - route = SurveyCheckRoute.route, + route = SURVEY_CHECK_ROUTE, arguments = listOf( navArgument("surveyId") { type = NavType.StringType @@ -34,7 +36,3 @@ fun NavGraphBuilder.surveyCheckScreen( ) } } - -object SurveyCheckRoute { - const val route = "survey/check/{surveyId}" -} From 9dfc6d6ce60059b08826808b88513cc6f6383dee Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Sat, 23 Dec 2023 13:18:17 +0900 Subject: [PATCH 20/22] =?UTF-8?q?[STYLE]=20#67=20:=20=EB=8B=A8=EC=9D=BC?= =?UTF-8?q?=EB=AC=B8=20=ED=95=A8=EC=88=98=20block=20to=20equal=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/data/repository/survey/SurveyFormRepositoryImpl.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepositoryImpl.kt b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepositoryImpl.kt index 6d0d5d8a..1bb911f7 100644 --- a/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepositoryImpl.kt +++ b/core/data/src/main/java/com/wap/wapp/core/data/repository/survey/SurveyFormRepositoryImpl.kt @@ -9,11 +9,10 @@ import javax.inject.Inject class SurveyFormRepositoryImpl @Inject constructor( private val surveyFormDataSource: SurveyFormDataSource, ) : SurveyFormRepository { - override suspend fun getSurveyForm(eventId: Int): Result { - return surveyFormDataSource.getSurveyForm(eventId).mapCatching { surveyFormResponse -> + override suspend fun getSurveyForm(eventId: Int): Result = + surveyFormDataSource.getSurveyForm(eventId).mapCatching { surveyFormResponse -> surveyFormResponse.toDomain() } - } override suspend fun getSurveyFormList(): Result> { return surveyFormDataSource.getSurveyFormList().mapCatching { surveyFormResponseList -> From ce29f5756a95283f56e7d5231d2b8d94d7a0db56 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Sat, 23 Dec 2023 13:19:20 +0900 Subject: [PATCH 21/22] =?UTF-8?q?[REFACTOR]=20#67=20:=20=EB=8B=A4=EC=9D=8C?= =?UTF-8?q?=20=EC=A7=88=EB=AC=B8=20=EB=84=98=EA=B8=B0=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20ViewModel=20to=20View=EB=A1=9C=20=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/survey/answer/SurveyAnswerScreen.kt | 10 ++++++++-- .../survey/answer/SurveyAnswerViewModel.kt | 16 ++-------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerScreen.kt b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerScreen.kt index e805354e..c9440a3d 100644 --- a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerScreen.kt +++ b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerScreen.kt @@ -95,8 +95,14 @@ internal fun SurveyAnswerScreen( onSubjectiveAnswerChanged = viewModel::setSubjectiveAnswer, onObjectiveAnswerSelected = viewModel::setObjectiveAnswer, onNextButtonClicked = { - viewModel.addSurveyAnswer() - viewModel.setNextQuestion() + viewModel.addSurveyAnswer() // 현재 응답 저장 + + if (questionNumber == lastQuestionNumber) { // 마지막 질문일 경우 제출 + viewModel.submitSurvey() + return@SurveyAnswerForm + } + + viewModel.setNextQuestionNumber() // 다음 질문 불러오기 }, ) } diff --git a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerViewModel.kt b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerViewModel.kt index 121ded8b..08160a49 100644 --- a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerViewModel.kt +++ b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerViewModel.kt @@ -85,19 +85,7 @@ class SurveyAnswerViewModel @Inject constructor( } } - fun setNextQuestion() { - val currentQuestionNumber = _questionNumber.value - val lastQuestionNumber = _surveyForm.value.surveyQuestionList.lastIndex - - if (currentQuestionNumber == lastQuestionNumber) { // 마지막 질문일 경우 제출 - submitSurvey() - return - } - - addQuestionNumber() // 다음 질문 넘기기 - } - - private fun submitSurvey() { + fun submitSurvey() { val surveyForm = _surveyForm.value val surveyAnswerList = surveyAnswerList.value @@ -119,7 +107,7 @@ class SurveyAnswerViewModel @Inject constructor( fun setObjectiveAnswer(answer: Rating) { _objectiveAnswer.value = answer } - private fun addQuestionNumber() { _questionNumber.value += 1 } + fun setNextQuestionNumber() { _questionNumber.value += 1 } private fun clearSubjectiveAnswer() { _subjectiveAnswer.value = "" } From 690a3d31cc70c4559c4966e2377b79bdfd0021b4 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Sat, 23 Dec 2023 13:30:42 +0900 Subject: [PATCH 22/22] =?UTF-8?q?[CHORE]=20#67=20:=20String=20to=20LocalDa?= =?UTF-8?q?teTime=20=EB=B3=80=ED=99=98=20=EC=9C=A0=ED=8B=B8=EB=A6=AC?= =?UTF-8?q?=ED=8B=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wap/wapp/core/network/model/survey/SurveyResponse.kt | 8 ++------ .../core/network/model/survey/form/SurveyFormResponse.kt | 5 ++--- .../java/com/wap/wapp/core/network/utils/LocalDateTime.kt | 8 ++++++++ 3 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 core/network/src/main/java/com/wap/wapp/core/network/utils/LocalDateTime.kt diff --git a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyResponse.kt b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyResponse.kt index c65b0def..3e6adeda 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyResponse.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/SurveyResponse.kt @@ -1,8 +1,7 @@ package com.wap.wapp.core.network.model.survey import com.wap.wapp.core.model.survey.Survey -import java.time.LocalDateTime -import java.time.format.DateTimeFormatter +import com.wap.wapp.core.network.utils.toISOLocalDateTime data class SurveyResponse( val surveyId: String, @@ -30,9 +29,6 @@ data class SurveyResponse( title = this.title, content = this.content, surveyAnswerList = this.surveyAnswerList.map { answer -> answer.toDomain() }, - surveyedAt = LocalDateTime.parse( - this.surveyedAt, - DateTimeFormatter.ISO_LOCAL_DATE_TIME, - ), + surveyedAt = surveyedAt.toISOLocalDateTime(), ) } diff --git a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyFormResponse.kt b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyFormResponse.kt index 46befb9f..1391e7d9 100644 --- a/core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyFormResponse.kt +++ b/core/network/src/main/java/com/wap/wapp/core/network/model/survey/form/SurveyFormResponse.kt @@ -1,8 +1,7 @@ package com.wap.wapp.core.network.model.survey.form import com.wap.wapp.core.model.survey.SurveyForm -import java.time.LocalDateTime -import java.time.format.DateTimeFormatter +import com.wap.wapp.core.network.utils.toISOLocalDateTime data class SurveyFormResponse( val eventId: Int, @@ -26,6 +25,6 @@ data class SurveyFormResponse( title = title, content = content, surveyQuestionList = surveyQuestionList.map { it.toDomain() }, - deadline = LocalDateTime.parse(deadline, DateTimeFormatter.ISO_LOCAL_DATE_TIME), + deadline = deadline.toISOLocalDateTime(), ) } diff --git a/core/network/src/main/java/com/wap/wapp/core/network/utils/LocalDateTime.kt b/core/network/src/main/java/com/wap/wapp/core/network/utils/LocalDateTime.kt new file mode 100644 index 00000000..4e87c2ce --- /dev/null +++ b/core/network/src/main/java/com/wap/wapp/core/network/utils/LocalDateTime.kt @@ -0,0 +1,8 @@ +package com.wap.wapp.core.network.utils + +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter + +internal fun String.toISOLocalDateTime(): LocalDateTime = LocalDateTime.parse( + this, DateTimeFormatter.ISO_LOCAL_DATE_TIME +)