magnetar/src/api_v1/mod.rs

31 lines
987 B
Rust

mod note;
mod user;
use crate::api_v1::note::handle_note;
use crate::api_v1::user::{
handle_user_by_id_many, handle_user_info, handle_user_info_by_acct, handle_user_info_self,
};
use crate::service::MagnetarService;
use crate::web::auth;
use crate::web::auth::AuthState;
use axum::middleware::from_fn_with_state;
use axum::routing::get;
use axum::Router;
use serde::de::{DeserializeOwned, Error};
use serde::{Deserialize, Deserializer};
use std::sync::Arc;
pub fn create_api_router(service: Arc<MagnetarService>) -> Router {
Router::new()
.route("/users/@self", get(handle_user_info_self))
.route("/users/by-acct/:id", get(handle_user_info_by_acct))
.route("/users/lookup-many", get(handle_user_by_id_many))
.route("/users/:id", get(handle_user_info))
.route("/notes/:id", get(handle_note))
.layer(from_fn_with_state(
AuthState::new(service.clone()),
auth::auth,
))
.with_state(service)
}