Skip to content

Commit

Permalink
[feat]: refactor upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lsakee committed Oct 26, 2024
1 parent e1ebc05 commit e76c3d5
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.record.workmanager.upload

interface UploadEnqueuer {
fun enqueueUploadWork(videoPath: String, location: String, keywords: String, content: String)
fun enqueueUploadWork(videoPath: String, content: String, placeId: Long)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.record.workmanager.upload

interface UploadTask {
suspend fun upload(videoPath: String, location: String, content: String, keywords: String): Result<Unit>
suspend fun upload(videoPath: String, content: String, placeId: Long): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ class UploadWorker @AssistedInject constructor(
) : CoroutineWorker(context, params) {
override suspend fun doWork(): Result {
val videoPath = inputData.getString(KEY_VIDEO_PATH) ?: return Result.failure()
val location = inputData.getString(KEY_LOCATION) ?: return Result.failure()
val keywords = inputData.getString(KEY_KEYWORDS) ?: return Result.failure()
val placeId = inputData.getString(KEY_PLACE) ?: return Result.failure()
val content = inputData.getString(KEY_CONTENT) ?: return Result.failure()
val result = uploadTask.upload(videoPath, location, content, keywords)
val result = uploadTask.upload(videoPath, content, placeId = placeId.toLong())

return result.fold(
onSuccess = {
Expand All @@ -32,8 +31,7 @@ class UploadWorker @AssistedInject constructor(

companion object {
const val KEY_VIDEO_PATH = "videoPath"
const val KEY_LOCATION = "location"
const val KEY_KEYWORDS = "keywords"
const val KEY_PLACE = "placeId"
const val KEY_CONTENT = "content"
const val UNIQUE_UPLOAD_WORK = "upload-work"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import javax.inject.Inject
class UploadEnqueuerImpl @Inject constructor(
private val workManager: WorkManager,
) : UploadEnqueuer {
override fun enqueueUploadWork(videoPath: String, location: String, keywords: String, content: String) {
override fun enqueueUploadWork(videoPath: String, content: String, placeId: Long) {
val data = Data.Builder()
.putString(UploadWorker.KEY_VIDEO_PATH, videoPath)
.putString(UploadWorker.KEY_LOCATION, location)
.putString(UploadWorker.KEY_KEYWORDS, keywords)
.putString(UploadWorker.KEY_PLACE, placeId.toString())
.putString(UploadWorker.KEY_CONTENT, content)
.build()
val request = OneTimeWorkRequestBuilder<UploadWorker>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ data class RequestPostVideoDto(
val content: String,
@SerialName("fileUrl")
val fileUrl: FileUrl,
@SerialName("keywords")
val keywords: String,
@SerialName("location")
val location: String,
@SerialName("placeId")
val placeId: Long,
)

fun VideoInfo.toData() = RequestPostVideoDto(
Expand All @@ -23,6 +21,5 @@ fun VideoInfo.toData() = RequestPostVideoDto(
videoUrl = videoUrl,
thumbnailUrl = previewUrl,
),
keywords = keywords,
location = location,
placeId = placeId,
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UploadRepositoryImpl @Inject constructor(
private val localVideoDataSource: LocalVideoDataSource,
) : UploadRepository {
override suspend fun upload(recordInfo: RecordInfo) {
uploadEnqueuer.enqueueUploadWork(recordInfo.videoPath, recordInfo.location, recordInfo.keywords, recordInfo.content)
uploadEnqueuer.enqueueUploadWork(recordInfo.videoPath, recordInfo.content, recordInfo.placeId)
}

override suspend fun getVideosFromGallery(page: Int, loadSize: Int, currentLocation: String?): Result<List<GalleryVideo>> = runCatching {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UploadTaskImpl @Inject constructor(
private val remoteUploadDataSource: RemoteUploadDataSource,
private val uploadBroadCaster: UploadBroadCaster,
) : UploadTask {
override suspend fun upload(videoPath: String, location: String, content: String, keywords: String): Result<Unit> {
override suspend fun upload(videoPath: String, content: String, placeId: Long): Result<Unit> {
val result = runCatching {
uploadBroadCaster.sendUploadStart()
val urls = remoteUploadDataSource.getUploadUrl()
Expand All @@ -31,11 +31,10 @@ class UploadTaskImpl @Inject constructor(
remoteUploadDataSource.uploadThumbnailToS3Bucket(previewUrl, File(videoPath)).let { previewUri ->
remoteUploadDataSource.uploadRecord(
VideoInfo(
location = location,
content = content,
keywords = keywords,
videoUrl = videoUri,
previewUrl = previewUri,
placeId = placeId,
).toData(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.record.upload.model

data class RecordInfo(
val videoPath: String,
val location: String,
val content: String,
val keywords: String,
val placeId: Long,
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.record.upload.model

data class VideoInfo(
val location: String,
val content: String,
val keywords: String,
val placeId: Long,
val videoUrl: String,
val previewUrl: String,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.record.upload

import androidx.lifecycle.viewModelScope
import com.record.common.util.encodingString
import com.record.designsystem.component.snackbar.SnackBarType
import com.record.keyword.repository.KeywordRepository
import com.record.model.AlertInfo
Expand Down Expand Up @@ -35,9 +34,8 @@ class UploadViewModel @Inject constructor(

val recordInfo = RecordInfo(
filePath,
uiState.value.locationTextValue,
uiState.value.contentTextValue,
keywords = encodingString(uiState.value.selectedList.joinToString(separator = ",")).trim(),
placeId = 0,
)
uploadRepository.upload(recordInfo)
popBackStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ fun VideoPickerScreen(
text = "다음",
enabled = state.locationTextValue.isNotEmpty() && state.video != null,
onClick = {
if (state.selectedList.isNotEmpty() && state.locationTextValue.isNotEmpty() && state.video != null) {
if (state.video != null) {
onClickUpload()
// compressVideo(context, state.video.uri,state.video.name, onSuccess = onSuccess)
}
Expand Down

0 comments on commit e76c3d5

Please sign in to comment.