|
|
@ -9,6 +9,7 @@ use axum::Json; |
|
|
|
use axum::Router; |
|
|
|
use axum::Router; |
|
|
|
use clap::Parser; |
|
|
|
use clap::Parser; |
|
|
|
use domain::entry::IncomingEntry; |
|
|
|
use domain::entry::IncomingEntry; |
|
|
|
|
|
|
|
use domain::entry::OutgoingEntry; |
|
|
|
use sqlx::sqlite::SqliteConnectOptions; |
|
|
|
use sqlx::sqlite::SqliteConnectOptions; |
|
|
|
use sqlx::sqlite::SqlitePoolOptions; |
|
|
|
use sqlx::sqlite::SqlitePoolOptions; |
|
|
|
use sqlx::SqlitePool; |
|
|
|
use sqlx::SqlitePool; |
|
|
@ -60,8 +61,12 @@ async fn serve(state: Arc<SqlitePool>, addr: &str) { |
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
async fn add_entry( |
|
|
|
async fn add_entry( |
|
|
|
State(state): State<Arc<SqlitePool>>, |
|
|
|
State(pool): State<Arc<SqlitePool>>, |
|
|
|
Json(payload): Json<IncomingEntry>, |
|
|
|
Json(payload): Json<IncomingEntry>, |
|
|
|
) -> Json<IncomingEntry> { |
|
|
|
) -> Result<Json<OutgoingEntry>, sqlx::Error> { |
|
|
|
Json(payload) |
|
|
|
let mut transaction = pool.begin().await?; |
|
|
|
|
|
|
|
payload.save(&mut transaction).await?; |
|
|
|
|
|
|
|
transaction.commit().await?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(Json(OutgoingEntry { id: "id".into() })) |
|
|
|
} |
|
|
|
} |
|
|
|