-
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.
[FEAT/#46] ocr post user check 서버통신 로직 구현
- Loading branch information
Showing
13 changed files
with
298 additions
and
8 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
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/keyneez/data/model/request/RequestPostStudentUserCheckDto.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.keyneez.data.model.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RequestPostStudentUserCheckDto( | ||
@SerialName("user_school") | ||
val school: String, | ||
@SerialName("user_name") | ||
val name: String, | ||
@SerialName("user_ocr") | ||
val ocrImg: String, | ||
@SerialName("ocr_dir") | ||
val ocrDir: Boolean | ||
) |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/keyneez/data/model/request/RequestPostYouthUserCheckDto.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.keyneez.data.model.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RequestPostYouthUserCheckDto( | ||
@SerialName("user_name") | ||
val name : String, | ||
@SerialName("user_birth") | ||
val birth : String, | ||
@SerialName("user_ocr") | ||
val ocrImg: String, | ||
@SerialName("ocr_dir") | ||
val ocrDir: Boolean | ||
) |
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/keyneez/data/model/response/ResponsePostUserCheckDto.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,46 @@ | ||
package com.keyneez.data.model.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponsePostUserCheckDto( | ||
@SerialName("user_key") | ||
val key: Int, | ||
@SerialName("user_name") | ||
val name: String, | ||
@SerialName("user_age") | ||
val age: String?, | ||
@SerialName("user_gender") | ||
val gender: String?, | ||
@SerialName("user_birth") | ||
val birthDate: String?, | ||
@SerialName("user_school") | ||
val school: String?, | ||
@SerialName("user_character") | ||
val character: Int?, | ||
@SerialName("user_password") | ||
val password: String?, | ||
@SerialName("user_ocr") | ||
val ocrImg: String?, | ||
@SerialName("ocr_dir") | ||
val ocrDir: Boolean?, | ||
@SerialName("user_benefit") | ||
val benefit: Boolean?, | ||
val Characters: Character? | ||
) { | ||
@Serializable | ||
data class Character( | ||
@SerialName("character_key") | ||
val key: Int, | ||
val inter: String?, | ||
val dispo: String?, | ||
val character: String?, | ||
@SerialName("character_img") | ||
val img: String?, | ||
@SerialName("character_desc") | ||
val description: String?, | ||
@SerialName("test_img") | ||
val testImg: 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
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
115 changes: 115 additions & 0 deletions
115
app/src/main/java/com/keyneez/presentation/ocr/dialog/OcrResultViewModel.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,115 @@ | ||
package com.keyneez.presentation.ocr.dialog | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.keyneez.data.model.request.RequestPostStudentUserCheckDto | ||
import com.keyneez.data.model.request.RequestPostYouthUserCheckDto | ||
import com.keyneez.data.repository.UserRepository | ||
import com.keyneez.util.UiState | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import retrofit2.HttpException | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class OcrResultViewModel @Inject constructor( | ||
private val userRepository: UserRepository | ||
) : ViewModel() { | ||
private val _stateMessage = MutableLiveData<UiState>() | ||
val stateMessage: LiveData<UiState> | ||
get() = _stateMessage | ||
|
||
fun postUserCheck( | ||
isStudent: Boolean, | ||
name: String, | ||
subEntry: String, | ||
img: String, | ||
isVertical: Boolean | ||
) { | ||
// 학생증인 경우 | ||
if (isStudent) { | ||
viewModelScope.launch { | ||
userRepository.postStudentUserCheck( | ||
RequestPostStudentUserCheckDto( | ||
subEntry, | ||
name, | ||
img, | ||
isVertical | ||
) | ||
) | ||
.onSuccess { response -> | ||
Timber.tag(successTag).d("response : $response") | ||
|
||
if (response.data == null) { | ||
_stateMessage.value = UiState.Failure(RESPONSE_NULL_CODE) | ||
return@onSuccess | ||
} | ||
|
||
_stateMessage.value = UiState.Success | ||
} | ||
.onFailure { | ||
Timber.tag(failTag).e("throwable: $it") | ||
if (it is HttpException) { | ||
Timber.tag(failTag).e("code : ${it.code()}") | ||
Timber.tag(failTag).e("message : ${it.message()}") | ||
|
||
when (it.code()) { | ||
INVALID_TOKEN_CODE -> _stateMessage.value = UiState.Failure( | ||
INVALID_TOKEN_CODE | ||
) | ||
CHECK_FAIL_CODE -> _stateMessage.value = UiState.Failure( | ||
CHECK_FAIL_CODE | ||
) | ||
else -> _stateMessage.value = UiState.Error | ||
} | ||
} else _stateMessage.value = UiState.Error | ||
} | ||
} | ||
} | ||
// 청소년증인 경우 | ||
else { | ||
viewModelScope.launch { | ||
userRepository.postYouthUserCheck(RequestPostYouthUserCheckDto(name, subEntry, img, isVertical)) | ||
.onSuccess { response -> | ||
Timber.tag(successTag).d("response : $response") | ||
|
||
if (response.data == null) { | ||
_stateMessage.value = UiState.Failure(RESPONSE_NULL_CODE) | ||
return@onSuccess | ||
} | ||
|
||
_stateMessage.value = UiState.Success | ||
} | ||
.onFailure { | ||
Timber.tag(failTag).e("throwable: $it") | ||
if (it is HttpException) { | ||
Timber.tag(failTag).e("code : ${it.code()}") | ||
Timber.tag(failTag).e("message : ${it.message()}") | ||
|
||
when (it.code()) { | ||
INVALID_TOKEN_CODE -> _stateMessage.value = UiState.Failure( | ||
INVALID_TOKEN_CODE | ||
) | ||
CHECK_FAIL_CODE -> _stateMessage.value = UiState.Failure( | ||
CHECK_FAIL_CODE | ||
) | ||
else -> _stateMessage.value = UiState.Error | ||
} | ||
} else _stateMessage.value = UiState.Error | ||
} | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val RESPONSE_NULL_CODE = 100 | ||
const val INVALID_TOKEN_CODE = 401 | ||
const val CHECK_FAIL_CODE = 400 | ||
|
||
private const val successTag = "POST_CHECK_USER_SUCCESS" | ||
private const val failTag = "POST_CHECK_USER_FAIL" | ||
} | ||
} |
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