Set up rocket/API/webserver

This commit is contained in:
D. Scott Boggs 2023-06-07 08:49:04 -04:00
parent 625da9b7af
commit d0635bc4c5
4 changed files with 717 additions and 22 deletions

23
src/api/mod.rs Normal file
View file

@ -0,0 +1,23 @@
use std::default::default;
use std::net::{IpAddr, Ipv4Addr};
use rocket::Config;
use crate::{
entities::{prelude::*, *},
rocket::{Build, Rocket},
};
#[get("/status")]
fn status() -> &'static str {
"Ok"
}
pub(crate) fn start_server() -> Rocket<Build> {
rocket::build()
.configure(Config {
address: IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
..default()
})
.mount("/", routes![status])
}

View file

@ -1,20 +1,36 @@
#![feature(default_free_fn)]
#![feature(default_free_fn, proc_macro_hygiene, decl_macro)]
#[macro_use]
extern crate rocket;
mod api;
mod db;
mod entities;
mod error;
mod migrator;
use error::Result;
use crate::migrator::Migrator;
use sea_orm::Database;
use sea_orm_migration::prelude::*;
#[tokio::main]
async fn main() -> Result<()> {
let db = Database::connect(db::connection_url()).await?;
#[launch]
async fn rocket_defines_the_main_fn() -> _ {
let url = db::connection_url();
let db = Database::connect(url).await.expect("db connection");
let schema_manager = SchemaManager::new(&db);
migrator::Migrator::refresh(&db).await?;
assert!(schema_manager.has_table("tracks").await?);
assert!(schema_manager.has_table("ticks").await?);
assert!(schema_manager.has_table("groups").await?);
assert!(schema_manager.has_table("track2groups").await?);
Ok(println!("Hello, world! {db:?}"))
Migrator::refresh(&db).await.expect("migration");
assert!(schema_manager
.has_table("tracks")
.await
.expect("fetch tracks table"));
assert!(schema_manager
.has_table("ticks")
.await
.expect("fetch ticks table"));
assert!(schema_manager
.has_table("groups")
.await
.expect("fetch groups table"));
assert!(schema_manager
.has_table("track2_groups")
.await
.expect("fetch track2groups table"));
api::start_server()
}