Create me route
This commit is contained in:
@@ -2,13 +2,19 @@ mod controllers;
|
|||||||
mod routes;
|
mod routes;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use utils::init_database;
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use axum::{routing::{delete, get, post, put}, Router};
|
use axum::{
|
||||||
use routes::{admin, auth as auth_routes, machines, setup};
|
routing::{delete, get, post, put},
|
||||||
use tower_http::{cors::CorsLayer, services::{ServeDir, ServeFile}};
|
Router,
|
||||||
|
};
|
||||||
|
use routes::{accounts, admin, auth as auth_routes, machines, setup};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use tokio::signal;
|
use tokio::signal;
|
||||||
|
use tower_http::{
|
||||||
|
cors::CorsLayer,
|
||||||
|
services::{ServeDir, ServeFile},
|
||||||
|
};
|
||||||
|
use utils::init_database;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
@@ -16,21 +22,17 @@ async fn main() -> Result<()> {
|
|||||||
let api_routes = Router::new()
|
let api_routes = Router::new()
|
||||||
.route("/setup/status", get(setup::get_setup_status))
|
.route("/setup/status", get(setup::get_setup_status))
|
||||||
.route("/setup/init", post(setup::init_setup))
|
.route("/setup/init", post(setup::init_setup))
|
||||||
|
|
||||||
.route("/auth/login", post(auth_routes::login))
|
.route("/auth/login", post(auth_routes::login))
|
||||||
.route("/auth/logout", post(auth_routes::logout))
|
.route("/auth/logout", post(auth_routes::logout))
|
||||||
|
.route("/accounts/me", get(accounts::me))
|
||||||
.route("/admin/users", get(admin::get_users))
|
.route("/admin/users", get(admin::get_users))
|
||||||
.route("/admin/users", post(admin::create_user_handler))
|
.route("/admin/users", post(admin::create_user_handler))
|
||||||
.route("/admin/users/{id}", put(admin::update_user_handler))
|
.route("/admin/users/{id}", put(admin::update_user_handler))
|
||||||
.route("/admin/users/{id}", delete(admin::delete_user_handler))
|
.route("/admin/users/{id}", delete(admin::delete_user_handler))
|
||||||
|
|
||||||
.route("/machines/register", post(machines::register_machine))
|
.route("/machines/register", post(machines::register_machine))
|
||||||
.route("/machines", get(machines::get_machines))
|
.route("/machines", get(machines::get_machines))
|
||||||
.route("/machines/{id}", delete(machines::delete_machine))
|
.route("/machines/{id}", delete(machines::delete_machine))
|
||||||
|
|
||||||
.layer(CorsLayer::permissive())
|
.layer(CorsLayer::permissive())
|
||||||
|
|
||||||
.with_state(pool);
|
.with_state(pool);
|
||||||
|
|
||||||
let dist_path = "./dist";
|
let dist_path = "./dist";
|
||||||
@@ -48,7 +50,9 @@ async fn main() -> Result<()> {
|
|||||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:8379").await?;
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:8379").await?;
|
||||||
println!("Server running on http://0.0.0.0:8379");
|
println!("Server running on http://0.0.0.0:8379");
|
||||||
|
|
||||||
axum::serve(listener, app).with_graceful_shutdown(shutdown_signal()).await?;
|
axum::serve(listener, app)
|
||||||
|
.with_graceful_shutdown(shutdown_signal())
|
||||||
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
server/src/routes/accounts.rs
Normal file
6
server/src/routes/accounts.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
use crate::utils::{auth::AuthUser, error::*, models::User};
|
||||||
|
use axum::response::Json;
|
||||||
|
|
||||||
|
pub async fn me(auth_user: AuthUser) -> Result<Json<User>, AppError> {
|
||||||
|
Ok(success_response(auth_user.user))
|
||||||
|
}
|
@@ -2,3 +2,4 @@ pub mod admin;
|
|||||||
pub mod auth;
|
pub mod auth;
|
||||||
pub mod machines;
|
pub mod machines;
|
||||||
pub mod setup;
|
pub mod setup;
|
||||||
|
pub mod accounts;
|
||||||
|
Reference in New Issue
Block a user