You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
3.1 KiB
83 lines
3.1 KiB
use crate::app::{catalog, history, home, item, overview, reports, upload};
|
|
use crate::session::SessionUser;
|
|
use axum::extract::FromRef;
|
|
use axum::middleware::from_extractor;
|
|
use axum::routing::{get, post, delete};
|
|
use axum::Router;
|
|
use axum_htmx::AutoVaryLayer;
|
|
use oauth2::basic::BasicClient;
|
|
use sqlx::SqlitePool;
|
|
|
|
pub fn routes() -> Router<AppState> {
|
|
Router::new()
|
|
.route("/", get(home::home))
|
|
.route("/index.html", get(home::home))
|
|
.route("/home", get(home::home))
|
|
.route("/home/search", get(home::home))
|
|
.route("/catalog", get(catalog::catalog))
|
|
.route("/catalog/", get(catalog::catalog))
|
|
.route("/item/:item_id",
|
|
get(item::item::item).
|
|
delete(item::delete::delete_item)
|
|
)
|
|
.route("/item/:item_id/",
|
|
get(item::item::item).
|
|
delete(item::delete::delete_item)
|
|
)
|
|
.route("/item/:item_id/count", get(item::count::item_count))
|
|
.route("/item/:item_id/stats", get(item::stats::item_stats))
|
|
.route("/item/:item_id/edit",
|
|
get(item::edit::edit_item_form_get).
|
|
post(item::edit::edit_item_form_post)
|
|
)
|
|
.route("/item/create",
|
|
get(item::create::create_item_form_get).
|
|
post(item::create::create_item_form_post)
|
|
)
|
|
.route("/item/:item_id/adjustments",
|
|
get(item::adjustment::table::get_adjustments_table),
|
|
)
|
|
.route("/item/:item_id/adjustment/negative",
|
|
get(item::adjustment::negative::negative_adjustment_form_get).
|
|
post(item::adjustment::negative::negative_adjustment_form_post),
|
|
)
|
|
.route("/item/:item_id/adjustment/positive",
|
|
get(item::adjustment::positive::positive_adjustment_form_get).
|
|
post(item::adjustment::positive::positive_adjustment_form_post),
|
|
)
|
|
.route("/upload", get(upload::index::upload_index_handler))
|
|
.route("/upload/catalog", post(upload::catalog::catalog_import))
|
|
.route("/upload/vetcove/history", post(upload::vetcove::item_history_import))
|
|
.route("/overview", get(overview::overview_handler))
|
|
.route("/reports", get(reports::reports_handler))
|
|
.route("/history", get(history::history_log_handler))
|
|
// Ensure that all routes here require an authenticated user
|
|
// whether explicitly asked or not
|
|
.route_layer(from_extractor::<SessionUser>())
|
|
.layer(AutoVaryLayer)
|
|
}
|
|
|
|
// App state. Pretty basic stuff. Gets passed around by the server to the handlers and whatnot
|
|
// Use in a handler with the state enum:
|
|
// async fn handler(State(my_app_state): State<AppState>)
|
|
#[derive(Clone)]
|
|
pub struct AppState {
|
|
pub db: SqlitePool,
|
|
pub oauth_client: BasicClient,
|
|
}
|
|
|
|
// Axum extractors for app state. These allow the handler to just use
|
|
// pieces of the App state
|
|
// async fn handler(State(my_db): State<SqlitePool>)
|
|
impl FromRef<AppState> for SqlitePool {
|
|
fn from_ref(input: &AppState) -> Self {
|
|
input.db.clone()
|
|
}
|
|
}
|
|
|
|
impl FromRef<AppState> for BasicClient {
|
|
fn from_ref(input: &AppState) -> Self {
|
|
input.oauth_client.clone()
|
|
}
|
|
}
|