Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ ParticipateExecutor を実装 #116

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +33 to +37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新しい関数currentUserAuthRepositoryインターフェースに追加されましたが、この関数の動作や使用方法についてのドキュメントコメントがありません。公開関数には特に例外を投げる可能性がある場合、その動作を説明するドキュメントが必要です。ドキュメントコメントの追加を検討してください。

}
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,
),
)
}
Comment on lines 16 to 28
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

authRepository.currentUser().id の呼び出しは例外を投げる可能性があるため、invoke メソッド内での例外処理を検討する必要があります。PRの概要によると currentUser() は例外を投げる可能性があるため、これらの例外を適切に処理することが重要です。

}
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)
}
}