-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from YAPP-Github/feature/MZ-145-export
Feature/mz 145 엑셀 파일 다운로드
- Loading branch information
Showing
10 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
data/src/main/java/com/susu/data/data/repository/ExcelRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.susu.data.data.repository | ||
|
||
import android.app.DownloadManager | ||
import android.os.Environment | ||
import androidx.core.net.toUri | ||
import com.susu.core.model.exception.UnknownException | ||
import com.susu.domain.repository.ExcelRepository | ||
import com.susu.domain.repository.TokenRepository | ||
import kotlinx.coroutines.flow.firstOrNull | ||
import javax.inject.Inject | ||
|
||
class ExcelRepositoryImpl @Inject constructor( | ||
private val downloadManager: DownloadManager, | ||
private val tokenRepository: TokenRepository, | ||
) : ExcelRepository { | ||
override suspend fun downloadEnvelopExcel(): Long { | ||
val token = tokenRepository.getAccessToken().firstOrNull() ?: throw UnknownException() | ||
|
||
val request = DownloadManager.Request(url.toUri()) | ||
.setMimeType(mimeType) | ||
.setAllowedOverMetered(true) | ||
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE) | ||
.setTitle(downloaderName) | ||
.addRequestHeader(headerTokenName, token) | ||
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName) | ||
|
||
return downloadManager.enqueue(request) | ||
} | ||
|
||
companion object { | ||
private const val url = "https://api.oksusu.site/api/v1/excel/all-envelopes" | ||
private const val mimeType = "application/vnd.ms-excel" | ||
private const val downloaderName = "수수" | ||
private const val headerTokenName = "X-SUSU-AUTH-TOKEN" | ||
private const val fileName = "수수_기록.xlsx" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.susu.data.remote.di | ||
|
||
import android.app.DownloadManager | ||
import android.content.Context | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ExcelModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun providesDownloadManager(@ApplicationContext context: Context): DownloadManager { | ||
return context.getSystemService(DownloadManager::class.java) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
domain/src/main/java/com/susu/domain/repository/ExcelRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.susu.domain.repository | ||
|
||
interface ExcelRepository { | ||
suspend fun downloadEnvelopExcel(): Long | ||
} |
13 changes: 13 additions & 0 deletions
13
domain/src/main/java/com/susu/domain/usecase/mypage/DownloadExcelUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.susu.domain.usecase.mypage | ||
|
||
import com.susu.core.common.runCatchingIgnoreCancelled | ||
import com.susu.domain.repository.ExcelRepository | ||
import javax.inject.Inject | ||
|
||
class DownloadExcelUseCase @Inject constructor( | ||
private val excelRepository: ExcelRepository, | ||
) { | ||
suspend operator fun invoke() = runCatchingIgnoreCancelled { | ||
excelRepository.downloadEnvelopExcel() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters