Moved server, added backend structs and added ui elements.

This commit is contained in:
2026-01-15 02:53:47 +01:00
parent 25a47bbce9
commit 0d5fef7fbb
19 changed files with 3355 additions and 123 deletions
+2939
View File
File diff suppressed because it is too large Load Diff
+32
View File
@@ -0,0 +1,32 @@
[package]
name = "server"
version = "0.1.0"
edition = "2024"
authors = ["Matthias Lodner <matthias@lodner.de>"]
[[bin]]
name = "server"
path = "src/main.rs"
[dependencies]
common = {path = "../common"}
axum = "0.8.8"
tokio = { version = "1.49.0", default-features = false, features = ["full"] }
http = "1.4.0"
tracing = "=0.1.44"
tracing-subscriber = "0.3.22"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
# Logging
env_logger = "0.11.8"
# Database
sqlx = { version = "0.8.6", features = [ "runtime-async-std-native-tls", "postgres", "chrono" ] }
# Etc.
dotenv = "0.15.0"
chrono = { version = "0.4.42" }
+55
View File
@@ -0,0 +1,55 @@
use std::env;
use axum::{
routing::{get, post},
http::StatusCode,
Json, Router,
};
use dotenv::dotenv;
use common::models::article::Article;
#[tokio::main]
async fn main() {
dotenv().ok();
let server_address = env::var("SERVER_ADDRESS").expect("SERVER_ADDRESS is not set in .env file");
let server_port = env::var("SERVER_PORT").expect("SERVER_PORT is not set in .env file");
let database = env::var("DATABASE_URL").expect("DATABASE is not set in .env file");
let addr = format!("{}:{}", server_address, server_port);
// initialize tracing
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("/article", post(create_article));
// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
}
// basic handler that responds with a static string
async fn root() -> &'static str {
"Hello, World!"
}
#[tracing::instrument(ret)]
async fn create_article(
Json(payload): Json<Article>,
) -> (StatusCode, Json<Article>) {
let article = Article {
id: payload.id,
name: payload.name,
bio: payload.bio,
origin: payload.origin,
description: payload.description,
ingredients: payload.ingredients,
variants: payload.variants,
};
(StatusCode::CREATED, Json(article))
}