50 lines
1.0 KiB
Rust
50 lines
1.0 KiB
Rust
mod users;
|
|
mod cases;
|
|
mod items;
|
|
mod types;
|
|
mod utils;
|
|
|
|
use users::*;
|
|
use cases::*;
|
|
use items::*;
|
|
use utils::*;
|
|
|
|
use actix_web::web::Data;
|
|
use actix_web::{App, HttpServer};
|
|
use sqlx::sqlite::SqlitePool;
|
|
|
|
#[derive(Clone)]
|
|
struct AppState {
|
|
database: SqlitePool,
|
|
token_expiration: u64,
|
|
}
|
|
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
let pool = SqlitePool::connect("sqlite:database.db")
|
|
.await
|
|
.expect("Could not connect to db");
|
|
let app_state = Data::new(AppState {
|
|
database: pool,
|
|
token_expiration: 86400,
|
|
});
|
|
HttpServer::new(move || {
|
|
App::new()
|
|
.service(login)
|
|
.service(register)
|
|
.service(logout)
|
|
.service(get_case)
|
|
.service(get_cases)
|
|
.service(get_item)
|
|
.service(get_items)
|
|
.service(get_case_items)
|
|
.service(get_item_cases)
|
|
.service(options)
|
|
.app_data(app_state.clone())
|
|
})
|
|
.bind(("127.0.0.1", 8000))?
|
|
.run()
|
|
.await
|
|
}
|