refactor sync server into modules

This commit is contained in:
Dustin J. Mitchell
2020-11-25 23:16:05 -05:00
parent d0bfbbb7f0
commit 087333a227
9 changed files with 1504 additions and 102 deletions

View File

@@ -0,0 +1,19 @@
use crate::server::SyncServer;
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<Arc<SyncServer>>,
web::Path((client_id, parent_version_id)): web::Path<(ClientId, VersionId)>,
) -> Result<HttpResponse> {
let result = data
.get_child_version(client_id, parent_version_id)
.map_err(|e| error::InternalError::new(e, StatusCode::INTERNAL_SERVER_ERROR))?;
if let Some(result) = result {
Ok(HttpResponse::Ok().json(result))
} else {
Err(error::ErrorNotFound("no such version"))
}
}