Initial Implementation of ResourceGuard Macro

This commit is contained in:
2024-02-24 19:03:48 -03:00
parent ef43c102aa
commit 077f69778f
15 changed files with 102 additions and 40 deletions

View File

@@ -1,10 +1,8 @@
use axum::{
http::StatusCode,
response::IntoResponse,
Json,
};
use crate::model::generic_response::{GenericResponse};
use crate::model::generic_response::GenericResponse;
use axum::{http::StatusCode, response::IntoResponse, Json};
use proc_utils::guard_resource;
#[guard_resource(ResourceType::OPEN)]
pub async fn health_check() -> impl IntoResponse {
const MESSAGE: &str = "Server is running";
let response = GenericResponse {
@@ -13,4 +11,4 @@ pub async fn health_check() -> impl IntoResponse {
};
(StatusCode::OK, Json(response))
}
}

View File

@@ -1,10 +1,8 @@
use axum::{
http::StatusCode,
response::IntoResponse,
Json,
};
use crate::model::send_message::{SendMessage};
use crate::model::send_message::SendMessage;
use axum::{http::StatusCode, response::IntoResponse, Json};
use proc_utils::guard_resource;
#[guard_resource(ResourceType::OPEN)]
pub async fn send_message(Json(payload): Json<SendMessage>) -> impl IntoResponse {
(StatusCode::OK, Json(payload))
}
}

View File

@@ -1,2 +1,2 @@
pub mod health;
pub mod message;
pub mod message;

1
src/interceptor/mod.rs Normal file
View File

@@ -0,0 +1 @@

View File

@@ -1,11 +1,7 @@
mod route;
mod model;
mod handler;
use axum::http::{
header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE},
HeaderValue, Method
};
mod interceptor;
mod model;
mod route;
#[tokio::main]
async fn main() {
@@ -14,4 +10,4 @@ async fn main() {
println!("🚀 Server started successfully");
let listener = tokio::net::TcpListener::bind("0.0.0.0:8500").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
}

View File

@@ -1,8 +1,7 @@
use serde::Serialize;
#[derive(Serialize)]
pub struct GenericResponse {
pub status: String,
pub message: String,
}
}

View File

@@ -1,2 +1,2 @@
pub mod generic_response;
pub mod send_message;
pub mod send_message;

View File

@@ -1,18 +1,15 @@
use chrono::naive::serde::ts_seconds::deserialize as from_ts;
use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use chrono::naive::serde::ts_seconds::deserialize as from_ts;
#[derive(Deserialize, Serialize)]
pub struct MessageAuthor {
name: String,
username: String,
email: String
email: String,
}
#[serde_as]
#[derive(Deserialize, Serialize)]
pub struct SendMessage {
@@ -23,5 +20,5 @@ pub struct SendMessage {
message: String,
#[serde(deserialize_with = "from_ts")]
timestamp: NaiveDateTime
}
timestamp: NaiveDateTime,
}

View File

@@ -1,13 +1,12 @@
use crate::handler::health::health_check;
use crate::handler::message::send_message;
use axum::{
routing::{get, post},
Router
Router,
};
use crate::handler::health::{health_check};
use crate::handler::message::{send_message};
pub fn create_route() -> Router {
Router::new()
.route("/health", get(health_check))
.route("/message", post(send_message))
}
}