Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/jaino/#53 #54

Merged
merged 11 commits into from
Nov 30, 2023
Merged
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.wap.wapp.core.data.repository.management

import com.wap.wapp.core.model.survey.SurveyForm

interface ManagementRepository {
suspend fun getManager(userId: String): Result<Boolean>

suspend fun postManager(userId: String): Result<Unit>

suspend fun getManagementCode(code: String): Result<Boolean>

suspend fun postSurveyForm(surveyForm: SurveyForm): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
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(
Expand All @@ -17,4 +20,17 @@ class ManagementRepositoryImpl @Inject constructor(
override suspend fun getManagementCode(code: String): Result<Boolean> {
return managementDataSource.getManagementCode(code)
}

override suspend fun postSurveyForm(surveyForm: SurveyForm): Result<Unit> {
return managementDataSource.postSurveyForm(
surveyFormRequest = SurveyFormRequest(
userId = surveyForm.userId,
title = surveyForm.title,
content = surveyForm.content,
surveyQuestion = surveyForm.surveyQuestion,
deadline = surveyForm.deadline.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
),
eventId = surveyForm.eventId,
)
}
Comment on lines 20 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 여기는 runCatching 안한 이유가 있을까요 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수를 호출하는 로직 안에 runCatching 이요 ,,,,?

저기 Local DateTime 포맷팅 하는 부분에서 예외가 발생할 것 같아서, 주시는 말씀인가요 ??

따로 로직을 수행하는게 아니고, 따로 파라미터를 넘기는 부분이라 하지는 않았습니다.. !

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeongjaino

와우 저는 이 때 까지 아무생각 없이 다 갖다 박았는데

파워 인사이트 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.wap.wapp.core.domain.usecase.management

import com.wap.wapp.core.data.repository.management.ManagementRepository
import com.wap.wapp.core.data.repository.user.UserRepository
import com.wap.wapp.core.model.event.Event
import com.wap.wapp.core.model.survey.SurveyForm
import com.wap.wapp.core.model.survey.SurveyQuestion
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import javax.inject.Inject

class RegisterSurveyUseCase @Inject constructor(
private val managementRepository: ManagementRepository,
private val userRepository: UserRepository,
) {
suspend operator fun invoke(
event: Event,
title: String,
content: String,
surveyQuestion: List<SurveyQuestion>,
deadlineDate: LocalDate,
deadlineTime: LocalTime,
): Result<Unit> {
return runCatching {
val userId = userRepository.getUserId().getOrThrow()

managementRepository.postSurveyForm(
SurveyForm(
eventId = event.eventId,
userId = userId,
title = title,
content = content,
surveyQuestion = surveyQuestion,
deadline = LocalDateTime.of(deadlineDate, deadlineTime),
),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import java.time.LocalDateTime

// 운영진이 등록하는 설문 모델
data class SurveyForm(
val eventId: String,
val eventId: Int,
val userId: String,
val title: String,
val content: String,
val surveyQuestion: List<SurveyQuestion>,
val deadLine: LocalDateTime,
val deadline: LocalDateTime,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ const val MANAGER_COLLECTION = "managers"
const val CODES_COLLECTION = "codes"
const val SURVEY_COLLECTION = "surveys"
const val EVENT_COLLECTION = "events"
const val SURVEY_FORM_COLLECTION = "surveyForms"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.wap.wapp.core.network.model.management

import com.wap.wapp.core.model.survey.SurveyQuestion

data class SurveyFormRequest(
val userId: String,
val title: String,
val content: String,
val surveyQuestion: List<SurveyQuestion>,
val deadline: String,
) {
constructor() : this(
"",
"",
"",
emptyList(),
"",
)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
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<Boolean>

suspend fun postManager(userId: String): Result<Unit>

suspend fun getManagementCode(code: String): Result<Boolean>

suspend fun postSurveyForm(surveyFormRequest: SurveyFormRequest, eventId: Int): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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

Expand Down Expand Up @@ -43,4 +45,17 @@ class ManagementDataSourceImpl @Inject constructor(
result.isEmpty.not()
}
}

override suspend fun postSurveyForm(
surveyFormRequest: SurveyFormRequest,
eventId: Int,
): Result<Unit> {
return runCatching {
val setOption = SetOptions.merge()
firebaseFirestore.collection(SURVEY_FORM_COLLECTION)
.document(eventId.toString())
.set(surveyFormRequest, setOption)
.await()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.wap.designsystem.WappTheme
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class SurveyRegistrationFragment : Fragment() {

private lateinit var composeView: ComposeView
Expand All @@ -29,6 +31,9 @@ class SurveyRegistrationFragment : Fragment() {
WappTheme {
SurveyRegistrationScreen(
onBackButtonClicked = { navigateToManagement() },
registerSurveyForm = {
navigateToManagement()
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import java.time.LocalTime

@Composable
internal fun SurveyRegistrationScreen(
registerSurveyForm: () -> Unit,
viewModel: SurveyRegistrationViewModel = hiltViewModel(),
onBackButtonClicked: () -> Unit,
) {
Expand All @@ -48,6 +49,7 @@ internal fun SurveyRegistrationScreen(
val title = viewModel.surveyTitle.collectAsState().value
val content = viewModel.surveyContent.collectAsState().value
val question = viewModel.surveyQuestion.collectAsState().value
val questionType = viewModel.surveyQuestionType.collectAsState().value
val totalQuestionSize = viewModel.surveyQuestionList.collectAsState().value.size + 1
val time = viewModel.surveyTimeDeadline.collectAsState().value
val date = viewModel.surveyDateDeadline.collectAsState().value
Expand All @@ -62,6 +64,10 @@ internal fun SurveyRegistrationScreen(
is SurveyRegistrationViewModel.SurveyRegistrationEvent.ValidationError -> {
snackBarHostState.showSnackbar(it.message)
}

is SurveyRegistrationViewModel.SurveyRegistrationEvent.Success -> {
registerSurveyForm()
}
}
}
}
Expand Down Expand Up @@ -99,6 +105,7 @@ internal fun SurveyRegistrationScreen(
title = title,
content = content,
question = question,
questionType = questionType,
date = date,
time = time,
currentQuestionIndex = totalQuestionSize,
Expand All @@ -108,12 +115,15 @@ internal fun SurveyRegistrationScreen(
onTitleChanged = { title -> viewModel.setSurveyTitle(title) },
onContentChanged = { content -> viewModel.setSurveyContent(content) },
onQuestionChanged = { question -> viewModel.setSurveyQuestion(question) },
onQuestionTypeChanged = { questionType ->
viewModel.setSurveyQuestionType(questionType)
},
onDateChanged = { localDate -> viewModel.setSurveyDateDeadline(localDate) },
onTimeChanged = { localTime -> viewModel.setSurveyTimeDeadline(localTime) },
onNextButtonClicked = { surveyRegistrationState ->
viewModel.setSurveyRegistrationState(surveyRegistrationState)
},
onAddQuestionButtonClicked = { type -> viewModel.addSurveyQuestion(type) },
onAddQuestionButtonClicked = { viewModel.addSurveyQuestion() },
onRegisterButtonClicked = { viewModel.registerSurvey() },
)
}
Expand Down Expand Up @@ -141,6 +151,7 @@ private fun SurveyRegistrationContent(
title: String,
content: String,
question: String,
questionType: QuestionType,
time: LocalTime,
date: LocalDate,
currentQuestionIndex: Int,
Expand All @@ -150,10 +161,11 @@ private fun SurveyRegistrationContent(
onTitleChanged: (String) -> Unit,
onContentChanged: (String) -> Unit,
onQuestionChanged: (String) -> Unit,
onQuestionTypeChanged: (QuestionType) -> Unit,
onDateChanged: (LocalDate) -> Unit,
onTimeChanged: (LocalTime) -> Unit,
onNextButtonClicked: (SurveyRegistrationState) -> Unit,
onAddQuestionButtonClicked: (QuestionType) -> Unit,
onAddQuestionButtonClicked: () -> Unit,
onRegisterButtonClicked: () -> Unit,
) {
when (surveyRegistrationState) {
Expand Down Expand Up @@ -181,8 +193,12 @@ private fun SurveyRegistrationContent(
SurveyRegistrationState.QUESTION -> {
SurveyQuestionContent(
question = question,
questionType = questionType,
onQuestionChanged = { defaultQuestion -> onQuestionChanged(defaultQuestion) },
onAddSurveyQuestionButtonClicked = { type -> onAddQuestionButtonClicked(type) },
onQuestionTypeChanged = { defaultQuestionType ->
onQuestionTypeChanged(defaultQuestionType)
},
onAddSurveyQuestionButtonClicked = { onAddQuestionButtonClicked() },
currentQuestionIndex = currentQuestionIndex,
totalQuestionIndex = totalQuestionSize,
onNextButtonClicked = { onNextButtonClicked(SurveyRegistrationState.DEADLINE) },
Expand Down
Loading