Skip to content

Conversation

@dmp100
Copy link
Collaborator

@dmp100 dmp100 commented Nov 28, 2025

5차 과제 PR - Flow 기반 입력 검증 및 코루틴 기반 API 호출 구현

Callback 코드를 코루틴으로 변환

  • 기존에 enqueue 쓰던거 다 viewModelScope.launch로 변경

에러 처리 정리

  • 네트워크 끊기면 → "네트워크 연결 확인해주세요"
  • 비밀번호 틀리면 → "아이디 또는 비밀번호가 틀렸습니다"
  • 사용자 없으면 → "존재하지 않는 사용자입니다"

변경사항

  1. Flow 관련 (LoginViewModel)

LoginUiState.kt - 검증 상태 필드 추가
LoginViewModel.kt - Flow로 실시간 검증 구현
LoginScreen.kt - Flow 상태를 UI에 표시

  1. 코루틴 관련 (API 호출)
  • AuthService.kt - suspend 함수로 변경
  • ReqresService.kt - suspend 함수로 변경
  • LoginViewModel.kt - Callback → 코루틴 (loginWithApi 함수)
  • MyViewModel.kt - Callback → 코루틴 (fetchUserFromServer 함수)
  • SignUpViewModel.kt - Callback → 코루틴 (signUpWithApi 함수)

주요 변경 사항

  • Callback 방식에서 코루틴 방식 적용
2025-11-28.18.00.09.mov

- Reqres GET /users API 연동
- ResponseReqresUsersDto, ReqresUser DTO 추가
- ReqresService 및 ReqresApiFactory 생성
- HomeItem에 UserProfile 타입 추가
- HomeViewModel에서 API 호출 및 에러 처리 로직 구현
- UserProfileComponent 컴포넌트 추가 (Coil 이미지 로딩)
- HomeScreen에 UserProfile 타입 렌더링 로직 추가
Copy link

@ShinHyeongcheol ShinHyeongcheol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

솝커톤에 합세까지 바빴을텐데 수고하셨습니다!!
7셈 심화인 리팩도 진행하실거죠?ㅎㅎㅋㅋㅋㅋ

*/
viewModelScope.launch {
// 로딩 시작
_uiState.value = _uiState.value.copy(isLoading = true, errorMessage = null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy를 바로 사용하지 말고 update라는게 있는데, 둘의 차이점을 알아보면 좋을 것 같아요!!

@SerialName("message")
val message: String,
@SerialName("data")
val data: ResponseUserDataDto

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전에 코리조에게 코리 받았던 내용 중 하나인데, 솝커톤때도 사용했듯이 Response 같은 경우의 BaseResponse를 만드는 것도 하나의 좋은 방법인것 같아요!!
success, code, message, data의 구조로 data만 병경이 되어서 사용하는데, 이 부분을 저는 제네릭으로 하여 구성했었습니다.

* - collectAsState()가 변경을 감지
* - 이 Composable이 자동으로 리컴포지션됨
*/
val uiState by viewModel.uiState.collectAsState()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 세미나에서 잠깐 다루었던것 같은데, collectAsState와 collectAsStateWithLifecycle의 차이점을 알아보면 좋을 것 같아요.

Copy link

@sohee6989 sohee6989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!!
조금 더 읽고 코리 더 남기겠습니다 :)


@Preview(showBackground = true)
@Composable
fun UserProfileComponentPreview() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프리뷰 코드는 private 붙여주시는거 어떠세요??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants