chore: re-map project structure to using multi workspace paradigm

This commit is contained in:
Maulana Sodiqin
2025-04-06 13:25:44 +07:00
parent de9c5a6dc1
commit b4bf78f0d6
87 changed files with 325 additions and 192 deletions
+11
View File
@@ -0,0 +1,11 @@
[package]
name = "imphnen-entities"
version = "0.1.0"
edition = "2024"
[dependencies]
axum.workspace = true
serde.workspace = true
surrealdb = { workspace = true, features = ["kv-mem"] }
thiserror.workspace = true
utoipa.workspace = true
+69
View File
@@ -0,0 +1,69 @@
use serde::{Deserialize, Serialize};
use surrealdb::{
engine::{local::Db, remote::ws::Client},
Surreal,
};
use utoipa::{IntoParams, ToSchema};
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct MessageResponseDto {
pub message: String,
pub version: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
pub struct MetaRequestDto {
pub page: Option<u64>,
pub per_page: Option<u64>,
pub search: Option<String>,
pub sort_by: Option<String>,
pub order: Option<String>,
pub filter: Option<String>,
pub filter_by: Option<String>,
}
impl Default for MetaRequestDto {
fn default() -> Self {
MetaRequestDto {
page: Some(1),
per_page: Some(10),
search: None,
sort_by: None,
order: None,
filter: None,
filter_by: None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
pub struct MetaResponseDto {
pub page: Option<u64>,
pub per_page: Option<u64>,
pub total: Option<u64>,
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct ResponseSuccessDto<T: Serialize> {
pub data: T,
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct ResponseListSuccessDto<T: Serialize> {
pub data: T,
pub meta: Option<MetaResponseDto>,
}
pub type SurrealWsClient = Surreal<Client>;
pub type SurrealMemClient = Surreal<Db>;
#[derive(Clone)]
pub struct AppState {
pub surrealdb_ws: SurrealWsClient,
pub surrealdb_mem: SurrealMemClient,
}
#[derive(Debug, serde::Deserialize)]
pub struct CountResult {
pub count: u64,
}
+26
View File
@@ -0,0 +1,26 @@
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
}
}
}
+4
View File
@@ -0,0 +1,4 @@
pub mod common_dto;
pub mod error_dto;
pub use common_dto::*;
pub use error_dto::*;