194c44c
use axum::Router;
use axum::middleware;
use axum::routing::{delete, get, patch, post, put};
use crate::handlers::accept_agreement::accept_agreement;
use crate::handlers::agreement_page::agreement_page;
use crate::handlers::create_report::create_report;
use crate::handlers::delete_notification::delete_notification;
use crate::handlers::get_preferences::get_preferences;
use crate::handlers::get_user::get_user;
use crate::handlers::list_agreements::list_agreements;
use crate::handlers::list_notifications::list_notifications;
use crate::handlers::me::me;
use crate::handlers::unread_notifications_count::unread_notifications_count;
use crate::handlers::update_preferences::update_preferences;
use crate::handlers::update_profile::update_profile;
use crate::handlers::users;
use crate::oauth;
use crate::services::AuthService;
use crate::share::guard::auth_guard;
pub fn router(service: AuthService) -> Router<AuthService> {
let public = Router::new()
.route("/auth/login", get(oauth::login::login))
.route("/auth/callback", get(oauth::callback::callback))
.route("/auth/refresh", post(oauth::refresh::refresh))
.route("/auth/logout", post(oauth::logout::logout))
.route("/auth/agreements", get(list_agreements));
let authed = Router::new()
.route("/users", get(users::list_users_batch))
.route(
"/users/by-username/{username}",
get(users::get_user_by_username),
)
.route("/users/{user_id}", get(get_user))
.route("/me", get(me).patch(update_profile))
.route("/auth/jwt-request", get(crate::handlers::jwt_request::jwt_request))
.route("/me/username", put(users::update_username))
.route(
"/me/preferences",
get(get_preferences).patch(update_preferences),
)
.route("/me/agreements/{key}", put(accept_agreement))
.route("/me/notifications", get(list_notifications))
.route(
"/me/notifications/unread-count",
get(unread_notifications_count),
)
.route(
"/me/notifications/{notification_id}",
delete(delete_notification),
)
.route(
"/me/notifications/read",
put(crate::handlers::mark_notifications_read::mark_notifications_read),
)
.route("/me/reports", post(create_report))
.route_layer(middleware::from_fn_with_state(service, auth_guard));
public.merge(authed)
}
pub fn pages_router(service: AuthService) -> Router {
Router::new()
.route("/agreements/{key}", get(agreement_page))
.with_state(service)
}