Skip to content

Commit 2b636a1

Browse files
committed
refactor(extern): remove internal api service
1 parent 04edb1d commit 2b636a1

File tree

26 files changed

+132
-192
lines changed

26 files changed

+132
-192
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ jobs:
126126
- name: test paypal
127127
run: |
128128
cargo run --bin academy-testing -- paypal &
129-
while ! curl -s http://127.0.0.1:8005; do sleep .1; done
129+
while ! curl -s http://127.0.0.1:8004; do sleep .1; done
130130
cargo test -p academy_extern_impl --no-fail-fast --all-features --test paypal
131131
env:
132132
ACADEMY_CONFIG: ${{ github.workspace }}/config.dev.toml

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,6 +2186,10 @@ rec {
21862186
name = "academy_cache_contracts";
21872187
packageId = "academy_cache_contracts";
21882188
}
2189+
{
2190+
name = "academy_core_coin_contracts";
2191+
packageId = "academy_core_coin_contracts";
2192+
}
21892193
{
21902194
name = "academy_core_oauth2_contracts";
21912195
packageId = "academy_core_oauth2_contracts";
@@ -2260,6 +2264,11 @@ rec {
22602264
packageId = "academy_cache_contracts";
22612265
features = [ "mock" ];
22622266
}
2267+
{
2268+
name = "academy_core_coin_contracts";
2269+
packageId = "academy_core_coin_contracts";
2270+
features = [ "mock" ];
2271+
}
22632272
{
22642273
name = "academy_core_oauth2_contracts";
22652274
packageId = "academy_core_oauth2_contracts";

academy/src/environment/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use academy_core_session_impl::SessionFeatureConfig;
1111
use academy_core_user_impl::UserFeatureConfig;
1212
use academy_di::provider;
1313
use academy_extern_impl::{
14-
internal::InternalApiServiceConfig, paypal::PaypalApiServiceConfig,
15-
recaptcha::RecaptchaApiServiceConfig, vat::VatApiServiceConfig,
14+
paypal::PaypalApiServiceConfig, recaptcha::RecaptchaApiServiceConfig, vat::VatApiServiceConfig,
1615
};
1716
use academy_models::oauth2::OAuth2Provider;
1817
use academy_shared_impl::{
@@ -35,7 +34,6 @@ provider! {
3534
RestServerConfig,
3635

3736
// Extern
38-
InternalApiServiceConfig,
3937
RecaptchaApiServiceConfig,
4038
VatApiServiceConfig,
4139
PaypalApiServiceConfig,
@@ -78,7 +76,6 @@ provider! {
7876
rest_server_config: RestServerConfig,
7977

8078
// Extern
81-
internal_api_service_config: InternalApiServiceConfig,
8279
recaptcha_api_service_config: RecaptchaApiServiceConfig,
8380
vat_api_service_config: VatApiServiceConfig,
8481
paypal_api_service_config: PaypalApiServiceConfig,
@@ -115,10 +112,6 @@ impl ConfigProvider {
115112
};
116113

117114
// Extern
118-
let internal_api_service_config = InternalApiServiceConfig {
119-
shop_url: config.internal.shop_url.clone(),
120-
};
121-
122115
let recaptcha_api_service_config = RecaptchaApiServiceConfig::new(
123116
config
124117
.recaptcha
@@ -229,7 +222,6 @@ impl ConfigProvider {
229222
rest_server_config,
230223

231224
// Extern
232-
internal_api_service_config,
233225
recaptcha_api_service_config,
234226
vat_api_service_config,
235227
paypal_api_service_config,

academy/src/environment/types.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use academy_core_user_impl::{
2929
};
3030
use academy_email_impl::{template::TemplateEmailServiceImpl, EmailServiceImpl};
3131
use academy_extern_impl::{
32-
internal::InternalApiServiceImpl, oauth2::OAuth2ApiServiceImpl, paypal::PaypalApiServiceImpl,
33-
recaptcha::RecaptchaApiServiceImpl, vat::VatApiServiceImpl,
32+
oauth2::OAuth2ApiServiceImpl, paypal::PaypalApiServiceImpl, recaptcha::RecaptchaApiServiceImpl,
33+
vat::VatApiServiceImpl,
3434
};
3535
use academy_persistence_postgres::{
3636
coin::PostgresCoinRepository, mfa::PostgresMfaRepository, oauth2::PostgresOAuth2Repository,
@@ -71,7 +71,6 @@ pub type TemplateEmail = TemplateEmailServiceImpl<Email, Template>;
7171
// Extern
7272
pub type RecaptchaApi = RecaptchaApiServiceImpl;
7373
pub type OAuth2Api = OAuth2ApiServiceImpl;
74-
pub type InternalApi = InternalApiServiceImpl<AuthInternal>;
7574
pub type VatApi = VatApiServiceImpl;
7675
pub type PaypalApi = PaypalApiServiceImpl;
7776

@@ -113,13 +112,13 @@ pub type UserFeature = UserFeatureServiceImpl<
113112
Auth,
114113
Captcha,
115114
VatApi,
116-
InternalApi,
117115
User,
118116
UserEmailConfirmation,
119117
UserUpdate,
120118
Session,
121119
OAuth2Registration,
122120
UserRepo,
121+
CoinRepo,
123122
>;
124123
pub type User = UserServiceImpl<Id, Time, Password, UserRepo, OAuth2Link>;
125124
pub type UserEmailConfirmation =

academy_config/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ pub struct JwtConfig {
140140
#[derive(Debug, Deserialize)]
141141
pub struct InternalConfig {
142142
pub jwt_ttl: Duration,
143-
pub shop_url: Url,
144143
}
145144

146145
#[derive(Debug, Deserialize)]

academy_core/user/impl/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ repository.workspace = true
1010
workspace = true
1111

1212
[dependencies]
13-
academy_cache_contracts.workspace = true
1413
academy_auth_contracts.workspace = true
14+
academy_cache_contracts.workspace = true
15+
academy_core_coin_contracts.workspace = true
1516
academy_core_oauth2_contracts.workspace = true
1617
academy_core_session_contracts.workspace = true
1718
academy_core_user_contracts.workspace = true
@@ -28,8 +29,9 @@ chrono.workspace = true
2829
tracing.workspace = true
2930

3031
[dev-dependencies]
31-
academy_cache_contracts = { workspace = true, features = ["mock"] }
3232
academy_auth_contracts = { workspace = true, features = ["mock"] }
33+
academy_cache_contracts = { workspace = true, features = ["mock"] }
34+
academy_core_coin_contracts = { workspace = true, features = ["mock"] }
3335
academy_core_oauth2_contracts = { workspace = true, features = ["mock"] }
3436
academy_core_session_contracts = { workspace = true, features = ["mock"] }
3537
academy_core_user_contracts = { workspace = true, features = ["mock"] }

academy_core/user/impl/src/lib.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ use academy_core_user_contracts::{
1818
UserVerifyEmailError, UserVerifyNewsletterSubscriptionError,
1919
};
2020
use academy_di::Build;
21-
use academy_extern_contracts::{internal::InternalApiService, vat::VatApiService};
21+
use academy_extern_contracts::vat::VatApiService;
2222
use academy_models::{
2323
auth::{AccessToken, Login},
2424
email_address::EmailAddress,
2525
session::DeviceName,
2626
user::{UserComposite, UserIdOrSelf, UserInvoiceInfoPatch, UserPassword, UserPatchRef},
2727
RecaptchaResponse, VerificationCode,
2828
};
29-
use academy_persistence_contracts::{user::UserRepository, Database, Transaction};
29+
use academy_persistence_contracts::{
30+
coin::CoinRepository, user::UserRepository, Database, Transaction,
31+
};
3032
use academy_shared_contracts::captcha::{CaptchaCheckError, CaptchaService};
3133
use academy_utils::{
3234
patch::{Patch, PatchValue},
@@ -47,25 +49,25 @@ pub struct UserFeatureServiceImpl<
4749
Auth,
4850
Captcha,
4951
VatApi,
50-
InternalApi,
5152
User,
5253
UserEmailConfirmation,
5354
UserUpdate,
5455
Session,
5556
OAuth2Registration,
5657
UserRepo,
58+
CoinRepo,
5759
> {
5860
db: Db,
5961
auth: Auth,
6062
captcha: Captcha,
6163
vat_api: VatApi,
62-
internal_api: InternalApi,
6364
user: User,
6465
user_email_confirmation: UserEmailConfirmation,
6566
user_update: UserUpdate,
6667
session: Session,
6768
oauth2_registration: OAuth2Registration,
6869
user_repo: UserRepo,
70+
coin_repo: CoinRepo,
6971
}
7072

7173
#[derive(Debug, Clone)]
@@ -84,39 +86,39 @@ impl<
8486
Auth,
8587
Captcha,
8688
VatApi,
87-
InternalApi,
8889
UserS,
8990
UserEmailConfirmation,
9091
UserUpdate,
9192
Session,
9293
OAuth2RegistrationS,
9394
UserRepo,
95+
CoinRepo,
9496
> UserFeatureService
9597
for UserFeatureServiceImpl<
9698
Db,
9799
Auth,
98100
Captcha,
99101
VatApi,
100-
InternalApi,
101102
UserS,
102103
UserEmailConfirmation,
103104
UserUpdate,
104105
Session,
105106
OAuth2RegistrationS,
106107
UserRepo,
108+
CoinRepo,
107109
>
108110
where
109111
Db: Database,
110112
Auth: AuthService<Db::Transaction>,
111113
Captcha: CaptchaService,
112114
VatApi: VatApiService,
113-
InternalApi: InternalApiService,
114115
UserS: UserService<Db::Transaction>,
115116
UserEmailConfirmation: UserEmailConfirmationService<Db::Transaction>,
116117
UserUpdate: UserUpdateService<Db::Transaction>,
117118
Session: SessionService<Db::Transaction>,
118119
OAuth2RegistrationS: OAuth2RegistrationService,
119120
UserRepo: UserRepository<Db::Transaction>,
121+
CoinRepo: CoinRepository<Db::Transaction>,
120122
{
121123
#[trace_instrument(skip(self))]
122124
async fn list_users(
@@ -439,10 +441,6 @@ where
439441
commit = true;
440442
}
441443

442-
if commit {
443-
txn.commit().await?;
444-
}
445-
446444
let user_composite = UserComposite {
447445
user,
448446
profile,
@@ -451,12 +449,16 @@ where
451449
};
452450

453451
if invoice_info_updated && user_composite.can_receive_coins() {
454-
self.internal_api
455-
.release_coins(user_composite.user.id)
452+
self.coin_repo
453+
.release_coins(&mut txn, user_id)
456454
.await
457455
.context("Failed to release coins")?;
458456
}
459457

458+
if commit {
459+
txn.commit().await?;
460+
}
461+
460462
Ok(user_composite)
461463
}
462464

academy_core/user/impl/src/tests/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ use academy_core_user_contracts::{
77
email_confirmation::MockUserEmailConfirmationService, update::MockUserUpdateService,
88
user::MockUserService,
99
};
10-
use academy_extern_contracts::{internal::MockInternalApiService, vat::MockVatApiService};
11-
use academy_persistence_contracts::{user::MockUserRepository, MockDatabase, MockTransaction};
10+
use academy_extern_contracts::vat::MockVatApiService;
11+
use academy_persistence_contracts::{
12+
coin::MockCoinRepository, user::MockUserRepository, MockDatabase, MockTransaction,
13+
};
1214
use academy_shared_contracts::captcha::MockCaptchaService;
1315

1416
use crate::{UserFeatureConfig, UserFeatureServiceImpl};
@@ -29,13 +31,13 @@ type Sut = UserFeatureServiceImpl<
2931
MockAuthService<MockTransaction>,
3032
MockCaptchaService,
3133
MockVatApiService,
32-
MockInternalApiService,
3334
MockUserService<MockTransaction>,
3435
MockUserEmailConfirmationService<MockTransaction>,
3536
MockUserUpdateService<MockTransaction>,
3637
MockSessionService<MockTransaction>,
3738
MockOAuth2RegistrationService,
3839
MockUserRepository<MockTransaction>,
40+
MockCoinRepository<MockTransaction>,
3941
>;
4042

4143
impl Default for UserFeatureConfig {

academy_core/user/impl/src/tests/update_user/invoice_info.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ use academy_demo::{
66
session::BAR_1,
77
user::{BAR, FOO},
88
};
9-
use academy_extern_contracts::{internal::MockInternalApiService, vat::MockVatApiService};
9+
use academy_extern_contracts::vat::MockVatApiService;
1010
use academy_models::user::{UserComposite, UserIdOrSelf, UserInvoiceInfo};
11-
use academy_persistence_contracts::{user::MockUserRepository, MockDatabase};
11+
use academy_persistence_contracts::{
12+
coin::MockCoinRepository, user::MockUserRepository, MockDatabase,
13+
};
1214
use academy_utils::{assert_matches, patch::Patch, Apply};
1315

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

97-
let internal_api = MockInternalApiService::new().with_release_coins(BAR.user.id);
99+
let coin_repo = MockCoinRepository::new().with_release_coins(BAR.user.id);
98100

99101
let sut = UserFeatureServiceImpl {
100102
auth,
101103
db,
102104
user_repo,
103105
user_update,
104106
vat_api,
105-
internal_api,
107+
coin_repo,
106108
..Sut::default()
107109
};
108110

0 commit comments

Comments
 (0)