Skip to content

Commit

Permalink
Merge pull request #114 from uswLectureEvaluation/feature/#113-write-…
Browse files Browse the repository at this point in the history
…evaluation

Feature/#113 write evaluation
  • Loading branch information
jinukeu authored Jan 24, 2024
2 parents d783de9 + 88787df commit 06a2041
Show file tree
Hide file tree
Showing 38 changed files with 609 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ fun SuwikiExamReviewContainer(
modifier: Modifier = Modifier,
difficulty: String,
examType: String,
semester: String,
examInfo: String,
content: String,
isAuthor: Boolean = false,
onClickButton: () -> Unit,
Expand All @@ -53,12 +55,12 @@ fun SuwikiExamReviewContainer(
}
SuwikiBadge(
color = BadgeColor.Gray,
text = stringResource(id = R.string.word_semester),
text = semester,
)
Spacer(modifier = Modifier.width(6.dp))
SuwikiBadge(
color = BadgeColor.Gray,
text = stringResource(id = R.string.word_type_exam),
text = examType,
)
Spacer(modifier = Modifier.weight(1f))
SuwikiContainedSmallButton(text = buttonText, onClick = onClickButton)
Expand Down Expand Up @@ -90,7 +92,7 @@ fun SuwikiExamReviewContainer(
color = Gray95,
)
Text(
text = examType,
text = examInfo,
style = SuwikiTheme.typography.caption1,
color = Black,
)
Expand All @@ -112,16 +114,20 @@ fun SuwikiExamReviewContainerPreview() {
SuwikiExamReviewContainer(
isAuthor = false,
difficulty = "어려움",
examType = "응용,실습,과제,PPT",
examInfo = "응용,실습,과제,PPT",
content = "거의 한 학기 팀플하시는데... 팀원 잘 만나면 잘 모르겠네요. 굉장히 오픈 마인드시긴해요.",
onClickButton = {},
examType = "중간고사",
semester = "2023-1",
)
SuwikiExamReviewContainer(
isAuthor = true,
difficulty = "어려움",
examType = "응용,실습,과제,PPT",
examType = "중간고사",
content = "거의 한 학기 팀플하시는데... 팀원 잘 만나면 잘 모르겠네요. 굉장히 오픈 마인드시긴해요.",
onClickButton = {},
semester = "2023-1",
examInfo = "응용,실습,과제,PPT",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ data class MyLectureEvaluation(
val id: Long = 0,
val lectureInfo: LectureInfo = LectureInfo(),
val selectedSemester: String = "",
val totalAvg: Float = 0f, // 총점
val satisfaction: Float = 0f, // 만족도
val learning: Float = 0f, // 배움지수
val honey: Float = 0f, // 꿀강지수
val totalAvg: Float = 2.5f, // 총점
val satisfaction: Float = 2.5f, // 만족도
val learning: Float = 2.5f, // 배움지수
val honey: Float = 2.5f, // 꿀강지수
val team: Int = 0, // 조별모임 유무(없음 == 0, 있음 == 1)
val difficulty: Int = 0, // 학점 잘주는가? (까다로움 == 0, 보통 == 1, 학점느님 ==2)
val homework: Int = 0, // 과제양 (없음 ==0, 보통 == 1, 많음 == 2)
val difficulty: Int = 1, // 학점 잘주는가? (까다로움 == 0, 보통 == 1, 학점느님 ==2)
val homework: Int = 1, // 과제양 (없음 ==0, 보통 == 1, 많음 == 2)
val content: String = "",
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.suwiki.data.lectureevaluation.editor.datasource
interface RemoteLectureEditorDataSource {

suspend fun postLectureEvaluation(
lectureId: Long,
lectureName: String,
professor: String,
selectedSemester: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class LectureEditorRepositoryImpl @Inject constructor(
private val lectureEditorDataSource: RemoteLectureEditorDataSource,
) : LectureEditorRepository {
override suspend fun postLectureEvaluation(
lectureId: Long,
lectureName: String,
professor: String,
selectedSemester: String,
Expand All @@ -20,6 +21,7 @@ class LectureEditorRepositoryImpl @Inject constructor(
content: String,
) {
lectureEditorDataSource.postLectureEvaluation(
lectureId = lectureId,
lectureName = lectureName,
professor = professor,
selectedSemester = selectedSemester,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.suwiki.data.lectureevaluation.viewerreporter.datasource
interface RemoteExamReportDataSource {

suspend fun reportExam(
evaluateIdx: Long,
examIdx: Long,
content: String = "",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class ExamReportRepositoryImpl @Inject constructor(
private val remoteExamReportDataSource: RemoteExamReportDataSource,
) : ExamReportRepository {

override suspend fun reportExam(evaluateIdx: Long, content: String) {
override suspend fun reportExam(examIdx: Long, content: String) {
remoteExamReportDataSource.reportExam(
evaluateIdx = evaluateIdx,
examIdx = examIdx,
content = content,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.suwiki.domain.lectureevaluation.editor.repository
interface LectureEditorRepository {

suspend fun postLectureEvaluation(
lectureId: Long,
lectureName: String,
professor: String,
selectedSemester: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PostLectureEvaluationUseCase @Inject constructor(
suspend operator fun invoke(param: Param): Result<Unit> = runCatchingIgnoreCancelled {
param.run {
lectureEditorRepository.postLectureEvaluation(
lectureId = id,
lectureName = lectureName,
professor = professor,
selectedSemester = selectedSemester,
Expand All @@ -25,6 +26,7 @@ class PostLectureEvaluationUseCase @Inject constructor(
}

data class Param(
val id: Long,
val lectureName: String,
val professor: String,
val selectedSemester: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class UpdateLectureEvaluationUseCase @Inject constructor(

data class Param(
val lectureId: Long,
val professor: String,
val selectedSemester: String,
val satisfaction: Float,
val learning: Float,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.suwiki.domain.lectureevaluation.viewerreporter.repository
interface ExamReportRepository {

suspend fun reportExam(
evaluateIdx: Long,
examIdx: Long,
content: String = "",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import javax.inject.Inject
class ReportExamUseCase @Inject constructor(
private val examReportRepository: ExamReportRepository,
) {
suspend operator fun invoke(evaluateIdx: Long): Result<Unit> = runCatchingIgnoreCancelled {
examReportRepository.reportExam(evaluateIdx = evaluateIdx)
suspend operator fun invoke(examIdx: Long): Result<Unit> = runCatchingIgnoreCancelled {
examReportRepository.reportExam(examIdx = examIdx)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import com.suwiki.core.model.enums.ExamLevel
import com.suwiki.core.model.enums.ExamType
import com.suwiki.core.model.lectureevaluation.exam.MyExamEvaluation
import com.suwiki.core.ui.extension.decodeFromUri
import com.suwiki.domain.lectureevaluation.editor.usecase.exam.PostExamEvaluationUseCase
import com.suwiki.domain.lectureevaluation.editor.usecase.exam.UpdateExamEvaluationUseCase
import com.suwiki.feature.lectureevaluation.editor.navigation.MyEvaluationEditRoute
import com.suwiki.feature.lectureevaluation.editor.navigation.EvaluationEditorRoute
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.toPersistentList
import kotlinx.serialization.json.Json
Expand All @@ -23,15 +24,17 @@ import org.orbitmvi.orbit.viewmodel.container
import javax.inject.Inject

@HiltViewModel
class MyExamEvaluationEditViewModel @Inject constructor(
class ExamEvaluationEditorViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
val postExamEvaluationUseCase: PostExamEvaluationUseCase,
val updateExamEvaluationUseCase: UpdateExamEvaluationUseCase,
) : ContainerHost<MyExamEvaluationEditState, MyExamEvaluationEditSideEffect>, ViewModel() {
override val container: Container<MyExamEvaluationEditState, MyExamEvaluationEditSideEffect> =
container(MyExamEvaluationEditState())
) : ContainerHost<ExamEvaluationEditorState, ExamEvaluationEditorSideEffect>, ViewModel() {
override val container: Container<ExamEvaluationEditorState, ExamEvaluationEditorSideEffect> =
container(ExamEvaluationEditorState())

private val myExamEvaluation = savedStateHandle.get<String>(MyEvaluationEditRoute.myExamEvaluation)!!
private val myExamEvaluation = savedStateHandle.get<String>(EvaluationEditorRoute.examEvaluation)!!
private val myExamEvaluationItem: MyExamEvaluation = Json.decodeFromUri(myExamEvaluation)
private val isEditMode = myExamEvaluationItem.content.isNotEmpty()

suspend fun initData() = intent {
showLoadingScreen()
Expand Down Expand Up @@ -60,7 +63,52 @@ class MyExamEvaluationEditViewModel @Inject constructor(
}
hideLoadingScreen()
}
fun updateExamEvaluation() = intent {

fun postOrUpdateExamEvaluation() = intent {
if (state.examEvaluation.length < 30) {
postSideEffect(ExamEvaluationEditorSideEffect.ShowInputMoreTextToast)
return@intent
}

if (state.selectedSemester.isNullOrEmpty()) {
postSideEffect(ExamEvaluationEditorSideEffect.ShowSelectSemesterToast)
return@intent
}

if (state.selectedExamType.isNullOrEmpty()) {
postSideEffect(ExamEvaluationEditorSideEffect.ShowSelectExamTypeToast)
return@intent
}

if (isEditMode) {
updateExamEvaluation()
} else {
postExamEvaluation()
}
}

private fun postExamEvaluation() = intent {
postExamEvaluationUseCase(
PostExamEvaluationUseCase.Param(
lectureId = myExamEvaluationItem.id,
lectureName = myExamEvaluationItem.lectureName,
professor = myExamEvaluationItem.professor,
selectedSemester = state.selectedSemester,
examInfo = state.examInfo.filter { it.isNotBlank() }.joinToString(", "),
examType = state.selectedExamType,
examDifficulty = state.examLevel!!.value,
content = state.examEvaluation,
),
)
.onSuccess {
popBackStack()
}
.onFailure {
postSideEffect(ExamEvaluationEditorSideEffect.HandleException(it))
}
}

private fun updateExamEvaluation() = intent {
updateExamEvaluationUseCase(
UpdateExamEvaluationUseCase.Param(
lectureId = myExamEvaluationItem.id,
Expand All @@ -75,7 +123,7 @@ class MyExamEvaluationEditViewModel @Inject constructor(
popBackStack()
}
.onFailure {
postSideEffect(MyExamEvaluationEditSideEffect.HandleException(it))
postSideEffect(ExamEvaluationEditorSideEffect.HandleException(it))
}
}

Expand Down Expand Up @@ -120,5 +168,5 @@ class MyExamEvaluationEditViewModel @Inject constructor(
fun showExamTypeBottomSheet() = intent { reduce { state.copy(showExamTypeBottomSheet = true) } }
fun hideExamTypeBottomSheet() = intent { reduce { state.copy(showExamTypeBottomSheet = false) } }

fun popBackStack() = intent { postSideEffect(MyExamEvaluationEditSideEffect.PopBackStack) }
fun popBackStack() = intent { postSideEffect(ExamEvaluationEditorSideEffect.PopBackStack) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.suwiki.core.model.enums.ExamLevel
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf

data class MyExamEvaluationEditState(
data class ExamEvaluationEditorState(
val isLoading: Boolean = false,
val point: Int = 0,
val semesterList: PersistentList<String> = persistentListOf(""),
Expand All @@ -17,10 +17,17 @@ data class MyExamEvaluationEditState(
val examInfo: PersistentList<String> = persistentListOf(),
val showSemesterBottomSheet: Boolean = false,
val showExamTypeBottomSheet: Boolean = false,
)
) {
val buttonEnabled = examLevel != null &&
examInfo.isNotEmpty() &&
examEvaluation.isNotEmpty()
}

sealed interface MyExamEvaluationEditSideEffect {
data object PopBackStack : MyExamEvaluationEditSideEffect
data object ShowMyExamEvaluationDeleteToast : MyExamEvaluationEditSideEffect
data class HandleException(val throwable: Throwable) : MyExamEvaluationEditSideEffect
sealed interface ExamEvaluationEditorSideEffect {
data object ShowInputMoreTextToast : ExamEvaluationEditorSideEffect
data object ShowSelectSemesterToast : ExamEvaluationEditorSideEffect
data object ShowSelectExamTypeToast : ExamEvaluationEditorSideEffect
data object PopBackStack : ExamEvaluationEditorSideEffect
data object ShowExamEvaluationDeleteToast : ExamEvaluationEditorSideEffect
data class HandleException(val throwable: Throwable) : ExamEvaluationEditorSideEffect
}
Loading

0 comments on commit 06a2041

Please sign in to comment.