-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: 학생 인증 레포지토리 정의 * feat: 학교 레포지토리 임시 정의 * feat: 학교 인증 화면 뷰모델 구현 * test: 학생 인증 화면 뷰모델 테스트 작성 * refactor: LiveData stateFlow 로 리팩터링 * feat: StudentVerificationActivity 생성 * feat: 학생 인증 화면 xml 그리기 * feat: 재사용 가능한 문장 검증 로직 생성 및 테스트 * feat: 학생 인증 검증 로직 생성 및 테스트 * feat: SchoolId Long 으로 변경 * feat: 인증 코드 확인 요청 기능 작성 * feat: 코드 형식 확인 인증 * feat: 임시 학교 인증 화면 이동 * refator: ktlint check * refator: 클래스 및 변수 명 변경 * fix: 화면 회전 시 학교 이메일을 재요청하지 않음 * refactor: 사용하지않는 코드 주석 제거 * refactor: repeatOnStartedState util 추가 * refactor: StudentVerificationActivity 전체 리팩터링 * refactor: Students 를 Student 로 통일 * refactor: State 성공 시 처리 함수 분리 및 네이밍 변경 * refactor: 글자 30개까지 입력으로 변경 * feat: sealed interface 학생 인증 이벤트 추가 * refactor: 학생 인증 ViewModel 리팩터링 * test: 학생 인증 이벤트 테스트 추가 * refactor: 사용하지 않는 뷰 제거 * test: 학생 인증 코드 예외 테스트 추가 * feat: Event observing 추가 * refactor: 테스트 리팩터링 * refactor: 테스트 네이밍 리팩터링 * refactor: turbine 추가 및 sharedFlow 테스트 리팩터링 * refactor: Text 검증 테스트 네이밍 및 구조 리팩터링 * refactor: TextValidator 생성 로직 통일 * refactor: given when 함수 분리 및 테스트 리팩터링 * refactor: seal interface 는 isExactlyInstanceOf 로 테스트
- Loading branch information
1 parent
09ba36b
commit 468f00e
Showing
24 changed files
with
946 additions
and
5 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
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
9 changes: 9 additions & 0 deletions
9
android/festago/app/src/main/java/com/festago/festago/data/dto/SendVerificationRequest.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,9 @@ | ||
package com.festago.festago.data.dto | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SendVerificationRequest( | ||
val userName: String, | ||
val schoolId: Int, | ||
) |
11 changes: 11 additions & 0 deletions
11
.../festago/app/src/main/java/com/festago/festago/data/repository/SchoolDefaultRepository.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,11 @@ | ||
package com.festago.festago.data.repository | ||
|
||
import com.festago.festago.repository.SchoolRepository | ||
|
||
class SchoolDefaultRepository() : SchoolRepository { | ||
|
||
override suspend fun loadSchoolEmail(schoolId: Long): Result<String> { | ||
// TODO: API 연동 작업 필요 | ||
return Result.success("festago.com") | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...src/main/java/com/festago/festago/data/repository/StudentVerificationDefaultRepository.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,20 @@ | ||
package com.festago.festago.data.repository | ||
|
||
import com.festago.festago.data.service.StudentVerificationRetrofitService | ||
import com.festago.festago.model.StudentVerificationCode | ||
import com.festago.festago.repository.StudentVerificationRepository | ||
|
||
class StudentVerificationDefaultRepository( | ||
private val studentVerificationRetrofitService: StudentVerificationRetrofitService, | ||
) : StudentVerificationRepository { | ||
|
||
override suspend fun sendVerificationCode(userName: String, schoolId: Long): Result<Unit> { | ||
// TODO: API 연동 작업 필요 | ||
return Result.success(Unit) | ||
} | ||
|
||
override suspend fun requestVerificationCodeConfirm(code: StudentVerificationCode): Result<Unit> { | ||
// TODO: API 연동 작업 필요 | ||
return Result.success(Unit) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../app/src/main/java/com/festago/festago/data/service/StudentVerificationRetrofitService.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,13 @@ | ||
package com.festago.festago.data.service | ||
|
||
import com.festago.festago.data.dto.SendVerificationRequest | ||
import retrofit2.Response | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface StudentVerificationRetrofitService { | ||
@POST("/students/send-verification") | ||
suspend fun sendVerificationCode( | ||
@Body sendVerificationRequest: SendVerificationRequest, | ||
): Response<Unit> | ||
} |
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
99 changes: 99 additions & 0 deletions
99
...va/com/festago/festago/presentation/ui/studentverification/StudentVerificationActivity.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,99 @@ | ||
package com.festago.festago.presentation.ui.studentverification | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.festago.festago.R | ||
import com.festago.festago.databinding.ActivityStudentVerificationBinding | ||
import com.festago.festago.presentation.ui.FestagoViewModelFactory | ||
import com.festago.festago.presentation.util.repeatOnStarted | ||
import java.time.LocalTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
class StudentVerificationActivity : AppCompatActivity() { | ||
|
||
private val binding: ActivityStudentVerificationBinding by lazy { | ||
ActivityStudentVerificationBinding.inflate(layoutInflater) | ||
} | ||
|
||
private val vm: StudentVerificationViewModel by viewModels { FestagoViewModelFactory } | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
initBinding() | ||
initView() | ||
initObserve() | ||
} | ||
|
||
private fun initBinding() { | ||
setContentView(binding.root) | ||
binding.lifecycleOwner = this | ||
binding.vm = vm | ||
} | ||
|
||
private fun initView() { | ||
val schoolId = intent.getLongExtra(KEY_SCHOOL_ID, -1L) | ||
vm.loadSchoolEmail(schoolId) | ||
initRequestVerificationCodeBtn(schoolId) | ||
} | ||
|
||
private fun initRequestVerificationCodeBtn(schoolId: Long) { | ||
binding.btnRequestVerificationCode.setOnClickListener { | ||
vm.sendVerificationCode(binding.tieVerificationCode.text.toString(), schoolId) | ||
} | ||
} | ||
|
||
private fun initObserve() { | ||
repeatOnStarted { | ||
vm.uiState.collect { uiState -> | ||
handleUiState(uiState) | ||
} | ||
} | ||
repeatOnStarted { | ||
vm.event.collect { event -> | ||
handleEvent(event) | ||
} | ||
} | ||
} | ||
|
||
private fun handleUiState(uiState: StudentVerificationUiState) { | ||
binding.uiState = uiState | ||
when (uiState) { | ||
is StudentVerificationUiState.Success -> handleSuccess(uiState) | ||
is StudentVerificationUiState.Loading, StudentVerificationUiState.Error -> Unit | ||
} | ||
} | ||
|
||
private fun handleSuccess(uiState: StudentVerificationUiState.Success) { | ||
binding.tvSchoolEmail.text = | ||
getString(R.string.student_verification_tv_email_format, uiState.schoolEmail) | ||
|
||
val format = | ||
DateTimeFormatter.ofPattern(getString(R.string.student_verification_tv_timer_format)) | ||
binding.tvTimerVerificationCode.text = LocalTime.ofSecondOfDay(uiState.remainTime.toLong()) | ||
.format(format) | ||
|
||
binding.btnVerificationConfirm.isEnabled = uiState.isValidateCode | ||
} | ||
|
||
private fun handleEvent(event: StudentVerificationEvent) { | ||
when (event) { | ||
is StudentVerificationEvent.VerificationSuccess -> Unit | ||
is StudentVerificationEvent.VerificationFailure -> Unit | ||
is StudentVerificationEvent.CodeTimeOut -> Unit | ||
} | ||
} | ||
|
||
companion object { | ||
|
||
private const val KEY_SCHOOL_ID = "KEY_SCHOOL_ID" | ||
|
||
fun getIntent(context: Context, schoolId: Long): Intent { | ||
return Intent(context, StudentVerificationActivity::class.java).apply { | ||
putExtra(KEY_SCHOOL_ID, schoolId) | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../java/com/festago/festago/presentation/ui/studentverification/StudentVerificationEvent.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,7 @@ | ||
package com.festago.festago.presentation.ui.studentverification | ||
|
||
sealed interface StudentVerificationEvent { | ||
object CodeTimeOut : StudentVerificationEvent | ||
object VerificationFailure : StudentVerificationEvent | ||
object VerificationSuccess : StudentVerificationEvent | ||
} |
17 changes: 17 additions & 0 deletions
17
...ava/com/festago/festago/presentation/ui/studentverification/StudentVerificationUiState.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,17 @@ | ||
package com.festago.festago.presentation.ui.studentverification | ||
|
||
sealed interface StudentVerificationUiState { | ||
object Loading : StudentVerificationUiState | ||
|
||
data class Success( | ||
val schoolEmail: String, | ||
val remainTime: Int, | ||
val isValidateCode: Boolean = false, | ||
) : StudentVerificationUiState | ||
|
||
object Error : StudentVerificationUiState | ||
|
||
val shouldShowSuccess get() = this is Success | ||
val shouldShowLoading get() = this is Loading | ||
val shouldShowError get() = this is Error | ||
} |
Oops, something went wrong.