forked from FoKE-Developers/FourCutTogether
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add UseCases for web communications [FoKE-Developers#73]
- 서버와 통신하기 위한 usecase들을 추가 - **CreateAccountUseCase**: 계정 생성 (`phase4` 구현) - **SignInUseCase**: 로그인 및 세션 생성 - **GetCurrentUserInformationUseCase**: 현재 로그인된 세센 계정 정보 - **UploadFileUseCase**: 파일을 pre-signed url을 통해 업로드 - https://4cuts.store/docs 내용 기반
- Loading branch information
Showing
13 changed files
with
133 additions
and
10 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
22 changes: 22 additions & 0 deletions
22
data/src/main/java/com/foke/together/data/repository/AccountRepository.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,22 @@ | ||
package com.foke.together.data.repository | ||
|
||
import com.foke.together.domain.interactor.entity.AccountData | ||
import com.foke.together.domain.output.AccountRepositoryInterface | ||
import javax.inject.Inject | ||
|
||
class AccountRepository @Inject constructor( | ||
) : AccountRepositoryInterface { | ||
private var accountData: AccountData? = null | ||
|
||
override suspend fun setAccountInfo(data: AccountData) { | ||
accountData = data | ||
} | ||
|
||
override suspend fun getAccountInfo(): Result<AccountData> { | ||
return accountData?.run { | ||
Result.success(this) | ||
} ?: run { | ||
Result.failure(Exception("account data is null")) | ||
} | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
domain/src/main/java/com/foke/together/domain/interactor/web/CreateAccountUseCase.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.foke.together.domain.interactor.web | ||
|
||
import com.foke.together.domain.output.RemoteRepositoryInterface | ||
import javax.inject.Inject | ||
|
||
class CreateAccountUseCase @Inject constructor( | ||
private val remoteRepository: RemoteRepositoryInterface | ||
) { | ||
operator fun invoke(id: String, password: String): Result<Unit> { | ||
// TODO: implement in sprint4 | ||
return Result.failure(Exception("not implemented")) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...src/main/java/com/foke/together/domain/interactor/web/GetCurrentUserInformationUseCase.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,20 @@ | ||
package com.foke.together.domain.interactor.web | ||
|
||
import com.foke.together.domain.interactor.entity.AccountData | ||
import com.foke.together.domain.output.AccountRepositoryInterface | ||
import com.foke.together.domain.output.RemoteRepositoryInterface | ||
import javax.inject.Inject | ||
|
||
class GetCurrentUserInformationUseCase @Inject constructor( | ||
private val remoteRepository: RemoteRepositoryInterface, | ||
private val accountRepository: AccountRepositoryInterface | ||
) { | ||
suspend operator fun invoke(): Result<AccountData> = | ||
accountRepository.getAccountInfo() | ||
.onFailure { | ||
remoteRepository.getAccountStatus() | ||
.onSuccess { | ||
accountRepository.setAccountInfo(it) | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
domain/src/main/java/com/foke/together/domain/interactor/web/SignInUseCase.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,26 @@ | ||
package com.foke.together.domain.interactor.web | ||
|
||
import com.foke.together.domain.interactor.entity.AccountData | ||
import com.foke.together.domain.output.AccountRepositoryInterface | ||
import com.foke.together.domain.output.RemoteRepositoryInterface | ||
import javax.inject.Inject | ||
|
||
class SignInUseCase @Inject constructor( | ||
private val remoteRepository: RemoteRepositoryInterface, | ||
private val accountRepository: AccountRepositoryInterface, | ||
private val getCurrentUserInformationUseCase: GetCurrentUserInformationUseCase | ||
) { | ||
suspend operator fun invoke(id: String, password: String): Result<Unit> { | ||
return remoteRepository.signIn(AccountData(id, password)) | ||
.onSuccess { | ||
getCurrentUserInformationUseCase() | ||
.onSuccess { accountData -> | ||
accountRepository.setAccountInfo(AccountData( | ||
email = accountData.email, | ||
password = "", | ||
name = accountData.name | ||
)) | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
domain/src/main/java/com/foke/together/domain/interactor/web/UploadFileUseCase.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,28 @@ | ||
package com.foke.together.domain.interactor.web | ||
|
||
import com.foke.together.domain.output.RemoteRepositoryInterface | ||
import com.foke.together.util.AppLog | ||
import java.io.File | ||
import javax.inject.Inject | ||
|
||
// Download url | ||
// https://4cuts.store/download/{user_name}/{key} | ||
class UploadFileUseCase @Inject constructor( | ||
private val remoteRepository: RemoteRepositoryInterface | ||
) { | ||
suspend operator fun invoke(key: String, file: File): Result<Unit> { | ||
remoteRepository.getUploadUrl("$key.${file.extension}", file) | ||
.onSuccess { preSignedUrl -> | ||
AppLog.e("UploadFileUseCase", "invoke", "preSignedUrl: $preSignedUrl") | ||
remoteRepository.uploadFile(preSignedUrl, file) | ||
.onFailure { | ||
AppLog.e("UploadFileUseCase", "invoke", "upload failed") | ||
return Result.failure(Exception("cannot upload file: $it")) | ||
} | ||
} | ||
.onFailure { | ||
return Result.failure(Exception("cannot get pre-signed url: $it")) | ||
} | ||
return Result.failure(Exception("Unknown error")) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
domain/src/main/java/com/foke/together/domain/output/AccountRepositoryInterface.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,8 @@ | ||
package com.foke.together.domain.output | ||
|
||
import com.foke.together.domain.interactor.entity.AccountData | ||
|
||
interface AccountRepositoryInterface { | ||
suspend fun setAccountInfo(data: AccountData) | ||
suspend fun getAccountInfo(): Result<AccountData> | ||
} |
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