feat: implement surrealdb and redis

This commit is contained in:
Maulana Sodiqin
2025-02-25 02:00:19 +07:00
parent 9abab01b9c
commit 44de53a49d
18 changed files with 2501 additions and 137 deletions
+10
View File
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use surrealdb::{engine::remote::ws::Client, Surreal};
use utoipa::{IntoParams, ToSchema};
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
@@ -35,3 +36,12 @@ pub struct ResponseListSuccessDto<T: Serialize> {
pub data: T,
pub meta: Option<MetaResponseDto>,
}
pub type SurrealClient = Surreal<Client>;
pub type RedisClient = redis::Client;
#[derive(Clone)]
pub struct AppState {
pub surrealdb: SurrealClient,
pub redisdb: RedisClient,
}
+27
View File
@@ -0,0 +1,27 @@
pub mod error {
use axum::http::StatusCode;
use axum::response::IntoResponse;
use axum::response::Response;
use axum::Json;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("database error")]
Db,
}
impl IntoResponse for Error {
fn into_response(self) -> Response {
(StatusCode::INTERNAL_SERVER_ERROR, Json(self.to_string()))
.into_response()
}
}
impl From<surrealdb::Error> for Error {
fn from(error: surrealdb::Error) -> Self {
eprintln!("{error}");
Self::Db
}
}
}
+2
View File
@@ -1,3 +1,5 @@
pub mod common_dto;
pub mod error_dto;
pub use common_dto::*;
pub use error_dto::*;