diff --git a/sync-server/src/api/add_version.rs b/sync-server/src/api/add_version.rs index 75398ecd9..cdc96db2a 100644 --- a/sync-server/src/api/add_version.rs +++ b/sync-server/src/api/add_version.rs @@ -1,8 +1,7 @@ -use crate::server::SyncServer; +use crate::api::ServerState; use crate::types::{ClientId, HistorySegment, VersionId}; use actix_web::{error, http::StatusCode, post, web, HttpResponse, Responder, Result}; use serde::{Deserialize, Serialize}; -use std::sync::Arc; /// Request body to add_version #[derive(Serialize, Deserialize)] @@ -14,7 +13,7 @@ pub(crate) struct AddVersionRequest { #[post("/client/{client_id}/add-version/{parent_version_id}")] pub(crate) async fn service( - data: web::Data>, + data: web::Data, web::Path((client_id, parent_version_id)): web::Path<(ClientId, VersionId)>, body: web::Json, ) -> Result { diff --git a/sync-server/src/api/get_child_version.rs b/sync-server/src/api/get_child_version.rs index 8512e6f4a..4383a6fbc 100644 --- a/sync-server/src/api/get_child_version.rs +++ b/sync-server/src/api/get_child_version.rs @@ -1,11 +1,10 @@ -use crate::server::SyncServer; +use crate::api::ServerState; use crate::types::{ClientId, VersionId}; use actix_web::{error, get, http::StatusCode, web, HttpResponse, Result}; -use std::sync::Arc; #[get("/client/{client_id}/get-child-version/{parent_version_id}")] pub(crate) async fn service( - data: web::Data>, + data: web::Data, web::Path((client_id, parent_version_id)): web::Path<(ClientId, VersionId)>, ) -> Result { let result = data diff --git a/sync-server/src/api/mod.rs b/sync-server/src/api/mod.rs index b955fcc25..cdab25fca 100644 --- a/sync-server/src/api/mod.rs +++ b/sync-server/src/api/mod.rs @@ -1,2 +1,8 @@ +use crate::server::SyncServer; +use std::sync::Arc; + pub(crate) mod add_version; pub(crate) mod get_child_version; + +/// The type containing a reference to the SyncServer object in the Actix state. +pub(crate) type ServerState = Arc>; diff --git a/sync-server/src/main.rs b/sync-server/src/main.rs index 20b7b118f..191908fb2 100644 --- a/sync-server/src/main.rs +++ b/sync-server/src/main.rs @@ -1,5 +1,4 @@ use actix_web::{App, HttpServer}; -use server::SyncServer; use std::sync::Arc; mod api; @@ -10,11 +9,11 @@ mod types; #[actix_web::main] async fn main() -> std::io::Result<()> { - let sync_server = Arc::new(SyncServer::new()); + let server_state = Arc::new(Box::new(server::NullSyncServer::new())); HttpServer::new(move || { App::new() - .data(sync_server.clone()) + .data(server_state.clone()) .service(api::get_child_version::service) .service(api::add_version::service) }) diff --git a/sync-server/src/server.rs b/sync-server/src/server/mod.rs similarity index 54% rename from sync-server/src/server.rs rename to sync-server/src/server/mod.rs index 8c4bdfdf2..df4377366 100644 --- a/sync-server/src/server.rs +++ b/sync-server/src/server/mod.rs @@ -2,16 +2,34 @@ use crate::types::{AddVersionResult, ClientId, GetVersionResult, HistorySegment, use failure::Fallible; use taskchampion::Uuid; -/// The sync server's implementation; HTTP API method call through to methods on a single -/// instance of this type. -pub(crate) struct SyncServer {} +pub(crate) trait SyncServer { + fn get_child_version( + &self, + client_id: ClientId, + parent_version_id: VersionId, + ) -> Fallible>; -impl SyncServer { + fn add_version( + &self, + client_id: ClientId, + parent_version_id: VersionId, + history_segment: &HistorySegment, + ) -> Fallible; +} + +// TODO: temporary +/// A "null" sync server's implementation; HTTP API methods call through to methods on a single +/// instance of this type. +pub(crate) struct NullSyncServer {} + +impl NullSyncServer { pub(crate) fn new() -> Self { Self {} } +} - pub(crate) fn get_child_version( +impl SyncServer for NullSyncServer { + fn get_child_version( &self, _client_id: ClientId, parent_version_id: VersionId, @@ -23,7 +41,7 @@ impl SyncServer { })) } - pub(crate) fn add_version( + fn add_version( &self, _client_id: ClientId, _parent_version_id: VersionId,