-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/#102 video detail api #107
Changes from all commits
3c408ed
d0541e4
0ebc593
ea8304b
a12db21
3998d34
b245e4b
f732be9
f0585dc
6a75b8c
f0e9812
8138e04
36ec6f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
alias(libs.plugins.recordy.android.library) | ||
alias(libs.plugins.recordy.android.hilt) | ||
} | ||
|
||
android { | ||
namespace = "com.record.cache" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,14 @@ import com.record.model.exception.ApiError | |
import com.record.video.model.VideoData | ||
import com.record.video.model.remote.response.toCore | ||
import com.record.video.model.remote.response.toDomain | ||
import com.record.video.source.local.LocalUserInfoDataSource | ||
import com.record.video.source.remote.RemoteVideoDataSource | ||
import retrofit2.HttpException | ||
import javax.inject.Inject | ||
|
||
class VideoRepositoryImpl @Inject constructor( | ||
private val remoteVideoDataSource: RemoteVideoDataSource, | ||
private val localUserInfoDataSource: LocalUserInfoDataSource, | ||
) : VideoRepository { | ||
override suspend fun getAllVideos(cursorId: Long, pageSize: Int): Result<List<VideoData>> = runCatching { | ||
remoteVideoDataSource.getAllVideos(cursorId, pageSize) | ||
|
@@ -30,10 +32,10 @@ class VideoRepositoryImpl @Inject constructor( | |
} | ||
} | ||
|
||
override suspend fun getRecentVideos(keywords: List<String>?, pageNumber: Int, pageSize: Int): Result<Cursor<VideoData>> = runCatching { | ||
override suspend fun getRecentVideos(keywords: List<String>?, cursor: Long, pageSize: Int): Result<Cursor<VideoData>> = runCatching { | ||
val encodedKeywords = keywords?.map { it.replace(" ", "_") }?.map { toUTF8(it) } | ||
|
||
remoteVideoDataSource.getRecentVideos(encodedKeywords, pageNumber, pageSize) | ||
remoteVideoDataSource.getRecentVideos(encodedKeywords, cursor, pageSize) | ||
}.mapCatching { | ||
it.toCore() | ||
}.recoverCatching { exception -> | ||
|
@@ -81,6 +83,26 @@ class VideoRepositoryImpl @Inject constructor( | |
} | ||
} | ||
|
||
override suspend fun getMyVideos(cursorId: Long, size: Int): Result<Cursor<VideoData>> = runCatching { | ||
remoteVideoDataSource.getUserVideos( | ||
localUserInfoDataSource.getMyId(), | ||
cursorId, | ||
size, | ||
) | ||
}.mapCatching { | ||
it.toCore() | ||
}.recoverCatching { exception -> | ||
when (exception) { | ||
is HttpException -> { | ||
throw ApiError(exception.message()) | ||
} | ||
|
||
else -> { | ||
throw exception | ||
} | ||
} | ||
Comment on lines
+92
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์๋ฌ ์ฒ๋ฆฌ ์ mapCatching์ด๋ recoverCatching ๊ฐ์ ๊ฑด ๋ชป ๋ณด๋ ์ด๋ฒคํธ ์ฒ๋ฆฌ์ธ๋ฐ .. ํฅ๋ฏธ๋กญ๋ค์๐๐ป ์์นํด๋ณด๋ ์ข์ ์ฒ๋ฆฌ ๊ฐ์ ์ ๋ ์ฝ์ฅ ํด๊ฐ๊ฒ์ ใ ใ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ ๋ mapCating๊ตฌ๋ฌธ ์ ๋ชจ๋ฅด๋๋ฐ ๋๋ถ์ ์ฐธ๊ณ ๊ฐ ๋์ด์ |
||
} | ||
|
||
override suspend fun getFollowingVideos(userId: Long, cursorId: Long, size: Int): Result<Cursor<VideoData>> = runCatching { | ||
remoteVideoDataSource.getFollowingVideos(userId, cursorId, size) | ||
}.mapCatching { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.record.video.source.local | ||
|
||
interface LocalUserInfoDataSource { | ||
suspend fun getMyId(): Long | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,8 @@ import com.record.model.exception.ApiError | |
import com.record.ui.base.BaseViewModel | ||
import com.record.video.repository.VideoRepository | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.collections.immutable.toImmutableList | ||
import kotlinx.coroutines.launch | ||
import okhttp3.internal.toImmutableList | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
|
@@ -18,12 +18,6 @@ class HomeViewModel @Inject constructor( | |
private val keywordRepository: KeywordRepository, | ||
) : BaseViewModel<HomeState, HomeSideEffect>(HomeState()) { | ||
|
||
init { | ||
getPreferenceKeywords() | ||
getPopularVideos() | ||
getRecentVideos() | ||
} | ||
|
||
fun navigateToUpload() { | ||
postSideEffect(HomeSideEffect.navigateToUpload) | ||
} | ||
|
@@ -36,11 +30,17 @@ class HomeViewModel @Inject constructor( | |
getRecentVideos() | ||
} | ||
|
||
fun getVideos() { | ||
getPreferenceKeywords() | ||
getPopularVideos() | ||
getRecentVideos() | ||
} | ||
|
||
Comment on lines
+33
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์๋ init ์ผ๋ก ๊ตฌํํด๋์ผ์ จ๋ ๊ฑด LaunchedEffect์์ ์ฒ๋ฆฌํ๋ ค๊ณ ํจ์๋ก ๋นผ์ จ๊ตฐ์ !!!! ์ข์ต๋๋ค ๐ซก |
||
private fun getPreferenceKeywords() { | ||
viewModelScope.launch { | ||
keywordRepository.getKeywords().onSuccess { | ||
intent { | ||
copy(chipList = it.keywords) | ||
copy(chipList = it.keywords.toImmutableList()) | ||
} | ||
}.onFailure { | ||
when (it) { | ||
|
@@ -58,7 +58,7 @@ class HomeViewModel @Inject constructor( | |
val keyword = if (keyIndex != null) listOf(uiState.value.chipList[keyIndex]) else null | ||
videoRepository.getRecentVideos( | ||
keywords = keyword, | ||
pageNumber = 0, | ||
cursor = 0, | ||
pageSize = 10, | ||
).onSuccess { | ||
intent { | ||
|
@@ -124,8 +124,8 @@ class HomeViewModel @Inject constructor( | |
|
||
Log.e("๋ฐํ๊ฐ", updatedPopularList.toString()) | ||
copy( | ||
recentList = updatedRecentList, | ||
popularList = updatedPopularList, | ||
recentList = updatedRecentList.toImmutableList(), | ||
popularList = updatedPopularList.toImmutableList(), | ||
) | ||
} | ||
viewModelScope.launch { | ||
|
@@ -151,8 +151,8 @@ class HomeViewModel @Inject constructor( | |
Log.e("๋ฐํ๊ฐ", updatedPopularList1.toString()) | ||
intent { | ||
copy( | ||
recentList = updatedRecentList1, | ||
popularList = updatedPopularList1, | ||
recentList = updatedRecentList1.toImmutableList(), | ||
popularList = updatedPopularList1.toImmutableList(), | ||
) | ||
} | ||
}.onFailure { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heap ํฌ๊ธฐ๊น์ง ์ ๊ฒฝ์ฐ๋ค๋..