Update formatting
This commit is contained in:
parent
dda356ea00
commit
49638e5aa7
27 changed files with 239 additions and 232 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use crate::{config::Config, consts::CONFIG_PATH, database::Database};
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::{config::Config, consts::CONFIG_PATH, database::Database};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AppState {
|
||||
pub config: Config,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use rand::distributions::Alphanumeric;
|
||||
use rand::{thread_rng, Rng};
|
||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ use anyhow::{Context, Result};
|
|||
use models::{
|
||||
DocumentId, DocumentVersionId, DocumentVersionWithoutContent, StoredDocumentVersion, VaultId,
|
||||
};
|
||||
use sqlx::sqlite::SqliteConnectOptions;
|
||||
use sqlx::types::chrono::Utc;
|
||||
use sqlx::{sqlite::SqliteConnectOptions, types::chrono::Utc};
|
||||
pub mod models;
|
||||
use sqlx::{sqlite::SqlitePoolOptions, Pool, Sqlite};
|
||||
|
||||
|
|
|
|||
|
|
@ -21,9 +21,7 @@ pub struct StoredDocumentVersion {
|
|||
}
|
||||
|
||||
impl StoredDocumentVersion {
|
||||
pub fn content_as_string(&self) -> String {
|
||||
String::from_utf8_lossy(&self.content).to_string()
|
||||
}
|
||||
pub fn content_as_string(&self) -> String { String::from_utf8_lossy(&self.content).to_string() }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||
|
|
|
|||
|
|
@ -82,9 +82,7 @@ impl OperationOutput for SyncServerError {
|
|||
type Inner = Self;
|
||||
}
|
||||
|
||||
pub fn init_error(error: anyhow::Error) -> SyncServerError {
|
||||
SyncServerError::InitError(error)
|
||||
}
|
||||
pub fn init_error(error: anyhow::Error) -> SyncServerError { SyncServerError::InitError(error) }
|
||||
|
||||
pub fn server_error(error: anyhow::Error) -> SyncServerError {
|
||||
warn!("Server error: {:?}", error);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use crate::app_state::AppState;
|
||||
use aide::{
|
||||
axum::{
|
||||
routing::{delete, get, post, put},
|
||||
|
|
@ -7,12 +6,15 @@ use aide::{
|
|||
openapi::{Info, OpenApi},
|
||||
scalar::Scalar,
|
||||
};
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::{extract::DefaultBodyLimit, Extension};
|
||||
use axum::{extract::WebSocketUpgrade, Json};
|
||||
use anyhow::{Context, Result};
|
||||
use axum::{
|
||||
extract::{DefaultBodyLimit, WebSocketUpgrade},
|
||||
response::{IntoResponse, Response},
|
||||
Extension, Json,
|
||||
};
|
||||
use log::info;
|
||||
|
||||
use crate::app_state::AppState;
|
||||
mod auth;
|
||||
mod create_document;
|
||||
mod delete_document;
|
||||
|
|
@ -90,6 +92,4 @@ async fn handler(ws: WebSocketUpgrade) -> Response {
|
|||
})
|
||||
}
|
||||
|
||||
async fn serve_api(Extension(api): Extension<OpenApi>) -> impl IntoResponse {
|
||||
Json(api)
|
||||
}
|
||||
async fn serve_api(Extension(api): Extension<OpenApi>) -> impl IntoResponse { Json(api) }
|
||||
|
|
|
|||
|
|
@ -1,21 +1,20 @@
|
|||
use crate::app_state::AppState;
|
||||
use crate::database::models::DocumentVersionWithoutContent;
|
||||
use crate::database::models::StoredDocumentVersion;
|
||||
use crate::database::models::VaultId;
|
||||
use crate::errors::client_error;
|
||||
use crate::errors::server_error;
|
||||
use crate::errors::SyncServerError;
|
||||
use anyhow::Context;
|
||||
use axum::extract::Path;
|
||||
use axum::extract::State;
|
||||
use axum::Json;
|
||||
use axum_extra::headers::authorization::Bearer;
|
||||
use axum_extra::headers::Authorization;
|
||||
use axum_extra::TypedHeader;
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
Json,
|
||||
};
|
||||
use axum_extra::{
|
||||
headers::{authorization::Bearer, Authorization},
|
||||
TypedHeader,
|
||||
};
|
||||
use sync_lib::base64_to_bytes;
|
||||
|
||||
use super::auth::auth;
|
||||
use super::requests::CreateDocumentVersion;
|
||||
use super::{auth::auth, requests::CreateDocumentVersion};
|
||||
use crate::{
|
||||
app_state::AppState,
|
||||
database::models::{DocumentVersionWithoutContent, StoredDocumentVersion, VaultId},
|
||||
errors::{client_error, server_error, SyncServerError},
|
||||
};
|
||||
|
||||
#[axum::debug_handler]
|
||||
pub async fn create_document(
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
use crate::app_state::AppState;
|
||||
use crate::database::models::DocumentId;
|
||||
use crate::database::models::StoredDocumentVersion;
|
||||
use crate::database::models::VaultId;
|
||||
use crate::errors::not_found_error;
|
||||
use crate::errors::server_error;
|
||||
use crate::errors::SyncServerError;
|
||||
use anyhow::anyhow;
|
||||
use anyhow::Context;
|
||||
use axum::extract::Path;
|
||||
use axum::extract::State;
|
||||
use axum::Json;
|
||||
use axum_extra::headers::authorization::Bearer;
|
||||
use axum_extra::headers::Authorization;
|
||||
use axum_extra::TypedHeader;
|
||||
use anyhow::{anyhow, Context};
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
Json,
|
||||
};
|
||||
use axum_extra::{
|
||||
headers::{authorization::Bearer, Authorization},
|
||||
TypedHeader,
|
||||
};
|
||||
|
||||
use super::auth::auth;
|
||||
use super::requests::DeleteDocumentVersion;
|
||||
use super::{auth::auth, requests::DeleteDocumentVersion};
|
||||
use crate::{
|
||||
app_state::AppState,
|
||||
database::models::{DocumentId, StoredDocumentVersion, VaultId},
|
||||
errors::{not_found_error, server_error, SyncServerError},
|
||||
};
|
||||
|
||||
#[axum::debug_handler]
|
||||
pub async fn delete_document(
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
use crate::app_state::AppState;
|
||||
use crate::database::models::DocumentId;
|
||||
use crate::database::models::DocumentVersion;
|
||||
use crate::database::models::VaultId;
|
||||
use crate::errors::not_found_error;
|
||||
use crate::errors::server_error;
|
||||
use crate::errors::SyncServerError;
|
||||
use anyhow::anyhow;
|
||||
use axum::extract::Path;
|
||||
use axum::extract::State;
|
||||
use axum::Json;
|
||||
use axum_extra::headers::authorization::Bearer;
|
||||
use axum_extra::headers::Authorization;
|
||||
use axum_extra::TypedHeader;
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
Json,
|
||||
};
|
||||
use axum_extra::{
|
||||
headers::{authorization::Bearer, Authorization},
|
||||
TypedHeader,
|
||||
};
|
||||
|
||||
use super::auth::auth;
|
||||
use crate::{
|
||||
app_state::AppState,
|
||||
database::models::{DocumentId, DocumentVersion, VaultId},
|
||||
errors::{not_found_error, server_error, SyncServerError},
|
||||
};
|
||||
|
||||
#[axum::debug_handler]
|
||||
pub async fn fetch_latest_document_version(
|
||||
|
|
|
|||
|
|
@ -1,16 +1,18 @@
|
|||
use crate::app_state::AppState;
|
||||
use crate::database::models::DocumentVersionWithoutContent;
|
||||
use crate::database::models::VaultId;
|
||||
use crate::errors::server_error;
|
||||
use crate::errors::SyncServerError;
|
||||
use axum::extract::Path;
|
||||
use axum::extract::State;
|
||||
use axum::Json;
|
||||
use axum_extra::headers::authorization::Bearer;
|
||||
use axum_extra::headers::Authorization;
|
||||
use axum_extra::TypedHeader;
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
Json,
|
||||
};
|
||||
use axum_extra::{
|
||||
headers::{authorization::Bearer, Authorization},
|
||||
TypedHeader,
|
||||
};
|
||||
|
||||
use super::auth::auth;
|
||||
use crate::{
|
||||
app_state::AppState,
|
||||
database::models::{DocumentVersionWithoutContent, VaultId},
|
||||
errors::{server_error, SyncServerError},
|
||||
};
|
||||
|
||||
#[axum::debug_handler]
|
||||
pub async fn fetch_latest_documents(
|
||||
|
|
|
|||
|
|
@ -1,25 +1,20 @@
|
|||
use crate::app_state::AppState;
|
||||
use crate::database::models::DocumentId;
|
||||
use crate::database::models::DocumentVersionWithoutContent;
|
||||
use crate::database::models::StoredDocumentVersion;
|
||||
use crate::database::models::VaultId;
|
||||
use crate::errors::client_error;
|
||||
use crate::errors::not_found_error;
|
||||
use crate::errors::server_error;
|
||||
use crate::errors::SyncServerError;
|
||||
use anyhow::anyhow;
|
||||
use anyhow::Context;
|
||||
use axum::extract::Path;
|
||||
use axum::extract::State;
|
||||
use axum::Json;
|
||||
use axum_extra::headers::authorization::Bearer;
|
||||
use axum_extra::headers::Authorization;
|
||||
use axum_extra::TypedHeader;
|
||||
use sync_lib::base64_to_bytes;
|
||||
use sync_lib::base64_to_string;
|
||||
use anyhow::{anyhow, Context};
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
Json,
|
||||
};
|
||||
use axum_extra::{
|
||||
headers::{authorization::Bearer, Authorization},
|
||||
TypedHeader,
|
||||
};
|
||||
use sync_lib::{base64_to_bytes, base64_to_string};
|
||||
|
||||
use super::auth::auth;
|
||||
use super::requests::UpdateDocumentVersion;
|
||||
use super::{auth::auth, requests::UpdateDocumentVersion};
|
||||
use crate::{
|
||||
app_state::AppState,
|
||||
database::models::{DocumentId, DocumentVersionWithoutContent, StoredDocumentVersion, VaultId},
|
||||
errors::{client_error, not_found_error, server_error, SyncServerError},
|
||||
};
|
||||
|
||||
#[axum::debug_handler]
|
||||
pub async fn update_document(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue