Fmt + Clippy
parent
8e6b652d5e
commit
b79db6029e
|
@ -4,9 +4,9 @@ use crate::Result;
|
|||
use geoffrey_db::helper::load_location;
|
||||
use geoffrey_models::models::locations::{Location, LocationDb};
|
||||
use geoffrey_models::models::parameters::add_location_params::AddLocationParams;
|
||||
use geoffrey_models::models::player::Player;
|
||||
use geoffrey_models::models::CommandLevel;
|
||||
use std::sync::Arc;
|
||||
use geoffrey_models::models::player::Player;
|
||||
|
||||
pub struct AddLocation {}
|
||||
|
||||
|
|
|
@ -2,7 +2,11 @@ use crate::commands::add_location::AddLocation;
|
|||
use crate::commands::find::FindCommand;
|
||||
use crate::commands::register::Register;
|
||||
use crate::context::Context;
|
||||
use crate::helper::get_player_from_req;
|
||||
use crate::Result;
|
||||
use geoffrey_models::models::parameters::CommandRequest;
|
||||
use geoffrey_models::models::player::Player;
|
||||
use geoffrey_models::models::response::api_error::GeoffreyAPIError;
|
||||
use geoffrey_models::models::response::APIResponse;
|
||||
use geoffrey_models::models::CommandLevel;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
@ -11,11 +15,6 @@ use std::fmt::Debug;
|
|||
use std::sync::Arc;
|
||||
use warp::filters::BoxedFilter;
|
||||
use warp::Filter;
|
||||
use geoffrey_models::models::player::Player;
|
||||
use crate::helper::get_player_from_req;
|
||||
use geoffrey_models::models::response::api_error::GeoffreyAPIError;
|
||||
use geoffrey_models::models::parameters::CommandRequest;
|
||||
|
||||
|
||||
pub mod add_location;
|
||||
pub mod find;
|
||||
|
@ -40,19 +39,14 @@ pub trait Command {
|
|||
fn user_is_authorized(user: &Option<Player>) -> Result<()> {
|
||||
if Self::command_level() == CommandLevel::ALL {
|
||||
Ok(())
|
||||
}
|
||||
else {
|
||||
if let Some(user) = user {
|
||||
if user.auth_level >= Self::command_level() {
|
||||
Ok(())
|
||||
}
|
||||
else {
|
||||
Err(GeoffreyAPIError::PermissionInsufficient)
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(GeoffreyAPIError::PlayerNotRegistered)
|
||||
} else if let Some(user) = user {
|
||||
if user.auth_level >= Self::command_level() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(GeoffreyAPIError::PermissionInsufficient)
|
||||
}
|
||||
} else {
|
||||
Err(GeoffreyAPIError::PlayerNotRegistered)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +59,7 @@ pub fn handle_command<T: Command>(ctx: Arc<Context>, req: T::Req) -> Result<T::R
|
|||
|
||||
match T::user_is_authorized(&user) {
|
||||
Ok(_) => T::run_command(ctx, req, user),
|
||||
Err(e) => Err(e)
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,11 +24,13 @@ impl Command for Register {
|
|||
CommandLevel::ALL
|
||||
}
|
||||
|
||||
fn run_command(ctx: Arc<Context>, req: Self::Req, _: Option<Player>) -> crate::Result<Self::Resp> {
|
||||
fn run_command(
|
||||
ctx: Arc<Context>,
|
||||
req: Self::Req,
|
||||
_: Option<Player>,
|
||||
) -> crate::Result<Self::Resp> {
|
||||
let player = Player::new(req.username.as_str(), req.new_user_id);
|
||||
|
||||
ctx.db
|
||||
.insert(player)
|
||||
.map_err(GeoffreyAPIError::from)
|
||||
ctx.db.insert(player).map_err(GeoffreyAPIError::from)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,4 +11,4 @@ pub fn get_player_from_req<T: CommandRequest>(db: &Database, req: &T) -> Result<
|
|||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::models::locations::LocationType;
|
||||
use crate::models::parameters::CommandRequest;
|
||||
use crate::models::player::UserID;
|
||||
use crate::models::{Position, Tunnel};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::models::player::UserID;
|
||||
use crate::models::parameters::CommandRequest;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct AddLocationParams {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use crate::models::parameters::CommandRequest;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct FindParams {
|
||||
|
|
|
@ -5,9 +5,9 @@ pub mod register_params;
|
|||
use crate::models::player::{Player, UserID};
|
||||
use crate::models::token::{Permissions, Token};
|
||||
use crate::models::CommandLevel;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use std::fmt::Debug;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
pub trait CommandRequest: Serialize + DeserializeOwned + Debug + Clone + Send + 'static {
|
||||
fn token(&self) -> u64;
|
||||
|
@ -31,4 +31,4 @@ pub trait CommandRequest: Serialize + DeserializeOwned + Debug + Clone + Send +
|
|||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::models::parameters::CommandRequest;
|
||||
use crate::models::player::UserID;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::models::parameters::CommandRequest;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct RegisterParameters {
|
||||
|
|
Loading…
Reference in New Issue