fabaccess-bffh/bffhd/capnp/user_system.rs

70 lines
1.8 KiB
Rust
Raw Normal View History

use capnp::capability::Promise;
2022-03-21 00:01:50 +01:00
use capnp_rpc::pry;
use api::usersystem_capnp::user_system::{
2022-04-21 23:02:58 +02:00
info, manage,
};
2022-04-26 23:21:43 +02:00
use crate::capnp::user::User;
2022-03-15 20:00:43 +01:00
2022-03-12 17:31:53 +01:00
use crate::session::SessionHandle;
2022-04-26 23:21:43 +02:00
2022-03-15 19:14:04 +01:00
#[derive(Clone)]
pub struct Users {
2022-03-12 17:31:53 +01:00
session: SessionHandle,
}
impl Users {
2022-03-12 17:31:53 +01:00
pub fn new(session: SessionHandle) -> Self {
Self { session }
}
}
impl info::Server for Users {
fn get_user_self(
&mut self,
_: info::GetUserSelfParams,
mut result: info::GetUserSelfResults,
) -> Promise<(), ::capnp::Error> {
2022-04-21 23:02:58 +02:00
let builder = result.get();
User::build(self.session.clone(), builder);
Promise::ok(())
}
}
impl manage::Server for Users {
fn get_user_list(
&mut self,
_: manage::GetUserListParams,
2022-03-21 00:01:50 +01:00
mut result: manage::GetUserListResults,
) -> Promise<(), ::capnp::Error> {
2022-03-21 00:01:50 +01:00
let userdb = self.session.users.into_inner();
let users = pry!(userdb.get_all()
.map_err(|e| capnp::Error::failed(format!("UserDB error: {:?}", e))));
let mut builder = result.get().init_user_list(users.len() as u32);
let me = User::new_self(self.session.clone());
for (i, (_, user)) in users.into_iter().enumerate() {
me.fill(user, builder.reborrow().get(i as u32));
}
Promise::ok(())
}
fn add_user(
&mut self,
_: manage::AddUserParams,
_: manage::AddUserResults,
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
fn remove_user(
&mut self,
_: manage::RemoveUserParams,
_: manage::RemoveUserResults,
) -> Promise<(), ::capnp::Error> {
Promise::err(::capnp::Error::unimplemented(
"method not implemented".to_string(),
))
}
}