From a739b00bc366758be9c452979cc4b4c831dd8a75 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Tue, 28 Jun 2022 09:42:00 -0400 Subject: tool: FMT --- src/handlers/planets.rs | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'src/handlers/planets.rs') diff --git a/src/handlers/planets.rs b/src/handlers/planets.rs index 2c66324..8593026 100644 --- a/src/handlers/planets.rs +++ b/src/handlers/planets.rs @@ -1,14 +1,14 @@ use axum::Extension; +use axum::{extract::Path, response::IntoResponse, Json}; use axum_macros::debug_handler; -use axum::{response::IntoResponse, Json, extract::Path}; use solarlib::ship::{DbShip, Ship}; use tokio::process::Command; use tracing::{error, instrument}; -use solarlib::star::{Star, NewPlanet}; -use solarlib::planet::Planet; use solarlib::errors::Error as SolarlibError; +use solarlib::planet::Planet; +use solarlib::star::{NewPlanet, Star}; use crate::{errors::*, get_star, State}; use std::sync::Arc; @@ -16,14 +16,13 @@ use std::sync::Arc; pub async fn list() -> JsonResult>> { let con_url = std::env::var("QEMU_URL").unwrap_or("qemu:///system".to_string()); let mut star = Star::new(con_url)?; - + let inhabitants = star.inhabitants()?; Ok(Json(inhabitants)) } pub async fn get(Path(uuid): Path) -> JsonResult> { - let con_url = std::env::var("QEMU_URL").unwrap_or("qemu:///system".to_string()); let mut star = Star::new(con_url)?; @@ -79,7 +78,7 @@ pub async fn reboot(Path(uuid): Path) -> NoneResult { } else { return Err(ServiceError::NotFound); } - + Ok(()) } @@ -113,7 +112,10 @@ pub async fn new_planet(Json(new_planet): Json) -> JsonResult) -> JsonResult { - match e { - SolarlibError::MissingImage(_) => { - ship.download(&s)?; - return Ok(Json(s.planet(new_planet.name, new_planet.max_mem, new_planet.max_cpus, new_planet.disk_size_mb, ship.clone())?)); - }, - _ => { - return Err(ServiceError::Solarlib(e)); - } + Err(e) => match e { + SolarlibError::MissingImage(_) => { + ship.download(&s)?; + return Ok(Json(s.planet( + new_planet.name, + new_planet.max_mem, + new_planet.max_cpus, + new_planet.disk_size_mb, + ship.clone(), + )?)); + } + _ => { + return Err(ServiceError::Solarlib(e)); } }, Ok(r) => { @@ -142,7 +154,6 @@ pub async fn new_planet(Json(new_planet): Json) -> JsonResult) -> NoneResult { let mut s = get_star()?; -- cgit v1.2.3