Added database connection
Code now connects to database and prints out errors. Also the ticket table now includes a timestamp field
This commit is contained in:
@@ -1,10 +1,24 @@
|
||||
mod models;
|
||||
use axum::{Router, routing};
|
||||
use dotenv::dotenv;
|
||||
use models::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{PgPool, postgres::PgPoolOptions};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
dotenv().ok();
|
||||
let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL variable not set");
|
||||
let pool = match PgPoolOptions::new().connect(&database_url).await {
|
||||
Ok(pool) => {
|
||||
println!("Database connection successful");
|
||||
pool
|
||||
}
|
||||
Err(err) => {
|
||||
println!("Failed to connect to database: {:?}", err);
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
let app = Router::new().route("/", routing::get(root_handler));
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:8001").await.unwrap();
|
||||
|
||||
30
backend/src/models.rs
Normal file
30
backend/src/models.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize)]
|
||||
pub enum category {
|
||||
WhiteboardBeamer,
|
||||
Internet,
|
||||
IPadKoffer,
|
||||
AppleTV,
|
||||
DocuCam,
|
||||
Sonstiges,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone, PartialEq, Debug)]
|
||||
pub struct ticket {
|
||||
pub id: i32,
|
||||
pub category: category,
|
||||
pub betreff: String,
|
||||
pub description: String,
|
||||
pub room: i16,
|
||||
pub date: chrono::NaiveDateTime,
|
||||
pub user_id: i16,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone, PartialEq, Debug)]
|
||||
pub struct user {
|
||||
pub id: i16,
|
||||
pub first_name: String,
|
||||
pub last_name: String,
|
||||
pub is_admin: bool,
|
||||
}
|
||||
Reference in New Issue
Block a user