|
|
@ -71,7 +71,7 @@ impl UserRepository {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn create(&self, user: &User) -> Result<()> {
|
|
|
|
pub fn create(&self, user: &User) -> Result<()> {
|
|
|
|
if let Some(_) = self.read_by_login(user.login())? {
|
|
|
|
if self.read_by_login(user.login())?.is_some() {
|
|
|
|
return Err(Box::new(UserAlreadyExistsError));
|
|
|
|
return Err(Box::new(UserAlreadyExistsError));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -81,7 +81,7 @@ impl UserRepository {
|
|
|
|
self.table
|
|
|
|
self.table
|
|
|
|
));
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
let uuid = cassandra_cpp::Uuid::from(user.id().clone());
|
|
|
|
let uuid = cassandra_cpp::Uuid::from(*user.id());
|
|
|
|
query.bind_uuid(0, uuid).expect("Binds the id");
|
|
|
|
query.bind_uuid(0, uuid).expect("Binds the id");
|
|
|
|
query.bind_string(1, user.login()).expect("Binds the login");
|
|
|
|
query.bind_string(1, user.login()).expect("Binds the login");
|
|
|
|
query.bind_string(2, user.hash()).expect("Binds the hash");
|
|
|
|
query.bind_string(2, user.hash()).expect("Binds the hash");
|
|
|
@ -91,15 +91,17 @@ impl UserRepository {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn read(&self, id: &uuid::Uuid) -> Result<Option<User>> {
|
|
|
|
pub fn read(&self, id: &uuid::Uuid) -> Result<Option<User>> {
|
|
|
|
let uuid = cassandra_cpp::Uuid::from(id.clone());
|
|
|
|
let uuid = cassandra_cpp::Uuid::from(*id);
|
|
|
|
// There is no OR in cassandra statements
|
|
|
|
// There is no OR in cassandra statements
|
|
|
|
let mut query = stmt!(&format!("SELECT JSON * FROM {} WHERE id = ?", self.table));
|
|
|
|
let mut query = stmt!(&format!("SELECT JSON * FROM {} WHERE id = ?", self.table));
|
|
|
|
query.bind_uuid(0, uuid).expect("Binds id");
|
|
|
|
query.bind_uuid(0, uuid).expect("Binds id");
|
|
|
|
|
|
|
|
|
|
|
|
Ok(match self.session.execute(&query).wait()?.first_row() {
|
|
|
|
Ok(self
|
|
|
|
Some(row) => Some(User::from_json(&format!("{row}"))),
|
|
|
|
.session
|
|
|
|
None => None,
|
|
|
|
.execute(&query)
|
|
|
|
})
|
|
|
|
.wait()?
|
|
|
|
|
|
|
|
.first_row()
|
|
|
|
|
|
|
|
.map(|row| User::from_json(&format!("{row}"))))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn read_by_login(&self, login: &str) -> Result<Option<User>> {
|
|
|
|
pub fn read_by_login(&self, login: &str) -> Result<Option<User>> {
|
|
|
@ -108,10 +110,12 @@ impl UserRepository {
|
|
|
|
self.table
|
|
|
|
self.table
|
|
|
|
));
|
|
|
|
));
|
|
|
|
query.bind_string(0, login).expect("Binds login");
|
|
|
|
query.bind_string(0, login).expect("Binds login");
|
|
|
|
Ok(match self.session.execute(&query).wait()?.first_row() {
|
|
|
|
Ok(self
|
|
|
|
Some(row) => Some(User::from_json(&format!("{row}"))),
|
|
|
|
.session
|
|
|
|
None => None,
|
|
|
|
.execute(&query)
|
|
|
|
})
|
|
|
|
.wait()?
|
|
|
|
|
|
|
|
.first_row()
|
|
|
|
|
|
|
|
.map(|row| User::from_json(&format!("{row}"))))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn read_all(&self) -> Result<Vec<User>> {
|
|
|
|
pub fn read_all(&self) -> Result<Vec<User>> {
|
|
|
@ -126,7 +130,7 @@ impl UserRepository {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn update(&self, user: &User) -> Result<()> {
|
|
|
|
pub fn update(&self, user: &User) -> Result<()> {
|
|
|
|
match self.read(&user.id())? {
|
|
|
|
match self.read(user.id())? {
|
|
|
|
Some(u) => {
|
|
|
|
Some(u) => {
|
|
|
|
log::info!("Modifying {u:?} to represent {user:?}");
|
|
|
|
log::info!("Modifying {u:?} to represent {user:?}");
|
|
|
|
|
|
|
|
|
|
|
@ -136,7 +140,7 @@ impl UserRepository {
|
|
|
|
self.table
|
|
|
|
self.table
|
|
|
|
));
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
let uuid = cassandra_cpp::Uuid::from(user.id().clone());
|
|
|
|
let uuid = cassandra_cpp::Uuid::from(*user.id());
|
|
|
|
query.bind_string(0, user.login()).expect("Binds the login");
|
|
|
|
query.bind_string(0, user.login()).expect("Binds the login");
|
|
|
|
query.bind_string(1, user.hash()).expect("Binds the hash");
|
|
|
|
query.bind_string(1, user.hash()).expect("Binds the hash");
|
|
|
|
query.bind_string(2, user.salt()).expect("Binds the salt");
|
|
|
|
query.bind_string(2, user.salt()).expect("Binds the salt");
|
|
|
@ -147,5 +151,4 @@ impl UserRepository {
|
|
|
|
None => Err(Box::new(UserDoesNotExistError)),
|
|
|
|
None => Err(Box::new(UserDoesNotExistError)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|