1.5 KBRaw
| 1 | use super::RepositoryResult; |
| 2 | use crate::domain::{Email, User, UserId}; |
| 3 | |
| 4 | /// Persistence for [`User`]. |
| 5 | pub trait UserRepository: Send + Sync { |
| 6 | /// Looks a user up by id. |
| 7 | fn find_by_id( |
| 8 | &self, |
| 9 | id: &UserId, |
| 10 | ) -> impl Future<Output = RepositoryResult<Option<User>>> + Send; |
| 11 | |
| 12 | /// Looks a user up by email — the credential used to sign in. |
| 13 | fn find_by_email( |
| 14 | &self, |
| 15 | email: &Email, |
| 16 | ) -> impl Future<Output = RepositoryResult<Option<User>>> + Send; |
| 17 | |
| 18 | /// Inserts or replaces a user. |
| 19 | /// |
| 20 | /// The user's organisation must already exist: the foreign key runs that |
| 21 | /// direction, and saving in the other order fails. |
| 22 | fn save(&self, user: &User) -> impl Future<Output = RepositoryResult<()>> + Send; |
| 23 | |
| 24 | /// Whether any user exists. Drives first-boot bootstrap. |
| 25 | fn any_exist(&self) -> impl Future<Output = RepositoryResult<bool>> + Send; |
| 26 | |
| 27 | /// The only user, when there is exactly one. |
| 28 | /// |
| 29 | /// `None` when the instance is unclaimed **and** when more than one user exists — |
| 30 | /// the second case is deliberate rather than a shortcut. "Who owns this instance" |
| 31 | /// has no answer once registration exists, so this refuses to guess instead of |
| 32 | /// returning whichever row happened to come back first. Milestone 7 has to define |
| 33 | /// the concept properly; until then a personal instance has one user and this is |
| 34 | /// unambiguous. |
| 35 | fn sole_user(&self) -> impl Future<Output = RepositoryResult<Option<User>>> + Send; |
| 36 | } |