diff --git a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/MusicApi.kt b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/MusicApi.kt index 58a77c1..b682a7a 100644 --- a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/MusicApi.kt +++ b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/MusicApi.kt @@ -16,7 +16,7 @@ interface MusicApi { @POST("musics") suspend fun postMusic( @Body music: MusicRequest - ): Response + ) @GET("musics/recent-uploads") suspend fun getRecentUploads(): Response> diff --git a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/UploadApi.kt b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/UploadApi.kt index 88a47f4..17b9232 100644 --- a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/UploadApi.kt +++ b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/api/UploadApi.kt @@ -15,7 +15,7 @@ interface UploadApi { @GET("upload/uuid") suspend fun getUuid( - ): Response + ): UuidResponse @GET("upload") suspend fun getPreSignedUrl( diff --git a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/di/RepositoryModule.kt b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/di/RepositoryModule.kt index d2bb5ee..a18d70a 100644 --- a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/di/RepositoryModule.kt +++ b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/di/RepositoryModule.kt @@ -4,10 +4,12 @@ import com.ohdodok.catchytape.core.data.repository.AuthRepositoryImpl import com.ohdodok.catchytape.core.data.repository.MusicRepositoryImpl import com.ohdodok.catchytape.core.data.repository.UrlRepositoryImpl import com.ohdodok.catchytape.core.data.repository.UserTokenRepositoryImpl +import com.ohdodok.catchytape.core.data.repository.UuidRepositoryImpl import com.ohdodok.catchytape.core.domain.repository.AuthRepository import com.ohdodok.catchytape.core.domain.repository.MusicRepository import com.ohdodok.catchytape.core.domain.repository.UrlRepository import com.ohdodok.catchytape.core.domain.repository.UserTokenRepository +import com.ohdodok.catchytape.core.domain.repository.UuidRepository import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -34,4 +36,8 @@ interface RepositoryModule { @Singleton fun bindUrlRepository(urlRepositoryImpl: UrlRepositoryImpl): UrlRepository + @Binds + @Singleton + fun bindUuidRepository(uuidRepositoryImpl: UuidRepositoryImpl): UuidRepository + } \ No newline at end of file diff --git a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/MusicRequest.kt b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/MusicRequest.kt index 2dab5f8..9716ee5 100644 --- a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/MusicRequest.kt +++ b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/MusicRequest.kt @@ -1,9 +1,12 @@ package com.ohdodok.catchytape.core.data.model +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class MusicRequest ( + @SerialName("music_id") + val musicId: String, val title: String, val cover: String, val file: String, diff --git a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/MusicResponse.kt b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/MusicResponse.kt index f0595fc..74848e3 100644 --- a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/MusicResponse.kt +++ b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/model/MusicResponse.kt @@ -1,12 +1,15 @@ package com.ohdodok.catchytape.core.data.model +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class MusicResponse ( - val musicId: Int, + @SerialName("music_id") + val musicId: String, val title: String, val cover: String, + @SerialName("music_file") val musicFile : String, val genre: String, val user: NicknameResponse diff --git a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/MusicRepositoryImpl.kt b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/MusicRepositoryImpl.kt index 798b85f..7fc3090 100644 --- a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/MusicRepositoryImpl.kt +++ b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/MusicRepositoryImpl.kt @@ -30,8 +30,9 @@ class MusicRepositoryImpl @Inject constructor( else -> throw RuntimeException("네트워크 에러") } } - + override fun postMusic( + musicId: String, title: String, imageUrl: String, audioUrl: String, @@ -39,20 +40,17 @@ class MusicRepositoryImpl @Inject constructor( ): Flow = flow { val response = musicApi.postMusic( MusicRequest( + musicId = musicId, title = title, cover = imageUrl, file = audioUrl, genre = genre ) ) - when (response.code()) { - // TODO : 네트워크 에러 로직 처리 - in 200..299 -> emit(response.body() ?: Unit) - else -> throw RuntimeException("네트워크 에러") - } + emit(response) } } - + fun MusicResponse.toDomain(): Music { return Music( id = musicId, diff --git a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/UrlRepositoryImpl.kt b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/UrlRepositoryImpl.kt index 3650d38..2638e3c 100644 --- a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/UrlRepositoryImpl.kt +++ b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/UrlRepositoryImpl.kt @@ -14,16 +14,6 @@ class UrlRepositoryImpl @Inject constructor( private val uploadApi: UploadApi ) : UrlRepository { - override fun getUuid(): Flow = flow { - val response = uploadApi.getUuid() - if (response.isSuccessful) { - response.body()?.let { uuidResponse -> emit(uuidResponse.uuid) } - } else { - // TODO : 네트워크 에러 로직 - throw Exception("uuid 생성 실패") - } - } - override fun getImageUrl(file: File): Flow = flow { val response = uploadApi.postImage(file.toMultipart("image/png")) if (response.isSuccessful) { diff --git a/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/UuidRepositoryImpl.kt b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/UuidRepositoryImpl.kt new file mode 100644 index 0000000..1393c90 --- /dev/null +++ b/android/core/data/src/main/java/com/ohdodok/catchytape/core/data/repository/UuidRepositoryImpl.kt @@ -0,0 +1,16 @@ +package com.ohdodok.catchytape.core.data.repository + +import com.ohdodok.catchytape.core.data.api.UploadApi +import com.ohdodok.catchytape.core.domain.repository.UuidRepository +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow +import javax.inject.Inject + +class UuidRepositoryImpl @Inject constructor( + private val uploadApi: UploadApi +) : UuidRepository { + + override fun getUuid(): Flow = flow { + emit(uploadApi.getUuid().uuid) + } +} \ No newline at end of file diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/model/Music.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/model/Music.kt index 442e3c8..d157001 100644 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/model/Music.kt +++ b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/model/Music.kt @@ -1,7 +1,7 @@ package com.ohdodok.catchytape.core.domain.model data class Music( - val id: Int, + val id: String, val title: String, val artist: String, val imageUrl: String diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/MusicRepository.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/MusicRepository.kt index f38a755..34aff41 100644 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/MusicRepository.kt +++ b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/MusicRepository.kt @@ -9,6 +9,6 @@ interface MusicRepository { fun getRecentUploadedMusic(): Flow> - fun postMusic(title: String, imageUrl: String, audioUrl: String, genre: String): Flow + fun postMusic(musicId: String, title: String, imageUrl: String, audioUrl: String, genre: String): Flow } \ No newline at end of file diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/UrlRepository.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/UrlRepository.kt index 82f2f07..be54fa3 100644 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/UrlRepository.kt +++ b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/UrlRepository.kt @@ -5,8 +5,6 @@ import java.io.File interface UrlRepository { - fun getUuid(): Flow - fun getImageUrl(file: File): Flow fun getAudioUrl(file: File): Flow diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/UuidRepository.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/UuidRepository.kt new file mode 100644 index 0000000..fa749f1 --- /dev/null +++ b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/repository/UuidRepository.kt @@ -0,0 +1,8 @@ +package com.ohdodok.catchytape.core.domain.repository + +import kotlinx.coroutines.flow.Flow + +interface UuidRepository { + + fun getUuid(): Flow +} \ No newline at end of file diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/GetMusicGenresUseCase.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/GetMusicGenresUseCase.kt deleted file mode 100644 index 4f93f64..0000000 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/GetMusicGenresUseCase.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.ohdodok.catchytape.core.domain.usecase - -import com.ohdodok.catchytape.core.domain.repository.MusicRepository -import kotlinx.coroutines.flow.Flow -import javax.inject.Inject - -class GetMusicGenresUseCase @Inject constructor( - private val musicRepository: MusicRepository -) { - - operator fun invoke(): Flow> = musicRepository.getGenres() -} \ No newline at end of file diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/GetRecentUploadedMusic.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/GetRecentUploadedMusic.kt deleted file mode 100644 index 3335e56..0000000 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/GetRecentUploadedMusic.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.ohdodok.catchytape.core.domain.usecase - -import com.ohdodok.catchytape.core.domain.model.Music -import com.ohdodok.catchytape.core.domain.repository.MusicRepository -import kotlinx.coroutines.flow.Flow -import javax.inject.Inject - -class GetRecentUploadedMusic @Inject constructor( - private val musicRepository: MusicRepository -) { - operator fun invoke(): Flow> = musicRepository.getRecentUploadedMusic() -} \ No newline at end of file diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/UploadFileUseCase.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/UploadFileUseCase.kt deleted file mode 100644 index 9a3cfa3..0000000 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/UploadFileUseCase.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.ohdodok.catchytape.core.domain.usecase - -import com.ohdodok.catchytape.core.domain.repository.UrlRepository -import kotlinx.coroutines.flow.Flow -import java.io.File -import javax.inject.Inject - -class UploadFileUseCase @Inject constructor( - private val urlRepository: UrlRepository -) { - - fun getImgUrl(file: File): Flow = urlRepository.getImageUrl(file) - - fun getAudioUrl(file: File): Flow = urlRepository.getAudioUrl(file) - - - // TODO : 나중에 쓸 부분임 -// fun getAudioUrl(file: File): Flow = urlRepository.getUuid().map { uuid -> -// urlRepository.getAudioUrl(uuid, file).single() -// } - -} \ No newline at end of file diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/UploadMusicUseCase.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/UploadMusicUseCase.kt deleted file mode 100644 index 4490ae6..0000000 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/UploadMusicUseCase.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.ohdodok.catchytape.core.domain.usecase - -import com.ohdodok.catchytape.core.domain.repository.MusicRepository -import kotlinx.coroutines.flow.Flow -import javax.inject.Inject - -class UploadMusicUseCase @Inject constructor( - private val musicRepository: MusicRepository -) { - - operator fun invoke( - imageUrl: String, - audioUrl: String, - title: String, - genre: String - ): Flow = musicRepository.postMusic( - title = title, - genre = genre, - imageUrl = imageUrl, - audioUrl = audioUrl - ) -} \ No newline at end of file diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/AutomaticallyLoginUseCase.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/login/AutomaticallyLoginUseCase.kt similarity index 90% rename from android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/AutomaticallyLoginUseCase.kt rename to android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/login/AutomaticallyLoginUseCase.kt index 5900fe4..b394dda 100644 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/AutomaticallyLoginUseCase.kt +++ b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/login/AutomaticallyLoginUseCase.kt @@ -1,4 +1,4 @@ -package com.ohdodok.catchytape.core.domain.usecase +package com.ohdodok.catchytape.core.domain.usecase.login import com.ohdodok.catchytape.core.domain.repository.AuthRepository import com.ohdodok.catchytape.core.domain.repository.UserTokenRepository @@ -8,6 +8,7 @@ class AutomaticallyLoginUseCase @Inject constructor( private val authRepository: AuthRepository, private val userTokenRepository: UserTokenRepository ) { + suspend operator fun invoke(): Boolean { val accessToken = userTokenRepository.getAccessToken() if (accessToken.isBlank()) return false diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/LoginUseCase.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/login/LoginUseCase.kt similarity index 90% rename from android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/LoginUseCase.kt rename to android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/login/LoginUseCase.kt index 8c543f1..1f6b304 100644 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/LoginUseCase.kt +++ b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/login/LoginUseCase.kt @@ -1,4 +1,4 @@ -package com.ohdodok.catchytape.core.domain.usecase +package com.ohdodok.catchytape.core.domain.usecase.login import com.ohdodok.catchytape.core.domain.repository.AuthRepository import com.ohdodok.catchytape.core.domain.repository.UserTokenRepository diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/SignUpUseCase.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/signup/SignUpUseCase.kt similarity index 91% rename from android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/SignUpUseCase.kt rename to android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/signup/SignUpUseCase.kt index 4e6e27b..5bc859f 100644 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/SignUpUseCase.kt +++ b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/signup/SignUpUseCase.kt @@ -1,4 +1,4 @@ -package com.ohdodok.catchytape.core.domain.usecase +package com.ohdodok.catchytape.core.domain.usecase.signup import com.ohdodok.catchytape.core.domain.repository.AuthRepository import com.ohdodok.catchytape.core.domain.repository.UserTokenRepository diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/upload/UploadMusicUseCase.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/upload/UploadMusicUseCase.kt new file mode 100644 index 0000000..b20d946 --- /dev/null +++ b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/upload/UploadMusicUseCase.kt @@ -0,0 +1,22 @@ +package com.ohdodok.catchytape.core.domain.usecase.upload + +import com.ohdodok.catchytape.core.domain.repository.MusicRepository +import com.ohdodok.catchytape.core.domain.repository.UuidRepository +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.map +import javax.inject.Inject + +class UploadMusicUseCase @Inject constructor( + private val musicRepository: MusicRepository, + private val uuidRepository: UuidRepository +) { + + operator fun invoke( + imageUrl: String, audioUrl: String, title: String, genre: String + ): Flow = uuidRepository.getUuid().map { uuid -> + musicRepository.postMusic( + musicId = uuid, title = title, genre = genre, imageUrl = imageUrl, audioUrl = audioUrl + ).first() + } +} \ No newline at end of file diff --git a/android/feature/home/src/main/java/com/ohdodok/catchytape/feature/home/HomeViewModel.kt b/android/feature/home/src/main/java/com/ohdodok/catchytape/feature/home/HomeViewModel.kt index dbe14b8..103921d 100644 --- a/android/feature/home/src/main/java/com/ohdodok/catchytape/feature/home/HomeViewModel.kt +++ b/android/feature/home/src/main/java/com/ohdodok/catchytape/feature/home/HomeViewModel.kt @@ -3,7 +3,7 @@ package com.ohdodok.catchytape.feature.home import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ohdodok.catchytape.core.domain.model.Music -import com.ohdodok.catchytape.core.domain.usecase.GetRecentUploadedMusic +import com.ohdodok.catchytape.core.domain.repository.MusicRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -19,14 +19,14 @@ data class HomeUiState( @HiltViewModel class HomeViewModel @Inject constructor( - private val getRecentUploadedMusicUseCase: GetRecentUploadedMusic + private val musicRepository: MusicRepository ) : ViewModel() { private val _uiState = MutableStateFlow(HomeUiState()) val uiState: StateFlow = _uiState.asStateFlow() fun fetchUploadedMusics() { - getRecentUploadedMusicUseCase() + musicRepository.getRecentUploadedMusic() .onEach { musics -> _uiState.update { it.copy( diff --git a/android/feature/login/src/main/java/com/ohdodok/catchytape/feature/login/LoginViewModel.kt b/android/feature/login/src/main/java/com/ohdodok/catchytape/feature/login/LoginViewModel.kt index dc3522c..60bd87e 100644 --- a/android/feature/login/src/main/java/com/ohdodok/catchytape/feature/login/LoginViewModel.kt +++ b/android/feature/login/src/main/java/com/ohdodok/catchytape/feature/login/LoginViewModel.kt @@ -4,8 +4,8 @@ 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.usecase.AutomaticallyLoginUseCase -import com.ohdodok.catchytape.core.domain.usecase.LoginUseCase +import com.ohdodok.catchytape.core.domain.usecase.login.AutomaticallyLoginUseCase +import com.ohdodok.catchytape.core.domain.usecase.login.LoginUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.flow.MutableSharedFlow diff --git a/android/feature/login/src/main/java/com/ohdodok/catchytape/feature/login/NicknameViewModel.kt b/android/feature/login/src/main/java/com/ohdodok/catchytape/feature/login/NicknameViewModel.kt index 4e84c90..f6135b0 100644 --- a/android/feature/login/src/main/java/com/ohdodok/catchytape/feature/login/NicknameViewModel.kt +++ b/android/feature/login/src/main/java/com/ohdodok/catchytape/feature/login/NicknameViewModel.kt @@ -4,7 +4,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.ohdodok.catchytape.core.domain.usecase.signup.NicknameValidationResult import com.ohdodok.catchytape.core.domain.usecase.signup.ValidateNicknameUseCase -import com.ohdodok.catchytape.core.domain.usecase.SignUpUseCase +import com.ohdodok.catchytape.core.domain.usecase.signup.SignUpUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow diff --git a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt index 207b068..f987759 100644 --- a/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt +++ b/android/feature/upload/src/main/java/com/ohdodok/catchytape/feature/upload/UploadViewModel.kt @@ -5,9 +5,9 @@ import dagger.hilt.android.lifecycle.HiltViewModel import java.io.File import javax.inject.Inject import androidx.lifecycle.viewModelScope -import com.ohdodok.catchytape.core.domain.usecase.UploadFileUseCase -import com.ohdodok.catchytape.core.domain.usecase.GetMusicGenresUseCase -import com.ohdodok.catchytape.core.domain.usecase.UploadMusicUseCase +import com.ohdodok.catchytape.core.domain.repository.MusicRepository +import com.ohdodok.catchytape.core.domain.repository.UrlRepository +import com.ohdodok.catchytape.core.domain.usecase.upload.UploadMusicUseCase import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted @@ -24,8 +24,8 @@ import kotlinx.coroutines.flow.stateIn @HiltViewModel class UploadViewModel @Inject constructor( - private val getMusicGenresUseCase: GetMusicGenresUseCase, - private val uploadFileUseCase: UploadFileUseCase, + private val musicRepository: MusicRepository, + private val urlRepository: UrlRepository, private val uploadMusicUseCase: UploadMusicUseCase ) : ViewModel() { @@ -69,13 +69,13 @@ class UploadViewModel @Inject constructor( } private fun fetchGenres() { - getMusicGenresUseCase().onEach { + musicRepository.getGenres().onEach { _musicGenres.value = it }.launchIn(viewModelScope) } fun uploadImage(imageFile: File) { - uploadFileUseCase.getImgUrl(imageFile).onStart { + urlRepository.getImageUrl(imageFile).onStart { _imageState.value = imageState.value.copy(isLoading = true) }.onEach { url -> _imageState.value = imageState.value.copy(url = url) @@ -85,7 +85,7 @@ class UploadViewModel @Inject constructor( } fun uploadAudio(audioFile: File) { - uploadFileUseCase.getAudioUrl(audioFile).onStart { + urlRepository.getAudioUrl(audioFile).onStart { _audioState.value = audioState.value.copy(isLoading = true) }.onEach { url -> _audioState.value = audioState.value.copy(url = url)