|
|
|
@ -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) |
|
|
|
|
} |
|
|
|
|