Set up monorepo Docker development

This commit is contained in:
2026-09-19 20:56:07 +02:00
parent ab4cfe40c8
commit 5b45203c14
13 changed files with 33 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
use std::env;
use tokio::net::TcpListener;
mod models;
mod routes;
#[tokio::main]
#[tracing::instrument]
async fn main() {
dotenv::dotenv().ok();
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
let host = env::var("HOST").unwrap_or_else(|_| "0.0.0.0".to_string());
let port = env::var("PORT").unwrap_or_else(|_| "3000".to_string());
let listener = TcpListener::bind(format!("{}:{}", host, port))
.await
.expect("Failed to bind to address");
tracing::info!("Starting server at {}:{}", host, port);
axum::serve(listener, routes::create_router().into_make_service())
.await
.expect("Failed to start server");
}
+1
View File
@@ -0,0 +1 @@
pub mod transaction;
+11
View File
@@ -0,0 +1,11 @@
use chrono::{DateTime, Utc};
use serde::Serialize;
use uuid::Uuid;
#[derive(Serialize)]
pub struct Transaction {
pub id: Uuid,
pub description: String,
pub amount: f64,
pub date: DateTime<Utc>,
}
+8
View File
@@ -0,0 +1,8 @@
mod transactions;
pub fn create_router() -> axum::Router {
axum::Router::new().nest(
"/api",
axum::Router::new().nest("/transactions", transactions::create_router()),
)
}
+23
View File
@@ -0,0 +1,23 @@
use crate::models::transaction::Transaction;
pub fn create_router() -> axum::Router {
axum::Router::new().route("/", axum::routing::get(get_transactions))
}
#[tracing::instrument]
pub async fn get_transactions() -> axum::Json<Vec<Transaction>> {
axum::Json(vec![
Transaction {
id: uuid::Uuid::new_v4(),
description: "Groceries".to_string(),
amount: 42.50,
date: chrono::Utc::now(),
},
Transaction {
id: uuid::Uuid::new_v4(),
description: "Coffee".to_string(),
amount: 4.25,
date: chrono::Utc::now(),
},
])
}