feat: implement surrealdb and redis
This commit is contained in:
+8
-9
@@ -1,15 +1,14 @@
|
||||
use axum::{routing::get, Router};
|
||||
use v1::auth_router;
|
||||
use crate::{AppState, RedisClient, SurrealClient};
|
||||
use axum::{Extension, Router};
|
||||
|
||||
pub mod v1;
|
||||
pub mod v2;
|
||||
|
||||
pub async fn apps() -> Router {
|
||||
let v1_routes = Router::new()
|
||||
.nest("/auth", auth_router())
|
||||
.route("/", get(|| async { "Comming Soon v1" }));
|
||||
pub async fn apps(surrealdb: SurrealClient, redisdb: RedisClient) -> Router {
|
||||
let state = AppState { surrealdb, redisdb };
|
||||
|
||||
let v2_routes = Router::new().route("/", get(|| async { "Comming Soon v2" }));
|
||||
|
||||
Router::new().nest("/v1", v1_routes).nest("/v2", v2_routes)
|
||||
Router::new()
|
||||
.nest("/v1", v1::routes().await)
|
||||
.nest("/v2", v2::routes().await)
|
||||
.layer(Extension(state))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
use super::{mutation_login, AuthLoginRequestDto};
|
||||
use axum::{response::Response, Json};
|
||||
use axum::{response::IntoResponse, Extension, Json};
|
||||
|
||||
pub async fn post_login(Json(payload): Json<AuthLoginRequestDto>) -> Response {
|
||||
mutation_login(payload).await
|
||||
use super::{mutation_login, AuthLoginRequestDto};
|
||||
use crate::AppState;
|
||||
|
||||
pub async fn post_login(
|
||||
Extension(state): Extension<AppState>,
|
||||
Json(payload): Json<AuthLoginRequestDto>,
|
||||
) -> impl IntoResponse {
|
||||
mutation_login(payload, &state).await
|
||||
}
|
||||
|
||||
@@ -1,8 +1,30 @@
|
||||
use super::auth_dto::AuthLoginRequestDto;
|
||||
use crate::{success_response, ResponseSuccessDto};
|
||||
use crate::{success_response, AppState, ResponseSuccessDto};
|
||||
use axum::response::Response;
|
||||
|
||||
pub async fn mutation_login(params: AuthLoginRequestDto) -> Response {
|
||||
const USERS_KEY: &str = "users";
|
||||
|
||||
pub async fn mutation_login(
|
||||
params: AuthLoginRequestDto,
|
||||
state: &AppState,
|
||||
) -> Response {
|
||||
let _users: Option<AuthLoginRequestDto> = state
|
||||
.surrealdb
|
||||
.select((USERS_KEY, &*params.email))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let mut redis_conn = state
|
||||
.redisdb
|
||||
.get_connection()
|
||||
.expect("failed to get connection");
|
||||
|
||||
redis::cmd("SET")
|
||||
.arg("some_key")
|
||||
.arg("some_value")
|
||||
.query::<()>(&mut redis_conn)
|
||||
.expect("failed to set value");
|
||||
|
||||
let response = ResponseSuccessDto {
|
||||
data: AuthLoginRequestDto {
|
||||
email: params.email,
|
||||
|
||||
+5
-1
@@ -1,3 +1,7 @@
|
||||
use axum::Router;
|
||||
|
||||
pub mod auth;
|
||||
|
||||
pub use auth::*;
|
||||
pub async fn routes() -> Router {
|
||||
Router::new().nest("/auth", auth::auth_router())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
use axum::{response::IntoResponse, routing::post, Router};
|
||||
|
||||
async fn dummy_login() -> impl IntoResponse {
|
||||
"Logged in successfully"
|
||||
}
|
||||
|
||||
pub fn auth_router() -> Router {
|
||||
Router::new().route("/login", post(dummy_login))
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
use axum::Router;
|
||||
|
||||
pub mod auth;
|
||||
pub use auth::*;
|
||||
|
||||
pub async fn routes() -> Router {
|
||||
let public_routes = Router::new().nest("/auth", auth::auth_router());
|
||||
Router::new().merge(public_routes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user