Skip to content

Commit

Permalink
refactor: move db as private repo of server
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys committed Dec 1, 2023
1 parent a5ce1a7 commit 619ece7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
4 changes: 1 addition & 3 deletions ee/tabby-webserver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use tokio::sync::Mutex;
use tracing::{error, warn};
use websocket::WebSocketTransport;

mod db;
mod repositories;
mod server;
mod ui;
Expand Down Expand Up @@ -41,8 +40,7 @@ pub async fn attach_webserver(
logger: Arc<dyn RawEventLogger>,
code: Arc<dyn CodeSearch>,
) -> (Router, Router) {
let conn = db::DbConn::new().await.unwrap();
let ctx = create_service_locator(conn, logger, code);
let ctx = create_service_locator(logger, code).await;
let schema = Arc::new(create_schema());

let api = api
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/schema/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ mod tests {
&UserInfo::new("test".to_string(), false)
);
}
}
}
14 changes: 6 additions & 8 deletions ee/tabby-webserver/src/server/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ use async_trait::async_trait;
use juniper::{FieldResult, IntoFieldError};
use validator::Validate;

use crate::{
db::DbConn,
schema::{
auth::{
generate_jwt, validate_jwt, AuthenticationService, Claims, RefreshTokenResponse,
RegisterResponse, TokenAuthResponse, UserInfo, VerifyTokenResponse,
},
ValidationErrors,
use super::db::DbConn;
use crate::schema::{
auth::{
generate_jwt, validate_jwt, AuthenticationService, Claims, RefreshTokenResponse,
RegisterResponse, TokenAuthResponse, UserInfo, VerifyTokenResponse,
},
ValidationErrors,
};

/// Input parameters for register mutation
Expand Down
File renamed without changes.
26 changes: 10 additions & 16 deletions ee/tabby-webserver/src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod auth;
mod db;
mod proxy;
mod worker;

Expand All @@ -11,13 +12,11 @@ use hyper::{client::HttpConnector, Body, Client, StatusCode};
use tabby_common::api::{code::CodeSearch, event::RawEventLogger};
use tracing::{info, warn};

use crate::{
db::DbConn,
schema::{
auth::AuthenticationService,
worker::{RegisterWorkerError, Worker, WorkerKind, WorkerService},
ServiceLocator,
},
use self::db::DbConn;
use crate::schema::{
auth::AuthenticationService,
worker::{RegisterWorkerError, Worker, WorkerKind, WorkerService},
ServiceLocator,
};

struct ServerContext {
Expand All @@ -31,16 +30,12 @@ struct ServerContext {
}

impl ServerContext {
pub fn new(
db_conn: DbConn,
logger: Arc<dyn RawEventLogger>,
code: Arc<dyn CodeSearch>,
) -> Self {
pub async fn new(logger: Arc<dyn RawEventLogger>, code: Arc<dyn CodeSearch>) -> Self {
Self {
client: Client::default(),
completion: worker::WorkerGroup::default(),
chat: worker::WorkerGroup::default(),
db_conn,
db_conn: DbConn::new().await.unwrap(),
logger,
code,
}
Expand Down Expand Up @@ -151,10 +146,9 @@ impl ServiceLocator for ServerContext {
}
}

pub fn create_service_locator(
db_conn: DbConn,
pub async fn create_service_locator(
logger: Arc<dyn RawEventLogger>,
code: Arc<dyn CodeSearch>,
) -> Arc<dyn ServiceLocator> {
Arc::new(ServerContext::new(db_conn, logger, code))
Arc::new(ServerContext::new(logger, code).await)
}

0 comments on commit 619ece7

Please sign in to comment.