Import of old stuff, it might work now

This commit is contained in:
2023-09-04 17:00:48 +01:00
parent 554e645f92
commit b6e7c870a7
11 changed files with 480 additions and 33 deletions
+30 -21
View File
@@ -1,30 +1,39 @@
use axum::{
routing::{get, post},
http::StatusCode,
response::IntoResponse,
Json, Router,
};
use serde::{Deserialize, Serialize};
mod ingestion;
mod error;
use axum::{Extension, Router};
use std::net::SocketAddr;
use axum::routing::post;
use clap::Parser;
use migration::{Migrator, MigratorTrait};
use crate::ingestion::ingestion::{monzo_batched_csv, monzo_batched_json, monzo_updated};
#[derive(Debug, clap::Parser)]
struct Config {
#[clap(short, long, env)]
addr: SocketAddr,
#[clap(short, long = "db", env)]
database_url: String,
}
#[tokio::main]
async fn main() {
// initialize tracing
async fn main() -> anyhow::Result<()> {
let config: Config = Config::parse();
let connection = sea_orm::Database::connect(&config.database_url).await?;
Migrator::up(&connection, None).await?;
tracing_subscriber::fmt::init();
// build our application with a route
let app = Router::new()
// `GET /` goes to `root`
.route("/", get(root))
// `POST /users` goes to `create_user`
.route("/users", post(create_user));
.route("/monzo-updated", post(monzo_updated))
.route("/monzo-batch-export", post(monzo_batched_json))
.route("/monzo-csv-ingestion", post(monzo_batched_csv))
.layer(Extension(connection.clone()));
// run our app with hyper
// `axum::Server` is a re-export of `hyper::Server`
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
tracing::debug!("listening on {}", &config.addr);
axum::Server::bind(&config.addr)
.serve(app.into_make_service())
.await
.unwrap();
}
Ok(())
}