add container adding

This commit is contained in:
stubbfelnewpc
2020-07-01 00:29:45 +02:00
parent 0fec303513
commit 4204e7bc25
2 changed files with 90 additions and 45 deletions

View File

@@ -23,6 +23,7 @@ use rocket_okapi::{gen::OpenApiGenerator, response::OpenApiResponder};
use schemars::JsonSchema;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::cell::RefCell;
#[derive(Serialize, Deserialize, Hash, JsonSchema, Clone)]
pub enum IdeState {
@@ -51,15 +52,15 @@ pub struct IdeStateResponse {
pub trait NixIdeManageServiceEngine {
fn fetch_current_ide_state(&self, ide_id: &str) -> Result<IdeState, Status>;
fn start_open(&self, ide_id: &str, param: &OpenGitParam) -> Result<IdeState, Status>;
fn start_open(&mut self, ide_id: &str, param: &OpenGitParam) -> Result<IdeState, Status>;
}
pub struct NixIdeManageService {
eng: Box<dyn NixIdeManageServiceEngine>,
eng: RefCell<Box<dyn NixIdeManageServiceEngine>>,
}
impl NixIdeManageService {
pub fn new(engine: Box<dyn NixIdeManageServiceEngine>) -> Self {
Self { eng: engine }
Self { eng: RefCell::new(engine) }
}
}
@@ -73,7 +74,7 @@ impl NixIdeManageServiceEngine for DummyEngine {
Ok(IdeState::OPENING)
}
fn start_open(&self, _ide_id: &str, _param: &OpenGitParam) -> Result<IdeState, Status> {
fn start_open(&mut self, _ide_id: &str, _param: &OpenGitParam) -> Result<IdeState, Status> {
Ok(IdeState::OPENING)
}
}
@@ -144,8 +145,7 @@ pub fn v1_open_inquirer_git(
};
let ide_id = create_ide_id(&param);
srv.eng
srv.eng.borrow_mut()
.start_open(&ide_id, &param)
.map_err(|_| Error {})
.and_then(|starting_result| {
@@ -163,7 +163,7 @@ pub fn v1_ide_state(
ide_id: String,
srv: State<NixIdeManageService>,
) -> Result<Json<IdeStateResponse>, status::NotFound<String>> {
srv.eng
srv.eng.borrow()
.fetch_current_ide_state(&ide_id)
.and_then(|ide_state| {
Ok(Json(IdeStateResponse {