Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
zupzup committed Nov 26, 2024
1 parent 536249e commit 763a58d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
28 changes: 16 additions & 12 deletions src/persistence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub enum Error {
pub use contact::ContactStoreApi;

use crate::config::Config;
use company::FileBasedCompanyStore;
use file_upload::FileUploadStore;

/// Given a base path and a directory path, ensures that the directory
/// exists and returns the full path.
Expand All @@ -57,29 +59,29 @@ pub struct DbContext {
pub contact_store: Arc<dyn ContactStoreApi>,
pub bill_store: Arc<dyn bill::BillStoreApi>,
pub identity_store: Arc<dyn identity::IdentityStoreApi>,
pub company_store: Arc<dyn company::CompanyStoreApi>,
pub file_upload_store: Arc<dyn file_upload::FileUploadStoreApi>,
}

/// Creates a new instance of the DbContext with the given SurrealDB configuration.
pub async fn get_db_context(conf: &Config) -> Result<DbContext> {
let surreal_db_config = SurrealDbConfig::new(&conf.surreal_db_connection);
let db = get_surreal_db(&surreal_db_config).await?;

let contact_store = Arc::new(SurrealContactStore::new(db));
let company_store =
Arc::new(FileBasedCompanyStore::new(&conf.data_dir, "company", "data", "keys").await?);
let file_upload_store =
Arc::new(FileUploadStore::new(&conf.data_dir, "files", "temp_upload").await?);

Check warning on line 74 in src/persistence/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/mod.rs#L71-L74

Added lines #L71 - L74 were not covered by tests

let bill_store = Arc::new(
FileBasedBillStore::new(
&conf.data_dir,
"bills",
"files",
"temp_upload",
"bills_keys",
)
.await?,
);
if let Err(e) = bill_store.cleanup_temp_uploads().await {
if let Err(e) = file_upload_store.cleanup_temp_uploads().await {

Check warning on line 76 in src/persistence/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/mod.rs#L76

Added line #L76 was not covered by tests
error!("Error cleaning up temp upload folder for bill: {e}");
}

let contact_store = Arc::new(SurrealContactStore::new(db));

Check warning on line 80 in src/persistence/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/mod.rs#L80

Added line #L80 was not covered by tests

let bill_store =
Arc::new(FileBasedBillStore::new(&conf.data_dir, "bills", "files", "bills_keys").await?);

Check warning on line 83 in src/persistence/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/mod.rs#L82-L83

Added lines #L82 - L83 were not covered by tests

let identity_store = Arc::new(
FileBasedIdentityStore::new(
&conf.data_dir,
Expand All @@ -95,5 +97,7 @@ pub async fn get_db_context(conf: &Config) -> Result<DbContext> {
contact_store,
bill_store,
identity_store,
company_store,
file_upload_store,

Check warning on line 101 in src/persistence/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/mod.rs#L100-L101

Added lines #L100 - L101 were not covered by tests
})
}
23 changes: 13 additions & 10 deletions src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,22 @@ pub async fn create_service_context(
shutdown_sender: broadcast::Sender<bool>,
db: DbContext,
) -> Result<ServiceContext> {
let contact_service = ContactService::new(client.clone(), db.contact_store);
let bill_service = BillService::new(client.clone(), db.bill_store, db.identity_store.clone());
let identity_service = IdentityService::new(client.clone(), db.identity_store);
let contact_service = ContactService::new(client.clone(), db.contact_store.clone());
let bill_service = BillService::new(
client.clone(),
db.bill_store,
db.identity_store.clone(),
db.file_upload_store.clone(),
);
let identity_service = IdentityService::new(client.clone(), db.identity_store.clone());

let company_store =
FileBasedCompanyStore::new(&config.data_dir, "company", "data", "keys").await?;
let company_service = CompanyService::new(
Arc::new(company_store),
file_upload_store.clone(),
identity_store.clone(),
contact_store.clone(),
db.company_store,
db.file_upload_store.clone(),
db.identity_store,
db.contact_store,
);
let file_upload_service = FileUploadService::new(file_upload_store);
let file_upload_service = FileUploadService::new(db.file_upload_store);

Check warning on line 194 in src/service/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/service/mod.rs#L179-L194

Added lines #L179 - L194 were not covered by tests

Ok(ServiceContext::new(
config,
Expand Down

0 comments on commit 763a58d

Please sign in to comment.