Skip to content

Commit bb0f9d4

Browse files
committed
wip
1 parent 4cea65c commit bb0f9d4

File tree

27 files changed

+1738
-2
lines changed

27 files changed

+1738
-2
lines changed

Cargo.lock

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

Cargo.nix

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ rec {
177177
# File a bug if you depend on any for non-debug work!
178178
debug = internal.debugCrate { inherit packageId; };
179179
};
180+
"academy_core_course_contracts" = rec {
181+
packageId = "academy_core_course_contracts";
182+
build = internal.buildRustCrateWithFeatures {
183+
packageId = "academy_core_course_contracts";
184+
};
185+
186+
# Debug support which might change between releases.
187+
# File a bug if you depend on any for non-debug work!
188+
debug = internal.debugCrate { inherit packageId; };
189+
};
190+
"academy_core_course_impl" = rec {
191+
packageId = "academy_core_course_impl";
192+
build = internal.buildRustCrateWithFeatures {
193+
packageId = "academy_core_course_impl";
194+
};
195+
196+
# Debug support which might change between releases.
197+
# File a bug if you depend on any for non-debug work!
198+
debug = internal.debugCrate { inherit packageId; };
199+
};
180200
"academy_core_finance_contracts" = rec {
181201
packageId = "academy_core_finance_contracts";
182202
build = internal.buildRustCrateWithFeatures {
@@ -652,6 +672,10 @@ rec {
652672
name = "academy_core_contact_impl";
653673
packageId = "academy_core_contact_impl";
654674
}
675+
{
676+
name = "academy_core_course_impl";
677+
packageId = "academy_core_course_impl";
678+
}
655679
{
656680
name = "academy_core_finance_contracts";
657681
packageId = "academy_core_finance_contracts";
@@ -896,6 +920,10 @@ rec {
896920
name = "academy_core_contact_contracts";
897921
packageId = "academy_core_contact_contracts";
898922
}
923+
{
924+
name = "academy_core_course_contracts";
925+
packageId = "academy_core_course_contracts";
926+
}
899927
{
900928
name = "academy_core_finance_contracts";
901929
packageId = "academy_core_finance_contracts";
@@ -1610,6 +1638,76 @@ rec {
16101638
}
16111639
];
16121640

1641+
};
1642+
"academy_core_course_contracts" = rec {
1643+
crateName = "academy_core_course_contracts";
1644+
version = "0.0.0";
1645+
edition = "2021";
1646+
src = lib.cleanSourceWith { filter = sourceFilter; src = ./academy_core/course/contracts; };
1647+
dependencies = [
1648+
{
1649+
name = "academy_models";
1650+
packageId = "academy_models";
1651+
}
1652+
{
1653+
name = "anyhow";
1654+
packageId = "anyhow";
1655+
usesDefaultFeatures = false;
1656+
features = [ "std" ];
1657+
}
1658+
{
1659+
name = "mockall";
1660+
packageId = "mockall";
1661+
optional = true;
1662+
usesDefaultFeatures = false;
1663+
}
1664+
{
1665+
name = "thiserror";
1666+
packageId = "thiserror 2.0.11";
1667+
usesDefaultFeatures = false;
1668+
}
1669+
];
1670+
features = {
1671+
"mock" = [ "dep:mockall" ];
1672+
};
1673+
resolvedDefaultFeatures = [ "mock" ];
1674+
};
1675+
"academy_core_course_impl" = rec {
1676+
crateName = "academy_core_course_impl";
1677+
version = "0.0.0";
1678+
edition = "2021";
1679+
src = lib.cleanSourceWith { filter = sourceFilter; src = ./academy_core/course/impl; };
1680+
dependencies = [
1681+
{
1682+
name = "academy_auth_contracts";
1683+
packageId = "academy_auth_contracts";
1684+
}
1685+
{
1686+
name = "academy_core_course_contracts";
1687+
packageId = "academy_core_course_contracts";
1688+
}
1689+
{
1690+
name = "academy_di";
1691+
packageId = "academy_di";
1692+
}
1693+
{
1694+
name = "academy_models";
1695+
packageId = "academy_models";
1696+
}
1697+
{
1698+
name = "academy_persistence_contracts";
1699+
packageId = "academy_persistence_contracts";
1700+
}
1701+
{
1702+
name = "academy_shared_contracts";
1703+
packageId = "academy_shared_contracts";
1704+
}
1705+
{
1706+
name = "academy_utils";
1707+
packageId = "academy_utils";
1708+
}
1709+
];
1710+
16131711
};
16141712
"academy_core_finance_contracts" = rec {
16151713
crateName = "academy_core_finance_contracts";

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ academy_core_config_contracts.path = "academy_core/config/contracts"
5757
academy_core_config_impl.path = "academy_core/config/impl"
5858
academy_core_contact_contracts.path = "academy_core/contact/contracts"
5959
academy_core_contact_impl.path = "academy_core/contact/impl"
60+
academy_core_course_contracts.path = "academy_core/course/contracts"
61+
academy_core_course_impl.path = "academy_core/course/impl"
6062
academy_core_finance_contracts.path = "academy_core/finance/contracts"
6163
academy_core_finance_impl.path = "academy_core/finance/impl"
6264
academy_core_health_contracts.path = "academy_core/health/contracts"

academy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ academy_core_coin_contracts.workspace = true
2020
academy_core_coin_impl.workspace = true
2121
academy_core_config_impl.workspace = true
2222
academy_core_contact_impl.workspace = true
23+
academy_core_course_impl.workspace = true
2324
academy_core_finance_contracts.workspace = true
2425
academy_core_finance_impl.workspace = true
2526
academy_core_health_impl.workspace = true

academy/src/environment/types.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use academy_cache_valkey::ValkeyCache;
88
use academy_core_coin_impl::{coin::CoinServiceImpl, CoinFeatureServiceImpl};
99
use academy_core_config_impl::ConfigFeatureServiceImpl;
1010
use academy_core_contact_impl::ContactFeatureServiceImpl;
11+
use academy_core_course_impl::CourseFeatureServiceImpl;
1112
use academy_core_finance_impl::{
1213
coin::FinanceCoinServiceImpl, invoice::FinanceInvoiceServiceImpl, FinanceFeatureServiceImpl,
1314
};
@@ -41,8 +42,8 @@ use academy_extern_impl::{
4142
vat::VatApiServiceImpl,
4243
};
4344
use academy_persistence_postgres::{
44-
coin::PostgresCoinRepository, heart::PostgresHeartRepository, mfa::PostgresMfaRepository,
45-
oauth2::PostgresOAuth2Repository, paypal::PostgresPaypalRepository,
45+
coin::PostgresCoinRepository, course::PostgresCourseRepository, heart::PostgresHeartRepository,
46+
mfa::PostgresMfaRepository, oauth2::PostgresOAuth2Repository, paypal::PostgresPaypalRepository,
4647
premium::PostgresPremiumRepository, session::PostgresSessionRepository,
4748
user::PostgresUserRepository, PostgresDatabase,
4849
};
@@ -68,6 +69,7 @@ pub type RestServer = academy_api_rest::RestServer<
6869
FinanceFeature,
6970
HeartFeature,
7071
PremiumFeature,
72+
CourseFeature,
7173
Internal,
7274
>;
7375

@@ -113,6 +115,7 @@ pub type CoinRepo = PostgresCoinRepository;
113115
pub type PaypalRepo = PostgresPaypalRepository;
114116
pub type HeartRepo = PostgresHeartRepository;
115117
pub type PremiumRepo = PostgresPremiumRepository;
118+
pub type CourseRepo = PostgresCourseRepository;
116119

117120
// Auth
118121
pub type Auth =
@@ -233,4 +236,6 @@ pub type PremiumPlan = PremiumPlanServiceImpl;
233236
pub type Premium = PremiumServiceImpl<Time, PremiumPurchase, PremiumRepo>;
234237
pub type PremiumPurchase = PremiumPurchaseServiceImpl<Id, Time, Coin, PremiumPlan, PremiumRepo>;
235238

239+
pub type CourseFeature = CourseFeatureServiceImpl<Database, Auth, Id, Time, CourseRepo>;
240+
236241
pub type Internal = InternalServiceImpl<Database, AuthInternal, UserRepo, Coin, Heart, Premium>;

academy_api/rest/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ academy_auth_contracts.workspace = true
1515
academy_core_coin_contracts.workspace = true
1616
academy_core_config_contracts.workspace = true
1717
academy_core_contact_contracts.workspace = true
18+
academy_core_course_contracts.workspace = true
1819
academy_core_finance_contracts.workspace = true
1920
academy_core_health_contracts.workspace = true
2021
academy_core_heart_contracts.workspace = true

academy_api/rest/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66
use academy_core_coin_contracts::CoinFeatureService;
77
use academy_core_config_contracts::ConfigFeatureService;
88
use academy_core_contact_contracts::ContactFeatureService;
9+
use academy_core_course_contracts::CourseFeatureService;
910
use academy_core_finance_contracts::FinanceFeatureService;
1011
use academy_core_health_contracts::HealthFeatureService;
1112
use academy_core_heart_contracts::HeartFeatureService;
@@ -57,6 +58,7 @@ pub struct RestServer<
5758
Finance,
5859
Heart,
5960
Premium,
61+
Course,
6062
Internal,
6163
> {
6264
_config: RestServerConfig,
@@ -72,6 +74,7 @@ pub struct RestServer<
7274
finance: Finance,
7375
heart: Heart,
7476
premium: Premium,
77+
course: Course,
7578
internal: Internal,
7679
}
7780

@@ -101,6 +104,7 @@ impl<
101104
Finance,
102105
Heart,
103106
Premium,
107+
Course,
104108
Internal,
105109
>
106110
RestServer<
@@ -116,6 +120,7 @@ impl<
116120
Finance,
117121
Heart,
118122
Premium,
123+
Course,
119124
Internal,
120125
>
121126
where
@@ -131,6 +136,7 @@ where
131136
Finance: FinanceFeatureService,
132137
Heart: HeartFeatureService,
133138
Premium: PremiumFeatureService,
139+
Course: CourseFeatureService,
134140
Internal: InternalService,
135141
{
136142
pub async fn serve(self) -> anyhow::Result<()> {
@@ -162,6 +168,7 @@ where
162168
routes::finance::TAG,
163169
routes::heart::TAG,
164170
routes::premium::TAG,
171+
routes::course::TAG,
165172
routes::internal::TAG,
166173
]
167174
.into_iter()
@@ -239,6 +246,7 @@ where
239246
.merge(routes::finance::router(self.finance.into()))
240247
.merge(routes::heart::router(self.heart.into()))
241248
.merge(routes::premium::router(self.premium.into()))
249+
.merge(routes::course::router(self.course.into()))
242250
.merge(routes::internal::router(self.internal.into()))
243251
}
244252
}

academy_api/rest/src/models/course.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use academy_models::{
2+
course::{Course, CourseDescription, CourseId, CourseLanguage, CourseTitle},
3+
url::Url,
4+
};
5+
use schemars::JsonSchema;
6+
use serde::{Deserialize, Serialize};
7+
8+
#[derive(Debug, Clone, Serialize, JsonSchema)]
9+
pub struct ApiCourse {
10+
pub id: CourseId,
11+
pub title: CourseTitle,
12+
pub description: Option<CourseDescription>,
13+
pub updated_at: i64,
14+
pub language: Option<ApiCourseLanguage>,
15+
pub image: Option<Url>,
16+
pub price: u32,
17+
}
18+
19+
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
20+
pub enum ApiCourseLanguage {
21+
English,
22+
German,
23+
}
24+
25+
impl From<Course> for ApiCourse {
26+
fn from(value: Course) -> Self {
27+
Self {
28+
id: value.id,
29+
title: value.title,
30+
description: value.description,
31+
updated_at: value.updated_at.timestamp(),
32+
language: value.language.map(Into::into),
33+
image: value.image,
34+
price: value.price,
35+
}
36+
}
37+
}
38+
39+
impl From<CourseLanguage> for ApiCourseLanguage {
40+
fn from(value: CourseLanguage) -> Self {
41+
match value {
42+
CourseLanguage::English => Self::English,
43+
CourseLanguage::German => Self::German,
44+
}
45+
}
46+
}

academy_api/rest/src/models/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::const_schema;
88

99
pub mod coin;
1010
pub mod contact;
11+
pub mod course;
1112
pub mod heart;
1213
pub mod oauth2;
1314
pub mod premium;

0 commit comments

Comments
 (0)