rustfmt
This commit is contained in:
parent
3c67388fae
commit
4f8d6ec3d0
16 changed files with 61 additions and 60 deletions
|
@ -1,9 +1,8 @@
|
|||
use reqwest::Method;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::UbisyncRequest;
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct AppRegisterRequest {
|
||||
pub name: String,
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use reqwest::Method;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::{ElementContent, ElementId, Element};
|
||||
use crate::types::{Element, ElementContent, ElementId};
|
||||
|
||||
use super::UbisyncRequest;
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ElementCreateRequest {
|
||||
pub content: ElementContent,
|
||||
|
@ -28,7 +27,6 @@ impl UbisyncRequest for ElementCreateRequest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ElementGetRequest;
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ pub mod messages;
|
|||
pub mod peer;
|
||||
pub mod types;
|
||||
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! tracing_setup {
|
||||
($level:expr) => {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::{MessageId, ElementId, ElementContent};
|
||||
use crate::types::{ElementContent, ElementId, MessageId};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Message {
|
||||
|
@ -9,8 +9,6 @@ pub struct Message {
|
|||
content: MessageContent,
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct MessageRelations {
|
||||
pub parents: Vec<MessageId>,
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use std::fmt::Display;
|
||||
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum UbisyncError {
|
||||
InvalidNodeReply(String),
|
||||
|
@ -12,7 +10,9 @@ impl Display for UbisyncError {
|
|||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::InvalidNodeReply(msg) => write!(f, "Invalid reply from ubisync node: {}", msg),
|
||||
Self::AppRegistrationFailed => write!(f, "Registrating this app at the ubisync node failed."),
|
||||
Self::AppRegistrationFailed => {
|
||||
write!(f, "Registrating this app at the ubisync node failed.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
use axum::{Router, routing::get, response::{Response, IntoResponse}, http::StatusCode, Json};
|
||||
use axum::{
|
||||
http::StatusCode,
|
||||
response::{IntoResponse, Response},
|
||||
routing::get,
|
||||
Json, Router,
|
||||
};
|
||||
use tokio::{net::TcpListener, task::JoinHandle};
|
||||
|
||||
use crate::{config::ApiConfig, state::ApiState};
|
||||
|
@ -75,7 +80,6 @@ impl ApiBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
async fn list_available_versions() -> Response {
|
||||
(StatusCode::OK, Json { 0: vec!["v0"] }).into_response()
|
||||
}
|
|
@ -11,8 +11,8 @@ use tracing::debug;
|
|||
use crate::state::ApiState;
|
||||
use ubisync_lib::{
|
||||
api::element::{
|
||||
ElementCreateRequest, ElementCreateResponse, ElementGetResponse, ElementSetRequest,
|
||||
ElementSetResponse, ElementRemoveResponse,
|
||||
ElementCreateRequest, ElementCreateResponse, ElementGetResponse, ElementRemoveResponse,
|
||||
ElementSetRequest, ElementSetResponse,
|
||||
},
|
||||
types::ElementId,
|
||||
};
|
||||
|
@ -27,9 +27,7 @@ pub(super) async fn get(Path(id): Path<ElementId>, s: Extension<Arc<ApiState>>)
|
|||
},
|
||||
)
|
||||
.into_response(),
|
||||
Err(_) => {
|
||||
StatusCode::NOT_FOUND.into_response()
|
||||
}
|
||||
Err(_) => StatusCode::NOT_FOUND.into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,7 +70,13 @@ pub(super) async fn set(
|
|||
pub(super) async fn remove(Path(id): Path<ElementId>, s: Extension<Arc<ApiState>>) -> Response {
|
||||
let res = s.remove_element(&id);
|
||||
match res {
|
||||
Ok(_) => (StatusCode::OK, Json { 0: ElementRemoveResponse }).into_response(),
|
||||
Ok(_) => (
|
||||
StatusCode::OK,
|
||||
Json {
|
||||
0: ElementRemoveResponse,
|
||||
},
|
||||
)
|
||||
.into_response(),
|
||||
Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ use tokio::task::JoinHandle;
|
|||
use crate::state::CommState;
|
||||
use crate::Config;
|
||||
|
||||
|
||||
pub struct CommHandle {
|
||||
state: Arc<CommState>,
|
||||
i2p_server: Arc<I2pListener>,
|
||||
|
@ -196,7 +195,8 @@ impl CommHandle {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {use i2p::net::I2pListener;
|
||||
mod tests {
|
||||
use i2p::net::I2pListener;
|
||||
use i2p::sam::StreamForward;
|
||||
use i2p::sam_options::SAMOptions;
|
||||
use i2p::Session;
|
||||
|
|
|
@ -5,11 +5,9 @@ use api::{Api, ApiBuilder};
|
|||
use comm::CommHandle;
|
||||
use config::Config;
|
||||
use i2p::net::I2pSocketAddr;
|
||||
use state::{State, CommState, ApiState};
|
||||
use state::{ApiState, CommState, State};
|
||||
use ubisync_lib::{peer::Peer, types::PeerId};
|
||||
|
||||
|
||||
|
||||
pub mod api;
|
||||
pub mod comm;
|
||||
pub mod config;
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
use ubisync::{Ubisync, config::Config};
|
||||
|
||||
|
||||
use ubisync::{config::Config, Ubisync};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let _node = Ubisync::new(&Config::default()).await.unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,10 @@ use chrono::Utc;
|
|||
use cozo::DbInstance;
|
||||
use jsonwebtoken::{DecodingKey, EncodingKey, Validation};
|
||||
use tracing::debug;
|
||||
use ubisync_lib::{types::{ElementContent, ElementId, Element}, messages::MessageContent};
|
||||
use ubisync_lib::{
|
||||
messages::MessageContent,
|
||||
types::{Element, ElementContent, ElementId},
|
||||
};
|
||||
|
||||
use crate::{api::v0::app::AppId, state::queries};
|
||||
|
||||
|
@ -32,13 +35,7 @@ impl ApiState {
|
|||
pub fn add_app(&self, name: &str, description: &str) -> anyhow::Result<AppId> {
|
||||
let id = AppId::new();
|
||||
let last_access = Utc::now();
|
||||
queries::apps::add(
|
||||
self.db(),
|
||||
&id,
|
||||
&last_access,
|
||||
name,
|
||||
description,
|
||||
)?;
|
||||
queries::apps::add(self.db(), &id, &last_access, name, description)?;
|
||||
debug!("Successfully added app");
|
||||
|
||||
Ok(id)
|
||||
|
@ -103,7 +100,7 @@ impl ApiState {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use tracing::Level;
|
||||
use ubisync_lib::{types::ElementContent, tracing_setup};
|
||||
use ubisync_lib::{tracing_setup, types::ElementContent};
|
||||
|
||||
use crate::state::State;
|
||||
|
||||
|
|
|
@ -3,7 +3,10 @@ use std::sync::Arc;
|
|||
use cozo::DbInstance;
|
||||
use tracing::debug;
|
||||
|
||||
use ubisync_lib::{types::{Element, ElementContent, ElementId, MessageId, PeerId}, peer::Peer};
|
||||
use ubisync_lib::{
|
||||
peer::Peer,
|
||||
types::{Element, ElementContent, ElementId, MessageId, PeerId},
|
||||
};
|
||||
|
||||
use crate::state::queries;
|
||||
|
||||
|
@ -85,7 +88,10 @@ mod tests {
|
|||
use super::CommState;
|
||||
|
||||
use tracing::Level;
|
||||
use ubisync_lib::{types::{ElementContent, ElementId, MessageId}, tracing_setup};
|
||||
use ubisync_lib::{
|
||||
tracing_setup,
|
||||
types::{ElementContent, ElementId, MessageId},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
#[serial_test::serial]
|
||||
|
|
|
@ -4,7 +4,6 @@ use anyhow::Error;
|
|||
use cozo::DbInstance;
|
||||
use tracing::{debug, error};
|
||||
|
||||
|
||||
mod api_state;
|
||||
mod comm_state;
|
||||
mod queries;
|
||||
|
@ -12,7 +11,11 @@ mod schema;
|
|||
|
||||
pub use api_state::ApiState;
|
||||
pub use comm_state::CommState;
|
||||
use ubisync_lib::{types::{ElementId, ElementContent, Element, Tag}, messages::{Message, MessageContent}, peer::Peer};
|
||||
use ubisync_lib::{
|
||||
messages::{Message, MessageContent},
|
||||
peer::Peer,
|
||||
types::{Element, ElementContent, ElementId, Tag},
|
||||
};
|
||||
|
||||
use crate::comm::CommHandle;
|
||||
|
||||
|
|
|
@ -7,9 +7,7 @@ use tracing::{debug, error};
|
|||
|
||||
use crate::{
|
||||
run_query,
|
||||
state::{
|
||||
Element, ElementContent, ElementId,
|
||||
},
|
||||
state::{Element, ElementContent, ElementId},
|
||||
};
|
||||
|
||||
use ubisync_lib::types::{MessageId, Tag};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use anyhow::Error;
|
||||
use cozo::{DataValue, DbInstance, ScriptMutability};
|
||||
use ubisync_lib::{types::PeerId, peer::Peer};
|
||||
use ubisync_lib::{peer::Peer, types::PeerId};
|
||||
|
||||
use crate::run_query;
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@ use tracing::{debug, warn, Level};
|
|||
use ubisync::{config::Config, Ubisync};
|
||||
use ubisync_lib::{
|
||||
api::element::{ElementCreateRequest, ElementGetRequest},
|
||||
types::{Element, ElementContent}, tracing_setup,
|
||||
tracing_setup,
|
||||
types::{Element, ElementContent},
|
||||
};
|
||||
use ubisync_sdk::UbisyncClient;
|
||||
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn two_nodes_element_creation() {
|
||||
tracing_setup!(Level::DEBUG);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue