Added router for routing requests
1. Duh 2. Also minor bugfix
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#![allow(unused_imports)]
|
||||
mod handlers;
|
||||
mod models;
|
||||
mod router;
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::{Router, routing};
|
||||
use dotenv::dotenv;
|
||||
use models::*;
|
||||
@@ -26,12 +29,7 @@ async fn main() {
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
let app = Router::new().route("/", routing::get(root_handler));
|
||||
|
||||
let app = create_router(Arc::new(AppState { db: pool.clone() }));
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:8001").await.unwrap();
|
||||
axum::serve(listener, app).await;
|
||||
}
|
||||
|
||||
async fn root_handler() -> &'static str {
|
||||
"Hello, World"
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::fmt::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{Decode, prelude::Type};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Decode, Type)]
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Type)]
|
||||
pub enum Category {
|
||||
WhiteboardBeamer,
|
||||
Internet,
|
||||
@@ -26,7 +26,7 @@ impl Display for Category {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Decode, Type)]
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Type)]
|
||||
pub enum Status {
|
||||
ToDo,
|
||||
InProgress,
|
||||
|
||||
22
backend/src/router.rs
Normal file
22
backend/src/router.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::{
|
||||
Router,
|
||||
routing::{get, post},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
AppState,
|
||||
handlers::ticket::{create_ticket, delete_ticket, get_ticket_by_id, get_tickets},
|
||||
};
|
||||
|
||||
pub fn create_router(state: Arc<AppState>) -> Router {
|
||||
Router::new()
|
||||
.route("/api/tickets", get(get_tickets))
|
||||
.route("/api/tickets/create", post(create_ticket))
|
||||
.route(
|
||||
"/api/tickets/{id}",
|
||||
get(get_ticket_by_id).delete(delete_ticket),
|
||||
)
|
||||
.with_state(state)
|
||||
}
|
||||
Reference in New Issue
Block a user