Reorganize the core API (#60)

This commit is contained in:
Dustin J. Mitchell 2024-11-19 18:22:42 -05:00 committed by GitHub
parent 2b1ad12a79
commit 5ad3b8e8bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 638 additions and 1813 deletions

View file

@ -1,5 +1,5 @@
use actix_web::{error, http::StatusCode, web, HttpRequest, Result, Scope};
use taskchampion_sync_server_core::{ClientId, ServerConfig, Storage};
use actix_web::{error, web, HttpRequest, Result, Scope};
use taskchampion_sync_server_core::{ClientId, Server, ServerError};
mod add_snapshot;
mod add_version;
@ -27,8 +27,7 @@ pub(crate) const SNAPSHOT_REQUEST_HEADER: &str = "X-Snapshot-Request";
/// The type containing a reference to the persistent state for the server
pub(crate) struct ServerState {
pub(crate) storage: Box<dyn Storage>,
pub(crate) config: ServerConfig,
pub(crate) server: Server,
}
pub(crate) fn api_scope() -> Scope {
@ -39,9 +38,17 @@ pub(crate) fn api_scope() -> Scope {
.service(add_snapshot::service)
}
/// Convert a failure::Error to an Actix ISE
fn failure_to_ise(err: anyhow::Error) -> impl actix_web::ResponseError {
error::InternalError::new(err, StatusCode::INTERNAL_SERVER_ERROR)
/// Convert a `anyhow::Error` to an Actix ISE
fn failure_to_ise(err: anyhow::Error) -> actix_web::Error {
error::ErrorInternalServerError(err)
}
/// Convert a ServerError to an Actix error
fn server_error_to_actix(err: ServerError) -> actix_web::Error {
match err {
ServerError::NoSuchClient => error::ErrorNotFound(err),
ServerError::Other(err) => error::ErrorInternalServerError(err),
}
}
/// Get the client id