Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor]: qa #155

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.record.network

import com.record.network.model.BaseResponse
import com.record.network.model.ResponsePostAuthRefreshDto
import retrofit2.http.Header
import retrofit2.http.POST
Expand All @@ -15,6 +14,6 @@ interface TokenRefreshService {

@POST("/$API/$VERSION/$USER/$TOKEN")
suspend fun postAuthRefresh(
@Header("refreshToken") refreshToken: String,
): BaseResponse<ResponsePostAuthRefreshDto>
@Header("Authorization") refreshToken: String,
): ResponsePostAuthRefreshDto
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.record.network.TokenRefreshService
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import okhttp3.Authenticator
import okhttp3.Request
import okhttp3.Response
Expand All @@ -18,30 +20,39 @@ class RecordyAuthenticator @Inject constructor(
private val tokenRefreshService: TokenRefreshService,
@ApplicationContext private val context: Context,
) : Authenticator {
private val mutex = Mutex()

override fun authenticate(route: Route?, response: Response): Request? {
if (response.code == CODE_TOKEN_EXPIRED) {
val newTokens = runCatching {
runBlocking {
tokenRefreshService.postAuthRefresh(dataStore.token.first().refreshToken)
}
}.onSuccess {
runBlocking {
dataStore.apply {
setAccessToken(it.data?.accessToken ?: "")
}
return if (response.code == CODE_TOKEN_EXPIRED) {
runBlocking {
mutex.withLock {
processTokenRefresh(response)
}
}.onFailure {
runBlocking {
dataStore.setAutoLogin(false)
}
ProcessPhoenix.triggerRebirth(context)
}.getOrThrow()

return response.request.newBuilder()
.header("accessToken", newTokens.data?.accessToken ?: "")
.build()
}
} else {
null
}
return null
}

private fun processTokenRefresh(response: Response): Request? {
val newTokens = runCatching {
runBlocking {
tokenRefreshService.postAuthRefresh(dataStore.token.first().refreshToken)
}
}.onSuccess {
runBlocking {
dataStore.setAccessToken(it.accessToken ?: "")
}
}.onFailure {
runBlocking {
dataStore.setAutoLogin(false)
}
ProcessPhoenix.triggerRebirth(context)
}.getOrThrow()

return response.request.newBuilder()
.header("accessToken", newTokens.accessToken ?: "")
.build()
}

companion object {
Expand Down
67 changes: 32 additions & 35 deletions feature/mypage/src/main/java/com/record/mypage/MypageViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.record.user.repository.UserRepository
import com.record.video.repository.VideoRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand Down Expand Up @@ -64,42 +63,40 @@ class MypageViewModel @Inject constructor(
}
}
}

fun initialData() = viewModelScope.launch {
val myVideosResult = async { videoRepository.getMyVideos(0, 10) }
val bookmarkVideosResult = async { videoRepository.getBookmarkVideos(0, 10) }
getInitialMyVideos()
getInitialBookMark()
}

myVideosResult.await()
.onSuccess { myVideo ->
bookmarkVideosResult.await()
.onSuccess { bookmarkVideo ->
Log.e("๋ถ๋งˆํฌ", bookmarkVideo.data.toString())
intent {
copy(
myRecordList = myVideo.data.toImmutableList(),
myBookmarkList = bookmarkVideo.data.toImmutableList(),
recordCursor = myVideo.nextCursor?.toLong() ?: 0,
bookmarkCursor = bookmarkVideo.nextCursor?.toLong() ?: 0,
recordIsEnd = false,
bookmarkIsEnd = false,
)
}
intent {
copy(
recordVideoCount = uiState.value.myRecordList.size,
bookmarkVideoCount = uiState.value.myBookmarkList.size,
)
}
}
.onFailure { error ->
Log.e("์˜ค๋ฅ˜ ๋ฐœ์ƒใ…‡ใ…‡", error.message.toString())
}
}
.onFailure { error ->
Log.e("์˜ค๋ฅ˜ ๋ฐœ์ƒใ…‡ใ…‡", error.message.toString())
private suspend fun getInitialMyVideos() = videoRepository.getMyVideos(0, 10)
.onSuccess { myVideo ->
intent {
copy(
myRecordList = myVideo.data.toImmutableList(),
recordCursor = myVideo.nextCursor?.toLong() ?: 0,
recordIsEnd = false,
recordVideoCount = myVideo.data.size,
)
}
}
}
.onFailure { error ->
Log.e("์˜ค๋ฅ˜ ๋ฐœ์ƒ", error.message.toString())
}

private suspend fun getInitialBookMark() = videoRepository.getBookmarkVideos(0, 10)
.onSuccess { bookmarkVideo ->
intent {
copy(
myBookmarkList = bookmarkVideo.data.toImmutableList(),
bookmarkCursor = bookmarkVideo.nextCursor?.toLong() ?: 0,
bookmarkIsEnd = false,
bookmarkVideoCount = bookmarkVideo.data.size,
)
}
}
.onFailure { error ->
Log.e("์˜ค๋ฅ˜ ๋ฐœ์ƒ", error.message.toString())
}
fun loadMoreUserVideos() = viewModelScope.launch {
val list = uiState.value.myRecordList.toList()
if (uiState.value.recordIsEnd) return@launch
Expand Down Expand Up @@ -168,21 +165,21 @@ class MypageViewModel @Inject constructor(
video
}
}

val updatedMyBookmarkList = uiState.value.myBookmarkList.map { video ->
if (video.id == id) {
video.copy(isBookmark = it)
} else {
video
}
}

intent {
copy(
myRecordList = updatedMyRecordList.toImmutableList(),
myBookmarkList = updatedMyBookmarkList.toImmutableList(),
)
}

getInitialBookMark()
}.onFailure {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,20 @@ fun BookmarkScreen(
}
}
items(videoItems) { item ->
RecordyVideoThumbnail(
imageUri = item.previewUrl,
isBookmarkable = true,
isBookmark = item.isBookmark,
onBookmarkClick = {
onBookmarkClick(item.id)
},
location = item.exhibitionName,
onClick = {
onItemClick(VideoType.BOOKMARK, item.id)
},
)
if (item.isBookmark) {
RecordyVideoThumbnail(
imageUri = item.previewUrl,
isBookmarkable = true,
isBookmark = item.isBookmark,
onBookmarkClick = {
onBookmarkClick(item.id)
},
location = item.exhibitionName,
onClick = {
onItemClick(VideoType.BOOKMARK, item.id)
},
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class UploadViewModel @Inject constructor(
}
}
fun setSelectedPlace(id: String, name: String, address: String) {
if (uiState.value.selectPlace.name != name) updateLocationTextField("")

if (id.isNotEmpty() && name.isNotEmpty() && address.isNotEmpty()) {
intent {
copy(
Expand Down
Loading