Skip to content

Commit

Permalink
🔀 :: (#648) password validator 수정
Browse files Browse the repository at this point in the history
🔀 :: (#648) password validator 수정
  • Loading branch information
JunJaBoy authored Mar 13, 2024
2 parents 0460cba + 405f884 commit 2d942c3
Show file tree
Hide file tree
Showing 19 changed files with 344 additions and 87 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ jobs:
run: |
echo $PROD_BASE_URL >> ./local.properties
echo $DEV_BASE_URL >> ./local.properties
echo $TERMS_URL >> ./local.properties
cat
env:
PROD_BASE_URL: ${{secrets.PROD_BASE_URL}}
DEV_BASE_URL: ${{secrets.DEV_BASE_URL}}
TERMS_URL: ${{secrets.TERMS_URL}}

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()

versionCode = 6
versionName = "v1.2.0"
versionCode = 8
versionName = "v1.2.2"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ import team.aliens.dms.android.data.meal.model.Meal
abstract class MealRepository {

abstract suspend fun fetchMeal(date: LocalDate): Meal

abstract suspend fun updateMeal(date: LocalDate): Meal
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ internal class MealRepositoryImpl @Inject constructor(
databaseMealDataSource.queryMeal(date).toModel()
} catch (_: Exception) {
try {
networkMealDataSource.fetchMeals(date).toModel().also { meals ->
databaseMealDataSource.saveMeals(meals.toEntity())
}
.find { it.date == date }!!
this.updateMeal(date = date)
} catch (_: Exception) {
throw CannotFindMealException()
}
}

override suspend fun updateMeal(date: LocalDate): Meal {
return networkMealDataSource.fetchMeals(date).toModel().also { meals ->
databaseMealDataSource.saveMeals(meals.toEntity())
}
.find { it.date == date }!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ internal fun EditPasswordSetPasswordScreen(

EditPasswordSideEffect.PasswordFormatError -> isPasswordFormatError = true

EditPasswordSideEffect.PasswordEditFailure -> toast.showErrorToast(
message = context.getString(R.string.edit_password_error_password_edit_failure),
)

else -> {/* explicit blank */
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,30 @@ class EditPasswordViewModel @Inject constructor(
),
)

private fun editPassword() = viewModelScope.launch(Dispatchers.IO) {
private fun editPassword() = run {
val capturedState = stateFlow.value
if (capturedState.newPassword != capturedState.newPasswordRepeat) {
val newPassword = capturedState.newPassword
val newPasswordRepeat = capturedState.newPasswordRepeat

if (newPassword != newPasswordRepeat) {
postSideEffect(EditPasswordSideEffect.PasswordMismatch)
return@launch
return@run
}
if (!checkIfPasswordValid(capturedState.newPassword)) {
if (!checkIfPasswordValid(newPassword)) {
postSideEffect(EditPasswordSideEffect.PasswordFormatError)
return@launch
return@run
}

runCatching {
userRepository.editPassword(
currentPassword = capturedState.currentPassword,
newPassword = capturedState.newPassword,
)
}.onSuccess {
postSideEffect(EditPasswordSideEffect.PasswordEdited)
}.onFailure {
it.printStackTrace()
postSideEffect(EditPasswordSideEffect.PasswordFormatError)
viewModelScope.launch(Dispatchers.IO) {
runCatching {
userRepository.editPassword(
currentPassword = capturedState.currentPassword,
newPassword = newPassword,
)
}.onSuccess {
postSideEffect(EditPasswordSideEffect.PasswordEdited)
}.onFailure {
postSideEffect(EditPasswordSideEffect.PasswordEditFailure)
}
}
}
}
Expand Down Expand Up @@ -111,4 +114,5 @@ sealed class EditPasswordSideEffect : SideEffect() {
data object PasswordEdited : EditPasswordSideEffect()
data object PasswordFormatError : EditPasswordSideEffect()
data object PasswordMismatch : EditPasswordSideEffect()
data object PasswordEditFailure : EditPasswordSideEffect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.Text
import androidx.compose.material3.pulltorefresh.PullToRefreshContainer
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -49,6 +51,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
Expand All @@ -67,12 +70,13 @@ import team.aliens.dms.android.core.designsystem.DmsCalendar
import team.aliens.dms.android.core.designsystem.DmsScaffold
import team.aliens.dms.android.core.designsystem.DmsTheme
import team.aliens.dms.android.core.designsystem.DmsTopAppBar
import team.aliens.dms.android.core.designsystem.LocalToast
import team.aliens.dms.android.core.designsystem.ModalBottomSheet
import team.aliens.dms.android.core.designsystem.OutlinedButton
import team.aliens.dms.android.core.designsystem.PrimaryDefault
import team.aliens.dms.android.core.designsystem.ShadowDefaults
import team.aliens.dms.android.core.designsystem.TextButton
import team.aliens.dms.android.core.designsystem.clickable
import team.aliens.dms.android.core.designsystem.rememberToastState
import team.aliens.dms.android.core.ui.DefaultHorizontalSpace
import team.aliens.dms.android.core.ui.DefaultVerticalSpace
import team.aliens.dms.android.core.ui.PaddingDefaults
Expand Down Expand Up @@ -100,13 +104,29 @@ internal fun HomeScreen(
onChangeBottomAppBarVisibility: (visible: Boolean) -> Unit,
onNavigateToAnnouncementList: () -> Unit,
) {
val toast = rememberToastState()
val toast = LocalToast.current
val context = LocalContext.current

val uiState by viewModel.stateFlow.collectAsStateWithLifecycle()
val pullToRefreshState = rememberPullToRefreshState()

val onRefresh = remember {
{
pullToRefreshState.startRefresh()
viewModel.postIntent(HomeIntent.UpdateMeal); Unit
}
}
viewModel.sideEffectFlow.collectInLaunchedEffectWithLifecycle { sideEffect ->
when (sideEffect) {
HomeSideEffect.CannotFindMeal -> toast.showErrorToast(context.getString(R.string.meal_error_not_found)) // FIXME: toast not showing
HomeSideEffect.CannotFindMeal, HomeSideEffect.MealUpdateFailed -> toast.showErrorToast(
context.getString(R.string.meal_error_not_found),
)

HomeSideEffect.MealUpdated -> {
pullToRefreshState.endRefresh()
toast.showSuccessToast(
message = context.getString(R.string.home_success_meal_refreshed),
)
}
}
}

Expand All @@ -119,6 +139,12 @@ internal fun HomeScreen(

val (shouldShowCalendar, onShouldShowCalendarChange) = remember { mutableStateOf(false) }

LaunchedEffect(pullToRefreshState.isRefreshing) {
if (pullToRefreshState.isRefreshing) {
onRefresh()
}
}

if (shouldShowCalendar) {
ModalBottomSheet(
onDismissRequest = {
Expand Down Expand Up @@ -151,6 +177,7 @@ internal fun HomeScreen(
) { padValues ->
Column(
modifier = Modifier
.nestedScroll(pullToRefreshState.nestedScrollConnection)
.animateContentSize()
.background(brush = HomeBackgroundBrush)
.fillMaxSize()
Expand Down Expand Up @@ -192,9 +219,18 @@ internal fun HomeScreen(
meal = uiState.currentMeal,
onNextDay = { onSelectedDateChange(uiState.selectedDate.plusDays(1)) },
onPreviousDay = { onSelectedDateChange(uiState.selectedDate.minusDays(1)) },
onRefresh = onRefresh,
)
Spacer(modifier = Modifier.height(92.dp))
}
Box(
modifier = Modifier
.fillMaxWidth()
.padding(top = padValues.calculateTopPadding()),
contentAlignment = Alignment.TopCenter,
) {
PullToRefreshContainer(state = pullToRefreshState)
}
}
}

Expand Down Expand Up @@ -362,6 +398,7 @@ private fun MealCards(
meal: Meal,
onNextDay: () -> Unit,
onPreviousDay: () -> Unit,
onRefresh: () -> Unit,
) {
val pagerState = rememberPagerState(
initialPage = getProperMeal(),
Expand Down Expand Up @@ -444,6 +481,7 @@ private fun MealCards(
)
}
},
onRefresh = onRefresh,
)
}
}
Expand Down Expand Up @@ -479,6 +517,7 @@ private fun MealCard(
kcalOfDinner: String?,
onSwipeToLeft: () -> Unit,
onSwipeToRight: () -> Unit,
onRefresh: () -> Unit,
) {
var dragDirection: DragDirection? by remember { mutableStateOf(null) }

Expand Down Expand Up @@ -519,14 +558,24 @@ private fun MealCard(
),
elevation = CardDefaults.outlinedCardElevation(defaultElevation = ShadowDefaults.SmallElevation),
) {
val dishes = when (currentCardType) {
BREAKFAST -> breakfast
LUNCH -> lunch
DINNER -> dinner
}
if (dishes.isEmpty()) {
TextButton(
modifier = Modifier.fillMaxWidth(),
onClick = onRefresh,
colors = ButtonDefaults.textGrayButtonColors(),
) {
Text(text = stringResource(id = R.string.refresh))
}
}
Dishes(
modifier = Modifier.fillMaxWidth(),
iconRes = currentCardType.iconRes,
dishes = when (currentCardType) {
BREAKFAST -> breakfast
LUNCH -> lunch
DINNER -> dinner
},
dishes = dishes,
kcal = when (currentCardType) {
BREAKFAST -> kcalOfBreakfast
LUNCH -> kcalOfLunch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ internal class HomeViewModel @Inject constructor(
) {
init {
fetchWhetherNewNoticeExists()
updateMeal(date = stateFlow.value.selectedDate)
updateDate(date = stateFlow.value.selectedDate)
}

override fun processIntent(intent: HomeIntent) {
when (intent) {
is HomeIntent.UpdateSelectedDate -> updateMeal(intent.selectedDate)
is HomeIntent.UpdateSelectedDate -> updateDate(intent.selectedDate)
HomeIntent.UpdateMeal -> updateMeal()
}
}

Expand All @@ -44,7 +45,7 @@ internal class HomeViewModel @Inject constructor(
}
}

private fun updateMeal(date: LocalDate) {
private fun updateDate(date: LocalDate) {
viewModelScope.launch(Dispatchers.IO) {
runCatching {
mealRepository.fetchMeal(date)
Expand All @@ -62,6 +63,27 @@ internal class HomeViewModel @Inject constructor(
}
}
}

private fun updateMeal() =
viewModelScope.launch(Dispatchers.IO) {
println("LOGLOG1")
val capturedDate = stateFlow.value.selectedDate
runCatching {
mealRepository.updateMeal(capturedDate)
}.onSuccess { meal ->
reduce(
newState = stateFlow.value.copy(
selectedDate = capturedDate,
currentMeal = meal,
),
)
postSideEffect(HomeSideEffect.MealUpdated)
}.onFailure {
postSideEffect(HomeSideEffect.MealUpdateFailed)
}.also {
println("LOGLOG ${it.isSuccess}")
}
}
}

internal data class HomeUiState(
Expand Down Expand Up @@ -94,10 +116,13 @@ internal data class HomeUiState(

internal sealed class HomeIntent : Intent() {
class UpdateSelectedDate(val selectedDate: LocalDate) : HomeIntent()
data object UpdateMeal : HomeIntent()
}

internal sealed class HomeSideEffect : SideEffect() {
data object CannotFindMeal : HomeSideEffect()
data object MealUpdated : HomeSideEffect()
data object MealUpdateFailed : HomeSideEffect()
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ internal fun SignUpSetPasswordScreen(
val (shouldShowQuitSignUpDialog, onShouldShowQuitSignUpDialogChange) = remember {
mutableStateOf(false)
}

val (isPasswordInvalid, onChangeIsPasswordInvalid) = remember(
uiState.password,
uiState.passwordRepeat
) {
mutableStateOf(false)
}

if (shouldShowQuitSignUpDialog) {
AlertDialog(
title = { Text(text = stringResource(id = R.string.sign_up)) },
Expand Down Expand Up @@ -90,6 +98,13 @@ internal fun SignUpSetPasswordScreen(
message = context.getString(R.string.sign_up_set_password_error_password_mismatch),
)

SignUpSideEffect.InvalidPassword -> {
toast.showErrorToast(
message = context.getString(R.string.sign_up_set_password_invalid_password),
)
onChangeIsPasswordInvalid(true)
}

else -> {/* explicit blank */
}
}
Expand Down Expand Up @@ -167,4 +182,4 @@ internal fun SignUpSetPasswordScreen(
BackHandler {
onShouldShowQuitSignUpDialogChange(true)
}
}
}
Loading

0 comments on commit 2d942c3

Please sign in to comment.