use crate::db::{Dao, TenebrousDbConn}; use crate::errors::Error; use crate::models::characters::Character; use crate::models::users::User; mod cofd; pub(crate) fn routes() -> Vec { routes![ cofd::update_basic_info, cofd::update_attribute_value, cofd::update_skill, cofd::update_skill_value, cofd::add_condition, cofd::remove_condition ] } /// Load the character belonging to the given user, as long as they're /// the owner of that character. Returns an error if user is not /// logged in, the owner of the character is not found, or the logged /// in user does not have the permission to access this character. async fn load_character( conn: &TenebrousDbConn<'_>, logged_in_user: Option<&User>, owner: &str, character_id: i32, ) -> Result { let logged_in_user = logged_in_user.ok_or(Error::NotLoggedIn)?; let character: Character = conn .load_character(character_id) .await? .ok_or(Error::NotFound)?; if &logged_in_user.username != owner { return Err(Error::NoPermission); } Ok(character) }