Skip to content

Commit

Permalink
feat(backend): add crate for lock service
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Dec 26, 2024
1 parent 3bd1be1 commit a0f96ed
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ members = [
"crates/services/importer",
"crates/services/integration",
"crates/services/jwt",
"crates/services/lock",
"crates/services/miscellaneous",
"crates/services/notification",
"crates/services/statistics",
Expand Down Expand Up @@ -144,6 +145,7 @@ serde_with = { version = "=3.11.0", features = ["chrono_0_4"] }
serde-xml-rs = "=0.6.0"
slug = "=0.1.6"
sonarr-api-rs = "=3.0.0"
sqlx = "=0.8.2"
strum = { version = "=0.26.3", features = ["derive"] }
struson = { version = "=0.6.0", features = ["serde"] }
reqwest = { version = "=0.12.9", features = ["json", "stream"] }
Expand Down
1 change: 1 addition & 0 deletions apps/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ importer-resolver = { path = "../../crates/resolvers/importer" }
importer-service = { path = "../../crates/services/importer" }
integration-service = { path = "../../crates/services/integration" }
itertools = { workspace = true }
lock-service = { path = "../../crates/services/lock" }
logs-wheel = { workspace = true }
migrations = { path = "../../crates/migrations" }
miscellaneous-resolver = { path = "../../crates/resolvers/miscellaneous" }
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use importer_resolver::{ImporterMutation, ImporterQuery};
use importer_service::ImporterService;
use integration_service::IntegrationService;
use itertools::Itertools;
use lock_service::LockService;
use miscellaneous_resolver::{MiscellaneousMutation, MiscellaneousQuery};
use miscellaneous_service::MiscellaneousService;
use openidconnect::{
Expand Down Expand Up @@ -71,10 +72,12 @@ pub async fn create_app_services(
config.file_storage.s3_bucket_name.clone(),
));
let cache_service = CacheService::new(&db, config.clone());
let lock_service = LockService::new(&db);
let supporting_service = Arc::new(
SupportingService::new(
&db,
timezone,
lock_service,
cache_service,
config.clone(),
oidc_client,
Expand Down
24 changes: 24 additions & 0 deletions crates/services/lock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "lock-service"
version = "0.1.0"
edition = "2021"

[dependencies]
async-graphql = { workspace = true }
chrono = { workspace = true }
common-models = { path = "../../models/common" }
common-utils = { path = "../../utils/common" }
config = { path = "../../config" }
database-models = { path = "../../models/database" }
dependent-models = { path = "../../models/dependent" }
env-utils = { path = "../../utils/env" }
sea-orm = { workspace = true }
sea-query = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sqlx = { workspace = true }
tracing = { workspace = true }
uuid = { workspace = true }

[package.metadata.cargo-machete]
ignored = ["serde", "tracing"]
19 changes: 19 additions & 0 deletions crates/services/lock/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use async_graphql::Result;
use common_models::ApplicationCacheKey;
use sea_orm::DatabaseConnection;

pub struct LockService {
db: DatabaseConnection,
}

impl LockService {
pub fn new(db: &DatabaseConnection) -> Self {
Self { db: db.clone() }
}
}

impl LockService {
pub async fn acquire_lock(&self, key: ApplicationCacheKey) -> Result<bool> {
todo!()
}
}
1 change: 1 addition & 0 deletions crates/services/supporting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ env-utils = { path = "../../utils/env" }
file-storage-service = { path = "../../services/file-storage" }
isolang = { workspace = true }
itertools = { workspace = true }
lock-service = { path = "../../services/lock" }
openidconnect = { workspace = true }
rustypipe = { workspace = true }
sea-orm = { workspace = true }
Expand Down
4 changes: 4 additions & 0 deletions crates/services/supporting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use enum_models::{
use env_utils::{APP_VERSION, UNKEY_API_ID};
use file_storage_service::FileStorageService;
use itertools::Itertools;
use lock_service::LockService;
use openidconnect::core::CoreClient;
use rustypipe::param::{Language, LANGUAGES};
use sea_orm::{DatabaseConnection, EntityTrait, Iterable, PaginatorTrait};
Expand All @@ -31,6 +32,7 @@ use unkey::{models::VerifyKeyRequest, Client};
pub struct SupportingService {
pub db: DatabaseConnection,
pub timezone: chrono_tz::Tz,
pub lock_service: LockService,
pub cache_service: CacheService,
pub config: Arc<config::AppConfig>,
pub oidc_client: Option<CoreClient>,
Expand All @@ -46,6 +48,7 @@ impl SupportingService {
pub async fn new(
db: &DatabaseConnection,
timezone: chrono_tz::Tz,
lock_service: LockService,
cache_service: CacheService,
config: Arc<config::AppConfig>,
oidc_client: Option<CoreClient>,
Expand All @@ -58,6 +61,7 @@ impl SupportingService {
config,
timezone,
oidc_client,
lock_service,
cache_service,
db: db.clone(),
file_storage_service,
Expand Down

0 comments on commit a0f96ed

Please sign in to comment.