This commit is contained in:
Michael Zhang 2024-06-27 11:06:47 -05:00
commit ea6a98b25b
10 changed files with 3790 additions and 0 deletions

2
.env Normal file
View file

@ -0,0 +1,2 @@
SOURCE=./crates/backend/migrations
DATABASE_URL=sqlite://./test.db

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
test.db*

3693
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

2
Cargo.toml Normal file
View file

@ -0,0 +1,2 @@
workspace.resolver = "2"
workspace.members = ["crates/*"]

13
crates/backend/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "backend"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0.86"
axum = { version = "0.7.5", features = ["http2", "macros", "ws"] }
dashmap = "6.0.1"
dioxus = { version = "0.5.1", features = ["axum", "ssr", "web"] }
serde = { version = "1.0.203", features = ["derive"] }
sqlx = { version = "0.7.4", features = ["tls-rustls", "runtime-tokio", "json", "sqlite", "chrono"] }
tokio = { version = "1.38.0", features = ["full"] }

View file

@ -0,0 +1,15 @@
CREATE TABLE users (
user_id TEXT PRIMARY KEY,
name TEXT UNIQUE
);
CREATE TABLE user_keys (
user_key TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
CREATE TABLE repo (
repo_id TEXT PRIMARY KEY,
repo_name TEXT NOT NULL
);

View file

@ -0,0 +1,53 @@
#[macro_use]
extern crate serde;
use std::sync::Arc;
use anyhow::Result;
use axum::{
extract::State,
response::Html,
routing::{get, post},
Router,
};
use dashmap::DashMap;
use dioxus::prelude::*;
use sqlx::{migrate, SqlitePool};
#[derive(Clone)]
struct AppState {
db: SqlitePool,
register_inits: Arc<DashMap<String, String>>,
}
#[tokio::main]
async fn main() -> Result<()> {
let db = SqlitePool::connect("sqlite://../../test.db").await?;
migrate!().run(&db).await?;
let state = AppState {
db,
register_inits: Default::default(),
};
let app = Router::new()
.route("/", get(app_endpoint))
.route("/register/init", post(register_init_endpoint))
.with_state(state);
// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
axum::serve(listener, app).await?;
Ok(())
}
async fn app_endpoint() -> Html<String> {
// render the rsx! macro to HTML
Html(dioxus::ssr::render_element(rsx! { div { "hello world!" } }))
}
#[derive(Deserialize)]
struct RegisterInit {}
async fn register_init_endpoint(State(state): State<AppState>) {}

6
crates/cli/Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[package]
name = "cli"
version = "0.1.0"
edition = "2021"
[dependencies]

3
crates/cli/src/main.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

1
rustfmt.toml Normal file
View file

@ -0,0 +1 @@
tab_spaces = 2