43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
use crate::commands::{Command, RequestType};
|
|
use crate::context::Context;
|
|
use crate::Result;
|
|
use geoffrey_db::helper::load_location;
|
|
use geoffrey_db::query::QueryBuilder;
|
|
use geoffrey_models::models::locations::{Location, LocationDb};
|
|
use geoffrey_models::models::parameters::info_params::InfoParams;
|
|
use geoffrey_models::models::player::Player;
|
|
use geoffrey_models::models::response::api_error::GeoffreyAPIError;
|
|
use geoffrey_models::models::CommandLevel;
|
|
use std::sync::Arc;
|
|
|
|
pub struct InfoCommand {}
|
|
|
|
impl Command for InfoCommand {
|
|
type Req = InfoParams;
|
|
type Resp = Location;
|
|
|
|
fn command_name() -> String {
|
|
"info".to_string()
|
|
}
|
|
|
|
fn request_type() -> RequestType {
|
|
RequestType::GET
|
|
}
|
|
|
|
fn command_level() -> CommandLevel {
|
|
CommandLevel::ALL
|
|
}
|
|
|
|
fn run_command(ctx: Arc<Context>, req: &Self::Req, _: Option<Player>) -> Result<Self::Resp> {
|
|
let query = QueryBuilder::<LocationDb>::default().with_name_regex(&req.location_name)?;
|
|
|
|
let location = ctx
|
|
.db
|
|
.run_query(query)?
|
|
.pop()
|
|
.ok_or(GeoffreyAPIError::EntryNotFound)?;
|
|
|
|
Ok(load_location(&ctx.db, &location)?)
|
|
}
|
|
}
|