Browse Source

Mostly the incoming request

main
Julio Biason 2 years ago
parent
commit
22f8028e46
  1. 3
      store/Cargo.toml
  2. 11
      store/src/domain/attachment.rs
  3. 14
      store/src/domain/entry.rs
  4. 10
      store/src/domain/meta.rs
  5. 3
      store/src/domain/mod.rs
  6. 3
      store/src/domain/options.rs
  7. 13
      store/src/main.rs

3
store/Cargo.toml

@ -14,4 +14,5 @@ sqlx = { version = "0.6.2", features = ["sqlite", "uuid", "chrono", "migrate", "
tokio = { version = "1.22.0", features = ["macros", "rt"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.16", default-features = false, features = ["env-filter", "fmt", "ansi"] }
axum = { version = "0.5.15" }
axum = { version = "0.6", features = ["json"] }
serde = { version = "1.0.152", features = ["derive"] }

11
store/src/domain/attachment.rs

@ -0,0 +1,11 @@
//! Versions of the attachments.
use serde::Deserialize;
use serde::Serialize;
#[derive(Deserialize, Serialize)]
pub struct IncomingAttachment {
name: String,
content_type: String,
content_base64: String,
}

14
store/src/domain/entry.rs

@ -0,0 +1,14 @@
//! Versions of the entry.
use serde::Deserialize;
use serde::Serialize;
#[derive(Deserialize, Serialize)]
pub struct IncomingEntry {
title: String,
content: String,
source: String,
meta: Vec<super::meta::IncomingMeta>,
attachments: Vec<super::attachment::IncomingAttachment>,
}

10
store/src/domain/meta.rs

@ -0,0 +1,10 @@
//! Version of the entry meta information.
use serde::Deserialize;
use serde::Serialize;
#[derive(Deserialize, Serialize)]
pub struct IncomingMeta {
name: String,
value: String,
}

3
store/src/domain/mod.rs

@ -1,3 +1,6 @@
//! Store own domain.
pub mod attachment;
pub mod entry;
pub mod meta;
pub mod options;

3
store/src/domain/options.rs

@ -12,4 +12,7 @@ pub struct Options {
/// Working directory
#[arg(short, long, env = "STORE_PATH", default_value = "./")]
pub working_directory: PathBuf,
#[arg(short, long, env = "STORE_ADDR", default_value = "127.0.0.1:4000")]
pub addr: String,
}

13
store/src/main.rs

@ -3,9 +3,12 @@ mod domain;
use std::path::Path;
use std::sync::Arc;
use axum::extract::State;
use axum::routing::post;
use axum::Json;
use axum::Router;
use clap::Parser;
use domain::entry::IncomingEntry;
use sqlx::sqlite::SqliteConnectOptions;
use sqlx::sqlite::SqlitePoolOptions;
use sqlx::SqlitePool;
@ -26,6 +29,7 @@ async fn main() -> Result<(), sqlx::Error> {
let options = Options::parse();
let pool = init_db(&options.working_directory).await?;
let state = Arc::new(pool);
serve(state.clone(), &options.addr).await;
Ok(())
}
@ -46,7 +50,7 @@ async fn init_db(wd: &Path) -> Result<SqlitePool, sqlx::Error> {
/// Start the server.
async fn serve(state: Arc<SqlitePool>, addr: &str) {
let app = Router::new().route("/", post(add_entry));
let app = Router::new().route("/", post(add_entry)).with_state(state);
tracing::info!(addr, "Store server up");
axum::Server::bind(&addr.parse().unwrap())
.serve(app.into_make_service())
@ -55,4 +59,9 @@ async fn serve(state: Arc<SqlitePool>, addr: &str) {
}
///
async fn add_entry(state: Arc<SqlitePool>) -> Json {}
async fn add_entry(
State(state): State<Arc<SqlitePool>>,
Json(payload): Json<IncomingEntry>,
) -> Json<IncomingEntry> {
Json(payload)
}

Loading…
Cancel
Save