feat: move project to crates

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-10-21 11:14:58 +02:00
parent 381b472eca
commit 6e16fc6b2b
63 changed files with 9 additions and 15 deletions

View File

@@ -0,0 +1,23 @@
[package]
name = "como_bin"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
como_gql.workspace = true
como_core.workspace = true
como_domain.workspace = true
como_infrastructure.workspace = true
como_api.workspace = true
axum.workspace = true
serde_json.workspace = true
tokio.workspace = true
anyhow.workspace = true
dotenv.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
clap.workspace = true

View File

@@ -0,0 +1,22 @@
use axum::{http::StatusCode, response::IntoResponse, Json};
use serde_json::json;
#[allow(dead_code)]
#[derive(Debug)]
pub enum AppError {
WrongCredentials,
InternalServerError,
}
impl IntoResponse for AppError {
fn into_response(self) -> axum::response::Response {
let (status, err_msg) = match self {
Self::WrongCredentials => (StatusCode::BAD_REQUEST, "invalid credentials"),
Self::InternalServerError => (
StatusCode::INTERNAL_SERVER_ERROR,
"something went wrong with your request",
),
};
(status, Json(json!({ "error": err_msg }))).into_response()
}
}

View File

@@ -0,0 +1,41 @@
use std::sync::Arc;
mod error;
use clap::Parser;
use anyhow::Context;
use como_api::router::Api;
use como_infrastructure::{
configs::AppConfig, database::ConnectionPoolManager, register::ServiceRegister,
};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing::info!("Loading dotenv");
dotenv::dotenv()?;
let config = Arc::new(AppConfig::parse());
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::new(&config.rust_log))
.with(tracing_subscriber::fmt::layer())
.init();
let pool = ConnectionPoolManager::new_pool(&config.database_url, true).await?;
let service_register = ServiceRegister::new(pool, config.clone()).await?;
Api::new(
config.api_port,
&config.cors_origin,
service_register.clone(),
)
.await
.context("could not initialize API")?;
Ok(())
}