use crate::commands::{Command, RequestType}; use crate::context::Context; use crate::Result; use geoffrey_db::helper::{find_location_by_name, load_location}; use geoffrey_models::models::locations::Location; use geoffrey_models::models::parameters::set_portal_params::SetPortalParams; use geoffrey_models::models::player::Player; use geoffrey_models::models::CommandLevel; use std::sync::Arc; pub struct SetPortal {} impl Command for SetPortal { type Req = SetPortalParams; type Resp = Location; fn command_name() -> String { "set_portal".to_string() } fn request_type() -> RequestType { RequestType::POST } fn command_level() -> CommandLevel { CommandLevel::REGISTERED } fn run_command(ctx: Arc, req: &Self::Req, user: Option) -> Result { let user = user.unwrap(); let mut location = find_location_by_name(&ctx.db, &req.loc_name, user.id.unwrap())?; location.portal = Some(req.portal.clone()); let location = ctx.db.insert(location)?; load_location(&ctx.db, &location).map_err(|err| err.into()) } }