Skip to content

Commit

Permalink
Merge pull request #116 from 2rabs/rt/add-participate-executor
Browse files Browse the repository at this point in the history
✨ ParticipateExecutor を実装
  • Loading branch information
tatsutakein authored Dec 4, 2023
2 parents 52f6fe4 + ab38477 commit 9c3beef
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package club.nito.core.data

import club.nito.core.model.ApiException
import club.nito.core.model.AuthStatus
import club.nito.core.model.UserInfo
import kotlinx.coroutines.flow.Flow
import kotlin.coroutines.cancellation.CancellationException

/**
* 認証に関するリポジトリ
Expand All @@ -27,4 +29,10 @@ public sealed interface AuthRepository {
* 認証ユーザー情報を更新する
*/
public suspend fun modifyAuthUser(email: String?, password: String?): UserInfo

/**
* 現在ログイン中のユーザー情報を取得する
*/
@Throws(ApiException.SessionNotFoundException::class, CancellationException::class)
public suspend fun currentUser(): UserInfo
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package club.nito.core.data

import club.nito.core.datastore.DataStore
import club.nito.core.model.ApiException
import club.nito.core.model.AuthStatus
import club.nito.core.model.UserInfo
import club.nito.core.network.auth.AuthRemoteDataSource
Expand Down Expand Up @@ -31,4 +32,7 @@ public class DefaultAuthRepository(
email = email,
password = password,
)

override suspend fun currentUser(): UserInfo = remoteDataSource.currentUserOrNull()
?: throw ApiException.SessionNotFoundException(cause = null)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package club.nito.core.domain

import club.nito.core.data.AuthRepository
import club.nito.core.data.ParticipantRepository
import club.nito.core.model.ExecuteResult
import club.nito.core.model.participant.ParticipantDeclaration
import club.nito.core.model.runExecuting

/**
* 参加表明するユースケース
Expand All @@ -11,9 +14,16 @@ public sealed interface ParticipateUseCase {
}

public class ParticipateExecutor(
private val authRepository: AuthRepository,
private val participantRepository: ParticipantRepository,
) : ParticipateUseCase {
override suspend fun invoke(scheduleId: String, comment: String): ExecuteResult<Unit> {
TODO("Not yet implemented")
override suspend fun invoke(scheduleId: String, comment: String): ExecuteResult<Unit> = runExecuting {
participantRepository.participate(
declaration = ParticipantDeclaration(
scheduleId = scheduleId,
memberId = authRepository.currentUser().id,
comment = comment,
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public sealed interface AuthRemoteDataSource {
public suspend fun modifyAuthUser(email: String?, password: String?): UserInfo
public suspend fun authIfNeeded()
public suspend fun refreshCurrentSession()

/**
* 現在ログイン中のユーザー情報を取得する
*/
public suspend fun currentUserOrNull(): UserInfo?
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ public class SupabaseAuthRemoteDataSource(
}

override suspend fun refreshCurrentSession(): Unit = goTrue.refreshCurrentSession()

override suspend fun currentUserOrNull(): UserInfo? {
return goTrue.currentUserOrNull()?.let(SupabaseAuthRemoteDataSourceMapper::transformToUserInfo)
}
}

0 comments on commit 9c3beef

Please sign in to comment.