Skip to content

Instantly share code, notes, and snippets.

@bigwheel
Created January 20, 2019 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigwheel/af0a4b6a91825c63e0971f90cbb12b43 to your computer and use it in GitHub Desktop.
Save bigwheel/af0a4b6a91825c63e0971f90cbb12b43 to your computer and use it in GitHub Desktop.
// アプリケーション層のどこか
def `ユーザーを有効状態で追加`(
`組織ID`: Int,
`ユーザー名`: String,
`メールアドレス`: String,
`ハッシュ化されたパスワード`: String): Try[`ユーザー`] = {
val `組織インスタンス` = `組織リポジトリ`.find(`組織ID`).get
if (`組織インスタンス`.`有効状態でユーザーを追加可能か`) {
val `ユーザーインスタンス` = `ユーザーファクトリ`.create(
`ユーザー名`,
`メールアドレス`,
`ハッシュ化されたパスワード`
)
val `新組織インスタンス` = `組織インスタンス`.
`有効状態でユーザーを追加`(`ユーザーインスタンス`.`ユーザーID`)
`組織リポジトリ`.save(`新組織インスタンス`) match {
case Success(_) =>
`ユーザーリポジトリ`.save(`ユーザーインスタンス`) match {
case Success(_) =>
Success(`ユーザーインスタンス`)
case f =>
// ① ユーザーの保存に失敗した場合は組織インスタンスを元の状態で保存し直す
`組織リポジトリ`.save(`組織インスタンス`)
f
}
case f =>
f
}
} else
Failure(new `有効ユーザー数上限Exception`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment