-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from 6QuizOnTheBlock/and/feat#293-student_rel…
…ay_create And/feat#293 학생 이어 달리기 생성
- Loading branch information
Showing
15 changed files
with
260 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
android/data/src/main/java/com/sixkids/data/model/request/RelayCreateRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.sixkids.data.model.request | ||
|
||
data class RelayCreateRequest( | ||
val organizationId: Int, | ||
val question: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
android/domain/src/main/java/com/sixkids/domain/usecase/relay/CreateRelayUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.sixkids.domain.usecase.relay | ||
|
||
import com.sixkids.domain.repository.RelayRepository | ||
import javax.inject.Inject | ||
|
||
class CreateRelayUseCase @Inject constructor( | ||
private val relayRepository: RelayRepository | ||
){ | ||
suspend operator fun invoke(organizationId: Int, question: String) = runCatching { | ||
relayRepository.createRelay(organizationId, question) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ature/student/relay/src/main/java/com/sixkids/student/relay/create/RelayCreateContract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.sixkids.student.relay.create | ||
|
||
import com.sixkids.ui.SnackbarToken | ||
import com.sixkids.ui.base.SideEffect | ||
import com.sixkids.ui.base.UiState | ||
|
||
data class RelayCreateState( | ||
val isLoading: Boolean = false, | ||
val question: String = "", | ||
val orgId: Int = -1 | ||
) : UiState | ||
|
||
sealed interface RelayCreateEffect: SideEffect { | ||
data class NavigateToRelayResult(val newRelayId: Long) : RelayCreateEffect | ||
data class OnShowSnackBar(val tkn : SnackbarToken) : RelayCreateEffect | ||
} |
111 changes: 111 additions & 0 deletions
111
...feature/student/relay/src/main/java/com/sixkids/student/relay/create/RelayCreateScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.sixkids.student.relay.create | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import com.sixkids.designsystem.component.button.UlbanFilledButton | ||
import com.sixkids.designsystem.component.screen.UlbanTopSection | ||
import com.sixkids.designsystem.component.textfield.UlbanUnderLineTextField | ||
import com.sixkids.designsystem.theme.UlbanTheme | ||
import com.sixkids.designsystem.theme.UlbanTypography | ||
import com.sixkids.student.relay.R | ||
import com.sixkids.ui.SnackbarToken | ||
import com.sixkids.ui.extension.collectWithLifecycle | ||
|
||
@Composable | ||
fun RelayCreateRoute( | ||
viewModel: RelayCreateViewModel = hiltViewModel(), | ||
navigateToRelayResult: (Long) -> Unit, | ||
onBackClick: () -> Unit, | ||
onShowSnackBar: (SnackbarToken) -> Unit | ||
) { | ||
val uiState = viewModel.uiState.collectAsStateWithLifecycle().value | ||
|
||
viewModel.sideEffect.collectWithLifecycle { sideEffect -> | ||
when (sideEffect) { | ||
is RelayCreateEffect.NavigateToRelayResult -> navigateToRelayResult(sideEffect.newRelayId) | ||
is RelayCreateEffect.OnShowSnackBar -> onShowSnackBar(sideEffect.tkn) | ||
} | ||
} | ||
|
||
LaunchedEffect(key1 = Unit) { | ||
viewModel.init() | ||
} | ||
|
||
RelayCreateScreen( | ||
uiState = uiState, | ||
onNewRelayClick = viewModel::newRelayClick, | ||
onBackClick = onBackClick, | ||
onUpdateQuestion = viewModel::updateQuestion, | ||
) | ||
|
||
} | ||
|
||
@Composable | ||
fun RelayCreateScreen( | ||
paddingValues: PaddingValues = PaddingValues(20.dp), | ||
uiState: RelayCreateState = RelayCreateState(), | ||
onNewRelayClick: () -> Unit = {}, | ||
onBackClick: () -> Unit = {}, | ||
onUpdateQuestion: (String) -> Unit = {} | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(paddingValues) | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize(), | ||
horizontalAlignment = Alignment.Start, | ||
) { | ||
UlbanTopSection(stringResource(id = R.string.relay_create_topsection), onBackClick) | ||
|
||
Spacer(modifier = Modifier.height(36.dp)) | ||
|
||
Text( | ||
text = stringResource(R.string.relay_create_question), | ||
style = UlbanTypography.bodyLarge, | ||
modifier = Modifier.padding(top = 10.dp, bottom = 10.dp) | ||
) | ||
UlbanUnderLineTextField( | ||
text = uiState.question, | ||
hint = stringResource(R.string.relay_create_question_hint), | ||
onTextChange = onUpdateQuestion, | ||
onIconClick = { | ||
onUpdateQuestion("") | ||
} | ||
) | ||
|
||
Spacer(modifier = Modifier.weight(1f)) | ||
|
||
UlbanFilledButton( | ||
text = stringResource(R.string.relay_create_create), | ||
onClick = { onNewRelayClick() }, | ||
modifier = Modifier.fillMaxWidth()) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview(showBackground = true) | ||
fun RelayCreateScreenPreview() { | ||
UlbanTheme { | ||
RelayCreateScreen() | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ture/student/relay/src/main/java/com/sixkids/student/relay/create/RelayCreateViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.sixkids.student.relay.create | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.viewModelScope | ||
import com.sixkids.domain.usecase.organization.GetSelectedOrganizationIdUseCase | ||
import com.sixkids.domain.usecase.relay.CreateRelayUseCase | ||
import com.sixkids.ui.SnackbarToken | ||
import com.sixkids.ui.base.BaseViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
private const val TAG = "D107" | ||
@HiltViewModel | ||
class RelayCreateViewModel @Inject constructor( | ||
private val getSelectedOrganizationIdUseCase: GetSelectedOrganizationIdUseCase, | ||
private val createRelayUseCase: CreateRelayUseCase | ||
) : BaseViewModel<RelayCreateState, RelayCreateEffect>(RelayCreateState()) { | ||
|
||
fun init() { | ||
viewModelScope.launch { | ||
getSelectedOrganizationIdUseCase() | ||
.onSuccess { | ||
intent { copy(orgId = it) } | ||
}.onFailure { | ||
postSideEffect(RelayCreateEffect.OnShowSnackBar(SnackbarToken("학급 정보를 불러오는데 실패했습니다"))) | ||
} | ||
} | ||
} | ||
|
||
fun newRelayClick() { | ||
viewModelScope.launch { | ||
intent { copy(isLoading = true) } | ||
if (uiState.value.orgId == -1){ | ||
init() | ||
}else{ | ||
Log.d(TAG, "newRelayClick: ${uiState.value.question} ${uiState.value.orgId}") | ||
createRelayUseCase(uiState.value.orgId, uiState.value.question) | ||
.onSuccess { | ||
postSideEffect(RelayCreateEffect.NavigateToRelayResult(it)) | ||
}.onFailure { | ||
postSideEffect(RelayCreateEffect.OnShowSnackBar(SnackbarToken("이어 달리기 생성에 실패했습니다"))) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun updateQuestion(question: String) { | ||
intent { copy(question = question) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.