Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ドメインサービスでバリデーション入れた場合のサンプル
package first
import first.usecase.{CreateUserInput, CreateUserOutput, CreateUserUseCase}
final class CreateUserInteractor(userService: UserService, userRepository: UserRepository) extends CreateUserUseCase {
override def handle(input: CreateUserInput): CreateUserOutput = {
val newUser = User.create(input.name)
userService.exists(newUser) match { // このバリデーションが必ず必要だが、知らないとできない。
case Left(_) => CreateUserOutput.UserNameConflict(newUser.name)
case Right(_) =>
val insertedUser = userRepository.insert(newUser)
CreateUserOutput.Success(insertedUser)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment