-
Notifications
You must be signed in to change notification settings - Fork 1
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
내가 업로드한 노래 3개 가져오기 #214
내가 업로드한 노래 3개 가져오기 #214
Changes from 3 commits
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.ohdodok.catchytape.core.data.model | ||
|
||
import com.ohdodok.catchytape.core.domain.model.Music | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
|
@@ -13,4 +14,15 @@ data class MusicResponse ( | |
val musicFile : String, | ||
val genre: String, | ||
val user: NicknameResponse | ||
) | ||
) { | ||
fun toDomain(): Music { | ||
return Music( | ||
id = musicId, | ||
title = title, | ||
artist = user.nickname, | ||
imageUrl = cover | ||
) | ||
} | ||
} | ||
Comment on lines
+18
to
+26
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. 요 부분 슬랙에도 말했는데 domain model 에서 data model로 변환할 때는 domain 이 data를 몰라서 클래스안에 멤버 함수로 둘 수가 없게 돼!! 그래서 두가지 방식을 일관성 있게 처리할라면 이 멤버 함수도 internal 확장함수로 두어야할 것 같아용 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. 나는 그래도 멤버함수파이긴 한데, 이거는 일단 머지해 놓고 다시 고민해볼게 |
||
|
||
internal fun List<MusicResponse>.toDomains(): List<Music> = this.map { it.toDomain() } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,72 @@ | ||
package com.ohdodok.catchytape.feature.mypage | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.ohdodok.catchytape.core.domain.model.CtErrorType | ||
import com.ohdodok.catchytape.core.domain.model.CtException | ||
import com.ohdodok.catchytape.core.domain.model.Music | ||
import com.ohdodok.catchytape.core.domain.repository.MusicRepository | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.CoroutineExceptionHandler | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.SharedFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.plus | ||
import javax.inject.Inject | ||
|
||
data class MyPageUiState( | ||
val myMusics: List<Music> = emptyList() | ||
) | ||
|
||
@HiltViewModel | ||
class MyPageViewModel @Inject constructor() : ViewModel() { | ||
class MyPageViewModel @Inject constructor( | ||
private val musicRepository: MusicRepository, | ||
) : ViewModel() { | ||
|
||
private val _uiState = MutableStateFlow(MyPageUiState()) | ||
val uiState: StateFlow<MyPageUiState> = _uiState.asStateFlow() | ||
|
||
private val _events = MutableSharedFlow<MyPageEvent>() | ||
val events: SharedFlow<MyPageEvent> = _events.asSharedFlow() | ||
} | ||
|
||
private val exceptionHandler = CoroutineExceptionHandler { _, throwable -> | ||
viewModelScope.launch { | ||
if (throwable is CtException) { | ||
_events.emit(MyPageEvent.ShowMessage(throwable.ctError)) | ||
} else { | ||
_events.emit(MyPageEvent.ShowMessage(CtErrorType.UN_KNOWN)) | ||
} | ||
} | ||
} | ||
|
||
sealed interface MyPageEvent { | ||
private val viewModelScopeWithExceptionHandler = viewModelScope + exceptionHandler | ||
|
||
init { | ||
fetchMyMusics() | ||
} | ||
|
||
private fun fetchMyMusics() { | ||
musicRepository.getMyMusics() | ||
.onEach { response -> | ||
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. response 보다는 musics 로 하는게 어떨까??? response 는 데이터 레이어와 관련된 것 같은 느낌이 들어서!!! |
||
_uiState.update { | ||
it.copy( | ||
myMusics = response.take(3) | ||
) | ||
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. 마이너 한데, |
||
} | ||
} | ||
.launchIn(viewModelScopeWithExceptionHandler) | ||
} | ||
} | ||
|
||
sealed interface MyPageEvent { | ||
data class ShowMessage( | ||
val error: CtErrorType | ||
) : MyPageEvent | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="share_music">노래를 공유해 보세요.</string> | ||
<string name="my_musics">내가 업로드한 노래</string> | ||
</resources> |
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.
getMyUploads 는 함수명 치고, 너무 추상적인 거 같은데 getMyUploadedMusics 가 어떠신가요?
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.
getRecentUploads 도 마찬가지 맥락입니다~
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.
데이터 레이어에 대한 추상화는 repository에서 이루어져서, 여기서는 서버를 그대로 반영하려고 했어!