Fmt + Clippy

main
Joey Hines 2021-10-24 13:21:30 -06:00
parent 8e6b652d5e
commit b79db6029e
No known key found for this signature in database
GPG Key ID: 80F567B5C968F91B
8 changed files with 26 additions and 30 deletions

View File

@ -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 {}

View File

@ -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,21 +39,16 @@ pub trait Command {
fn user_is_authorized(user: &Option<Player>) -> Result<()> {
if Self::command_level() == CommandLevel::ALL {
Ok(())
}
else {
if let Some(user) = user {
} else if let Some(user) = user {
if user.auth_level >= Self::command_level() {
Ok(())
}
else {
} else {
Err(GeoffreyAPIError::PermissionInsufficient)
}
}
else {
} else {
Err(GeoffreyAPIError::PlayerNotRegistered)
}
}
}
}
pub fn handle_command<T: Command>(ctx: Arc<Context>, req: T::Req) -> Result<T::Resp> {
@ -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),
}
}

View File

@ -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)
}
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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;

View File

@ -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 {