Skip to content

Commit

Permalink
refactor(extern): remove internal api service
Browse files Browse the repository at this point in the history
  • Loading branch information
Defelo committed Nov 4, 2024
1 parent 2d152a4 commit 27f091f
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 192 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
- name: test paypal
run: |
cargo run --bin academy-testing -- paypal &
while ! curl -s http://127.0.0.1:8005; do sleep .1; done
while ! curl -s http://127.0.0.1:8004; do sleep .1; done
cargo test -p academy_extern_impl --no-fail-fast --all-features --test paypal
env:
ACADEMY_CONFIG: ${{ github.workspace }}/config.dev.toml
1 change: 1 addition & 0 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,10 @@ rec {
name = "academy_cache_contracts";
packageId = "academy_cache_contracts";
}
{
name = "academy_core_coin_contracts";
packageId = "academy_core_coin_contracts";
}
{
name = "academy_core_oauth2_contracts";
packageId = "academy_core_oauth2_contracts";
Expand Down Expand Up @@ -2285,6 +2289,11 @@ rec {
packageId = "academy_cache_contracts";
features = [ "mock" ];
}
{
name = "academy_core_coin_contracts";
packageId = "academy_core_coin_contracts";
features = [ "mock" ];
}
{
name = "academy_core_oauth2_contracts";
packageId = "academy_core_oauth2_contracts";
Expand Down
10 changes: 1 addition & 9 deletions academy/src/environment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use academy_core_session_impl::SessionFeatureConfig;
use academy_core_user_impl::UserFeatureConfig;
use academy_di::provider;
use academy_extern_impl::{
internal::InternalApiServiceConfig, paypal::PaypalApiServiceConfig,
recaptcha::RecaptchaApiServiceConfig, vat::VatApiServiceConfig,
paypal::PaypalApiServiceConfig, recaptcha::RecaptchaApiServiceConfig, vat::VatApiServiceConfig,
};
use academy_models::oauth2::OAuth2Provider;
use academy_shared_impl::{
Expand All @@ -35,7 +34,6 @@ provider! {
RestServerConfig,

// Extern
InternalApiServiceConfig,
RecaptchaApiServiceConfig,
VatApiServiceConfig,
PaypalApiServiceConfig,
Expand Down Expand Up @@ -78,7 +76,6 @@ provider! {
rest_server_config: RestServerConfig,

// Extern
internal_api_service_config: InternalApiServiceConfig,
recaptcha_api_service_config: RecaptchaApiServiceConfig,
vat_api_service_config: VatApiServiceConfig,
paypal_api_service_config: PaypalApiServiceConfig,
Expand Down Expand Up @@ -115,10 +112,6 @@ impl ConfigProvider {
};

// Extern
let internal_api_service_config = InternalApiServiceConfig {
shop_url: config.internal.shop_url.clone(),
};

let recaptcha_api_service_config = RecaptchaApiServiceConfig::new(
config
.recaptcha
Expand Down Expand Up @@ -229,7 +222,6 @@ impl ConfigProvider {
rest_server_config,

// Extern
internal_api_service_config,
recaptcha_api_service_config,
vat_api_service_config,
paypal_api_service_config,
Expand Down
7 changes: 3 additions & 4 deletions academy/src/environment/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use academy_core_user_impl::{
};
use academy_email_impl::{template::TemplateEmailServiceImpl, EmailServiceImpl};
use academy_extern_impl::{
internal::InternalApiServiceImpl, oauth2::OAuth2ApiServiceImpl, paypal::PaypalApiServiceImpl,
recaptcha::RecaptchaApiServiceImpl, vat::VatApiServiceImpl,
oauth2::OAuth2ApiServiceImpl, paypal::PaypalApiServiceImpl, recaptcha::RecaptchaApiServiceImpl,
vat::VatApiServiceImpl,
};
use academy_persistence_postgres::{
coin::PostgresCoinRepository, mfa::PostgresMfaRepository, oauth2::PostgresOAuth2Repository,
Expand Down Expand Up @@ -71,7 +71,6 @@ pub type TemplateEmail = TemplateEmailServiceImpl<Email, Template>;
// Extern
pub type RecaptchaApi = RecaptchaApiServiceImpl;
pub type OAuth2Api = OAuth2ApiServiceImpl;
pub type InternalApi = InternalApiServiceImpl<AuthInternal>;
pub type VatApi = VatApiServiceImpl;
pub type PaypalApi = PaypalApiServiceImpl;

Expand Down Expand Up @@ -113,13 +112,13 @@ pub type UserFeature = UserFeatureServiceImpl<
Auth,
Captcha,
VatApi,
InternalApi,
User,
UserEmailConfirmation,
UserUpdate,
Session,
OAuth2Registration,
UserRepo,
CoinRepo,
>;
pub type User = UserServiceImpl<Id, Time, Password, UserRepo, OAuth2Link>;
pub type UserEmailConfirmation =
Expand Down
1 change: 0 additions & 1 deletion academy_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ pub struct JwtConfig {
#[derive(Debug, Deserialize)]
pub struct InternalConfig {
pub jwt_ttl: Duration,
pub shop_url: Url,
}

#[derive(Debug, Deserialize)]
Expand Down
6 changes: 4 additions & 2 deletions academy_core/user/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ repository.workspace = true
workspace = true

[dependencies]
academy_cache_contracts.workspace = true
academy_auth_contracts.workspace = true
academy_cache_contracts.workspace = true
academy_core_coin_contracts.workspace = true
academy_core_oauth2_contracts.workspace = true
academy_core_session_contracts.workspace = true
academy_core_user_contracts.workspace = true
Expand All @@ -28,8 +29,9 @@ chrono.workspace = true
tracing.workspace = true

[dev-dependencies]
academy_cache_contracts = { workspace = true, features = ["mock"] }
academy_auth_contracts = { workspace = true, features = ["mock"] }
academy_cache_contracts = { workspace = true, features = ["mock"] }
academy_core_coin_contracts = { workspace = true, features = ["mock"] }
academy_core_oauth2_contracts = { workspace = true, features = ["mock"] }
academy_core_session_contracts = { workspace = true, features = ["mock"] }
academy_core_user_contracts = { workspace = true, features = ["mock"] }
Expand Down
28 changes: 15 additions & 13 deletions academy_core/user/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ use academy_core_user_contracts::{
UserVerifyEmailError, UserVerifyNewsletterSubscriptionError,
};
use academy_di::Build;
use academy_extern_contracts::{internal::InternalApiService, vat::VatApiService};
use academy_extern_contracts::vat::VatApiService;
use academy_models::{
auth::{AccessToken, Login},
email_address::EmailAddress,
session::DeviceName,
user::{UserComposite, UserIdOrSelf, UserInvoiceInfoPatch, UserPassword, UserPatchRef},
RecaptchaResponse, VerificationCode,
};
use academy_persistence_contracts::{user::UserRepository, Database, Transaction};
use academy_persistence_contracts::{
coin::CoinRepository, user::UserRepository, Database, Transaction,
};
use academy_shared_contracts::captcha::{CaptchaCheckError, CaptchaService};
use academy_utils::{
patch::{Patch, PatchValue},
Expand All @@ -47,25 +49,25 @@ pub struct UserFeatureServiceImpl<
Auth,
Captcha,
VatApi,
InternalApi,
User,
UserEmailConfirmation,
UserUpdate,
Session,
OAuth2Registration,
UserRepo,
CoinRepo,
> {
db: Db,
auth: Auth,
captcha: Captcha,
vat_api: VatApi,
internal_api: InternalApi,
user: User,
user_email_confirmation: UserEmailConfirmation,
user_update: UserUpdate,
session: Session,
oauth2_registration: OAuth2Registration,
user_repo: UserRepo,
coin_repo: CoinRepo,
}

#[derive(Debug, Clone)]
Expand All @@ -84,39 +86,39 @@ impl<
Auth,
Captcha,
VatApi,
InternalApi,
UserS,
UserEmailConfirmation,
UserUpdate,
Session,
OAuth2RegistrationS,
UserRepo,
CoinRepo,
> UserFeatureService
for UserFeatureServiceImpl<
Db,
Auth,
Captcha,
VatApi,
InternalApi,
UserS,
UserEmailConfirmation,
UserUpdate,
Session,
OAuth2RegistrationS,
UserRepo,
CoinRepo,
>
where
Db: Database,
Auth: AuthService<Db::Transaction>,
Captcha: CaptchaService,
VatApi: VatApiService,
InternalApi: InternalApiService,
UserS: UserService<Db::Transaction>,
UserEmailConfirmation: UserEmailConfirmationService<Db::Transaction>,
UserUpdate: UserUpdateService<Db::Transaction>,
Session: SessionService<Db::Transaction>,
OAuth2RegistrationS: OAuth2RegistrationService,
UserRepo: UserRepository<Db::Transaction>,
CoinRepo: CoinRepository<Db::Transaction>,
{
#[trace_instrument(skip(self))]
async fn list_users(
Expand Down Expand Up @@ -439,10 +441,6 @@ where
commit = true;
}

if commit {
txn.commit().await?;
}

let user_composite = UserComposite {
user,
profile,
Expand All @@ -451,12 +449,16 @@ where
};

if invoice_info_updated && user_composite.can_receive_coins() {
self.internal_api
.release_coins(user_composite.user.id)
self.coin_repo
.release_coins(&mut txn, user_id)
.await
.context("Failed to release coins")?;
}

if commit {
txn.commit().await?;
}

Ok(user_composite)
}

Expand Down
8 changes: 5 additions & 3 deletions academy_core/user/impl/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ use academy_core_user_contracts::{
email_confirmation::MockUserEmailConfirmationService, update::MockUserUpdateService,
user::MockUserService,
};
use academy_extern_contracts::{internal::MockInternalApiService, vat::MockVatApiService};
use academy_persistence_contracts::{user::MockUserRepository, MockDatabase, MockTransaction};
use academy_extern_contracts::vat::MockVatApiService;
use academy_persistence_contracts::{
coin::MockCoinRepository, user::MockUserRepository, MockDatabase, MockTransaction,
};
use academy_shared_contracts::captcha::MockCaptchaService;

use crate::{UserFeatureConfig, UserFeatureServiceImpl};
Expand All @@ -29,13 +31,13 @@ type Sut = UserFeatureServiceImpl<
MockAuthService<MockTransaction>,
MockCaptchaService,
MockVatApiService,
MockInternalApiService,
MockUserService<MockTransaction>,
MockUserEmailConfirmationService<MockTransaction>,
MockUserUpdateService<MockTransaction>,
MockSessionService<MockTransaction>,
MockOAuth2RegistrationService,
MockUserRepository<MockTransaction>,
MockCoinRepository<MockTransaction>,
>;

impl Default for UserFeatureConfig {
Expand Down
10 changes: 6 additions & 4 deletions academy_core/user/impl/src/tests/update_user/invoice_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use academy_demo::{
session::BAR_1,
user::{BAR, FOO},
};
use academy_extern_contracts::{internal::MockInternalApiService, vat::MockVatApiService};
use academy_extern_contracts::vat::MockVatApiService;
use academy_models::user::{UserComposite, UserIdOrSelf, UserInvoiceInfo};
use academy_persistence_contracts::{user::MockUserRepository, MockDatabase};
use academy_persistence_contracts::{
coin::MockCoinRepository, user::MockUserRepository, MockDatabase,
};
use academy_utils::{assert_matches, patch::Patch, Apply};

use crate::{tests::Sut, UserFeatureServiceImpl};
Expand Down Expand Up @@ -94,15 +96,15 @@ async fn ok_release_coins() {
let vat_api = MockVatApiService::new()
.with_is_vat_id_valid(FOO.invoice_info.vat_id.clone().unwrap().into_inner(), true);

let internal_api = MockInternalApiService::new().with_release_coins(BAR.user.id);
let coin_repo = MockCoinRepository::new().with_release_coins(BAR.user.id);

let sut = UserFeatureServiceImpl {
auth,
db,
user_repo,
user_update,
vat_api,
internal_api,
coin_repo,
..Sut::default()
};

Expand Down
20 changes: 0 additions & 20 deletions academy_extern/contracts/src/internal.rs

This file was deleted.

1 change: 0 additions & 1 deletion academy_extern/contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod internal;
pub mod oauth2;
pub mod paypal;
pub mod recaptcha;
Expand Down
40 changes: 0 additions & 40 deletions academy_extern/impl/src/internal.rs

This file was deleted.

Loading

0 comments on commit 27f091f

Please sign in to comment.