refactor sync server into modules
This commit is contained in:
25
sync-server/src/api/add_version.rs
Normal file
25
sync-server/src/api/add_version.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use crate::server::SyncServer;
|
||||
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)]
|
||||
pub(crate) struct AddVersionRequest {
|
||||
// TODO: temporary!
|
||||
#[serde(default)]
|
||||
history_segment: HistorySegment,
|
||||
}
|
||||
|
||||
#[post("/client/{client_id}/add-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)>,
|
||||
body: web::Json<AddVersionRequest>,
|
||||
) -> Result<impl Responder> {
|
||||
let result = data
|
||||
.add_version(client_id, parent_version_id, &body.history_segment)
|
||||
.map_err(|e| error::InternalError::new(e, StatusCode::INTERNAL_SERVER_ERROR))?;
|
||||
Ok(HttpResponse::Ok().json(result))
|
||||
}
|
||||
19
sync-server/src/api/get_child_version.rs
Normal file
19
sync-server/src/api/get_child_version.rs
Normal 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"))
|
||||
}
|
||||
}
|
||||
2
sync-server/src/api/mod.rs
Normal file
2
sync-server/src/api/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub(crate) mod add_version;
|
||||
pub(crate) mod get_child_version;
|
||||
Reference in New Issue
Block a user