Skip to content

Commit

Permalink
[CHORE] #82 : Reslove Conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Jan 6, 2024
2 parents 3144a4a + eb7037b commit c137109
Show file tree
Hide file tree
Showing 15 changed files with 212 additions and 43 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ fun WappNavHost(
surveyNavGraph(
navigateToSurvey = navController::navigateToSurvey,
navigateToSurveyAnswer = navController::navigateToSurveyAnswer,
navigateToSignIn = navController::navigateToSignIn,
)
surveyCheckScreen(
navigateToManagement = navController::navigateToManagement,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wap.wapp.core.data.repository.management

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import javax.inject.Inject
class ManagementRepositoryImpl @Inject constructor(
private val managementDataSource: ManagementDataSource,
) : ManagementRepository {
override suspend fun getManager(userId: String): Result<Boolean> =
managementDataSource.getManager(userId)
override suspend fun isManager(userId: String): Result<Boolean> =
managementDataSource.isManager(userId)

override suspend fun postManager(userId: String): Result<Unit> =
managementDataSource.postManager(userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HasManagerStateUseCase @Inject constructor(
suspend operator fun invoke(): Result<Boolean> = runCatching {
val userId = userRepository.getUserId().getOrThrow()

managementRepository.getManager(userId).fold(
managementRepository.isManager(userId).fold(
onSuccess = { hasManagerState -> hasManagerState },
onFailure = { throw (it) },
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.wap.wapp.core.domain.usecase.user

import com.wap.wapp.core.data.repository.management.ManagementRepository
import com.wap.wapp.core.data.repository.user.UserRepository
import com.wap.wapp.core.model.user.UserRole
import javax.inject.Inject

class GetUserRoleUseCase @Inject constructor(
private val userRepository: UserRepository,
private val managementRepository: ManagementRepository,
) {
suspend operator fun invoke(): Result<UserRole> {
return runCatching {
val userId = userRepository.getUserId()
.getOrElse { exception ->
if (exception is IllegalStateException) { // 회원이 아닌 경우
return@runCatching UserRole.GUEST
}
throw exception
}

managementRepository.isManager(userId)
.fold(
onSuccess = { isManager ->
if (isManager) { // 매니저인 경우
return@fold UserRole.MANAGER
}
UserRole.MEMBER
},
onFailure = { exception ->
throw exception
},
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.wap.wapp.core.model.survey

import java.time.Duration
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

// 운영진이 등록하는 설문 모델
data class SurveyForm(
Expand All @@ -17,4 +19,31 @@ data class SurveyForm(
emptyList(),
LocalDateTime.MIN,
)

fun calculateDeadline(): String {
val currentDateTime = LocalDateTime.now()
val duration = Duration.between(currentDateTime, deadline)

if (duration.toMinutes() < 60) {
val leftMinutes = duration.toMinutes().toString()
return leftMinutes + "분 후 마감"
}

if (duration.toHours() < 24) {
val leftHours = duration.toHours().toString()
return leftHours + "시간 후 마감"
}

if (duration.toDays() < 31) {
val leftDays = duration.toDays().toString()
return leftDays + "일 후 마감"
}

return deadline.format(DateTimeFormatter.ofPattern("yyyy.MM.dd")) + " 마감"
}

fun isAfterDeadline(): Boolean {
val currentDateTime = LocalDateTime.now()
return deadline.isAfter(currentDateTime)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wap.wapp.core.model.user

enum class UserRole {
GUEST, MEMBER, MANAGER
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wap.wapp.core.network.source.management

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import javax.inject.Inject
class ManagementDataSourceImpl @Inject constructor(
private val firebaseFirestore: FirebaseFirestore,
) : ManagementDataSource {
override suspend fun getManager(userId: String): Result<Boolean> = runCatching {
override suspend fun isManager(userId: String): Result<Boolean> = runCatching {
val result = firebaseFirestore.collection(MANAGER_COLLECTION)
.whereEqualTo("userId", userId)
.get()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.wap.wapp.feature.survey

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.wap.designsystem.WappTheme
import com.wap.designsystem.component.WappButton

@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun SurveyGuestDialog(
onDismissRequest: () -> Unit,
onButtonClicked: () -> Unit,
) {
AlertDialog(
onDismissRequest = { onDismissRequest() },
modifier = Modifier
.padding(16.dp)
.fillMaxWidth(),
) {
Column(
verticalArrangement = Arrangement.spacedBy(16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxWidth(),
) {
Column {
Text(
text = stringResource(R.string.survey_guset_title),
style = WappTheme.typography.titleBold,
color = WappTheme.colors.white,
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
)
Text(
text = stringResource(R.string.survey_guest_content),
style = WappTheme.typography.captionMedium,
color = WappTheme.colors.white,
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
)
}

WappButton(
textRes = R.string.go_to_signin,
onClick = onButtonClicked,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,33 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.wap.designsystem.WappTheme
import com.wap.designsystem.component.WappMainTopBar
import com.wap.wapp.core.commmon.extensions.toSupportingText
import com.wap.wapp.core.commmon.util.DateUtil
import com.wap.wapp.core.commmon.util.DateUtil.yyyyMMddFormatter
import com.wap.wapp.core.model.survey.SurveyForm
import com.wap.wapp.core.model.user.UserRole
import kotlinx.coroutines.flow.collectLatest
import java.time.Duration
import java.time.LocalDateTime

@Composable
internal fun SurveyScreen(
viewModel: SurveyViewModel,
navigateToSignIn: () -> Unit,
navigateToSurveyAnswer: (String) -> Unit,
) {
val context = LocalContext.current
val surveyFormListUiState = viewModel.surveyFormListUiState.collectAsState().value
val surveyFormListUiState = viewModel.surveyFormListUiState.collectAsStateWithLifecycle().value
val snackBarHostState = remember { SnackbarHostState() }
var isShowGuestDialog by rememberSaveable { mutableStateOf(false) }

LaunchedEffect(true) {
viewModel.surveyEvent.collectLatest {
Expand All @@ -64,10 +67,36 @@ internal fun SurveyScreen(
}
}

LaunchedEffect(true) {
viewModel.userRoleUiState.collectLatest { userRoleUiState ->
when (userRoleUiState) {
is SurveyViewModel.UserRoleUiState.Init -> {}
is SurveyViewModel.UserRoleUiState.Success -> {
when (userRoleUiState.userRole) {
UserRole.GUEST -> {
isShowGuestDialog = true
}

// 비회원이 아닌 경우, 목록 호출
UserRole.MEMBER, UserRole.MANAGER -> {
viewModel.getSurveyFormList()
}
}
}
}
}
}

Scaffold(
modifier = Modifier.fillMaxSize(),
containerColor = WappTheme.colors.backgroundBlack,
snackbarHost = { SnackbarHost(snackBarHostState) },
topBar = {
WappMainTopBar(
titleRes = R.string.survey,
contentRes = R.string.survey_content,
)
},
contentWindowInsets = WindowInsets(0.dp),
) { paddingValues ->
when (surveyFormListUiState) {
Expand All @@ -81,6 +110,13 @@ internal fun SurveyScreen(
}
}
}

if (isShowGuestDialog) {
SurveyGuestDialog(
onDismissRequest = { isShowGuestDialog = false },
onButtonClicked = navigateToSignIn,
)
}
}

@Composable
Expand All @@ -93,11 +129,6 @@ private fun SurveyContent(
verticalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.padding(paddingValues),
) {
WappMainTopBar(
titleRes = R.string.survey,
contentRes = R.string.survey_content,
)

LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.padding(horizontal = 16.dp),
Expand Down Expand Up @@ -138,14 +169,13 @@ private fun SurveyFormItemCard(
style = WappTheme.typography.titleBold,
)
Text(
text = calculateDeadline(surveyForm.deadline),
text = surveyForm.calculateDeadline(),
color = WappTheme.colors.yellow34,
style = WappTheme.typography.captionMedium,
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.End,
)
}

Text(
text = surveyForm.content,
color = WappTheme.colors.grayBD,
Expand All @@ -154,25 +184,3 @@ private fun SurveyFormItemCard(
}
}
}

private fun calculateDeadline(deadline: LocalDateTime): String {
val currentDateTime = DateUtil.generateNowDateTime()
val duration = Duration.between(currentDateTime, deadline)

if (duration.toMinutes() < 60) {
val leftMinutes = duration.toMinutes().toString()
return leftMinutes + "분 후 마감"
}

if (duration.toHours() < 24) {
val leftHours = duration.toHours().toString()
return leftHours + "시간 후 마감"
}

if (duration.toDays() < 31) {
val leftDays = duration.toDays().toString()
return leftDays + "일 후 마감"
}

return deadline.format(yyyyMMddFormatter) + " 마감"
}
Loading

0 comments on commit c137109

Please sign in to comment.