Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Defelo committed Feb 6, 2025
1 parent 4cea65c commit bb0f9d4
Show file tree
Hide file tree
Showing 27 changed files with 1,738 additions and 2 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

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

98 changes: 98 additions & 0 deletions Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,26 @@ rec {
# File a bug if you depend on any for non-debug work!
debug = internal.debugCrate { inherit packageId; };
};
"academy_core_course_contracts" = rec {
packageId = "academy_core_course_contracts";
build = internal.buildRustCrateWithFeatures {
packageId = "academy_core_course_contracts";
};

# Debug support which might change between releases.
# File a bug if you depend on any for non-debug work!
debug = internal.debugCrate { inherit packageId; };
};
"academy_core_course_impl" = rec {
packageId = "academy_core_course_impl";
build = internal.buildRustCrateWithFeatures {
packageId = "academy_core_course_impl";
};

# Debug support which might change between releases.
# File a bug if you depend on any for non-debug work!
debug = internal.debugCrate { inherit packageId; };
};
"academy_core_finance_contracts" = rec {
packageId = "academy_core_finance_contracts";
build = internal.buildRustCrateWithFeatures {
Expand Down Expand Up @@ -652,6 +672,10 @@ rec {
name = "academy_core_contact_impl";
packageId = "academy_core_contact_impl";
}
{
name = "academy_core_course_impl";
packageId = "academy_core_course_impl";
}
{
name = "academy_core_finance_contracts";
packageId = "academy_core_finance_contracts";
Expand Down Expand Up @@ -896,6 +920,10 @@ rec {
name = "academy_core_contact_contracts";
packageId = "academy_core_contact_contracts";
}
{
name = "academy_core_course_contracts";
packageId = "academy_core_course_contracts";
}
{
name = "academy_core_finance_contracts";
packageId = "academy_core_finance_contracts";
Expand Down Expand Up @@ -1610,6 +1638,76 @@ rec {
}
];

};
"academy_core_course_contracts" = rec {
crateName = "academy_core_course_contracts";
version = "0.0.0";
edition = "2021";
src = lib.cleanSourceWith { filter = sourceFilter; src = ./academy_core/course/contracts; };
dependencies = [
{
name = "academy_models";
packageId = "academy_models";
}
{
name = "anyhow";
packageId = "anyhow";
usesDefaultFeatures = false;
features = [ "std" ];
}
{
name = "mockall";
packageId = "mockall";
optional = true;
usesDefaultFeatures = false;
}
{
name = "thiserror";
packageId = "thiserror 2.0.11";
usesDefaultFeatures = false;
}
];
features = {
"mock" = [ "dep:mockall" ];
};
resolvedDefaultFeatures = [ "mock" ];
};
"academy_core_course_impl" = rec {
crateName = "academy_core_course_impl";
version = "0.0.0";
edition = "2021";
src = lib.cleanSourceWith { filter = sourceFilter; src = ./academy_core/course/impl; };
dependencies = [
{
name = "academy_auth_contracts";
packageId = "academy_auth_contracts";
}
{
name = "academy_core_course_contracts";
packageId = "academy_core_course_contracts";
}
{
name = "academy_di";
packageId = "academy_di";
}
{
name = "academy_models";
packageId = "academy_models";
}
{
name = "academy_persistence_contracts";
packageId = "academy_persistence_contracts";
}
{
name = "academy_shared_contracts";
packageId = "academy_shared_contracts";
}
{
name = "academy_utils";
packageId = "academy_utils";
}
];

};
"academy_core_finance_contracts" = rec {
crateName = "academy_core_finance_contracts";
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ academy_core_config_contracts.path = "academy_core/config/contracts"
academy_core_config_impl.path = "academy_core/config/impl"
academy_core_contact_contracts.path = "academy_core/contact/contracts"
academy_core_contact_impl.path = "academy_core/contact/impl"
academy_core_course_contracts.path = "academy_core/course/contracts"
academy_core_course_impl.path = "academy_core/course/impl"
academy_core_finance_contracts.path = "academy_core/finance/contracts"
academy_core_finance_impl.path = "academy_core/finance/impl"
academy_core_health_contracts.path = "academy_core/health/contracts"
Expand Down
1 change: 1 addition & 0 deletions academy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ academy_core_coin_contracts.workspace = true
academy_core_coin_impl.workspace = true
academy_core_config_impl.workspace = true
academy_core_contact_impl.workspace = true
academy_core_course_impl.workspace = true
academy_core_finance_contracts.workspace = true
academy_core_finance_impl.workspace = true
academy_core_health_impl.workspace = true
Expand Down
9 changes: 7 additions & 2 deletions academy/src/environment/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use academy_cache_valkey::ValkeyCache;
use academy_core_coin_impl::{coin::CoinServiceImpl, CoinFeatureServiceImpl};
use academy_core_config_impl::ConfigFeatureServiceImpl;
use academy_core_contact_impl::ContactFeatureServiceImpl;
use academy_core_course_impl::CourseFeatureServiceImpl;
use academy_core_finance_impl::{
coin::FinanceCoinServiceImpl, invoice::FinanceInvoiceServiceImpl, FinanceFeatureServiceImpl,
};
Expand Down Expand Up @@ -41,8 +42,8 @@ use academy_extern_impl::{
vat::VatApiServiceImpl,
};
use academy_persistence_postgres::{
coin::PostgresCoinRepository, heart::PostgresHeartRepository, mfa::PostgresMfaRepository,
oauth2::PostgresOAuth2Repository, paypal::PostgresPaypalRepository,
coin::PostgresCoinRepository, course::PostgresCourseRepository, heart::PostgresHeartRepository,
mfa::PostgresMfaRepository, oauth2::PostgresOAuth2Repository, paypal::PostgresPaypalRepository,
premium::PostgresPremiumRepository, session::PostgresSessionRepository,
user::PostgresUserRepository, PostgresDatabase,
};
Expand All @@ -68,6 +69,7 @@ pub type RestServer = academy_api_rest::RestServer<
FinanceFeature,
HeartFeature,
PremiumFeature,
CourseFeature,
Internal,
>;

Expand Down Expand Up @@ -113,6 +115,7 @@ pub type CoinRepo = PostgresCoinRepository;
pub type PaypalRepo = PostgresPaypalRepository;
pub type HeartRepo = PostgresHeartRepository;
pub type PremiumRepo = PostgresPremiumRepository;
pub type CourseRepo = PostgresCourseRepository;

// Auth
pub type Auth =
Expand Down Expand Up @@ -233,4 +236,6 @@ pub type PremiumPlan = PremiumPlanServiceImpl;
pub type Premium = PremiumServiceImpl<Time, PremiumPurchase, PremiumRepo>;
pub type PremiumPurchase = PremiumPurchaseServiceImpl<Id, Time, Coin, PremiumPlan, PremiumRepo>;

pub type CourseFeature = CourseFeatureServiceImpl<Database, Auth, Id, Time, CourseRepo>;

pub type Internal = InternalServiceImpl<Database, AuthInternal, UserRepo, Coin, Heart, Premium>;
1 change: 1 addition & 0 deletions academy_api/rest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ academy_auth_contracts.workspace = true
academy_core_coin_contracts.workspace = true
academy_core_config_contracts.workspace = true
academy_core_contact_contracts.workspace = true
academy_core_course_contracts.workspace = true
academy_core_finance_contracts.workspace = true
academy_core_health_contracts.workspace = true
academy_core_heart_contracts.workspace = true
Expand Down
8 changes: 8 additions & 0 deletions academy_api/rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
use academy_core_coin_contracts::CoinFeatureService;
use academy_core_config_contracts::ConfigFeatureService;
use academy_core_contact_contracts::ContactFeatureService;
use academy_core_course_contracts::CourseFeatureService;
use academy_core_finance_contracts::FinanceFeatureService;
use academy_core_health_contracts::HealthFeatureService;
use academy_core_heart_contracts::HeartFeatureService;
Expand Down Expand Up @@ -57,6 +58,7 @@ pub struct RestServer<
Finance,
Heart,
Premium,
Course,
Internal,
> {
_config: RestServerConfig,
Expand All @@ -72,6 +74,7 @@ pub struct RestServer<
finance: Finance,
heart: Heart,
premium: Premium,
course: Course,
internal: Internal,
}

Expand Down Expand Up @@ -101,6 +104,7 @@ impl<
Finance,
Heart,
Premium,
Course,
Internal,
>
RestServer<
Expand All @@ -116,6 +120,7 @@ impl<
Finance,
Heart,
Premium,
Course,
Internal,
>
where
Expand All @@ -131,6 +136,7 @@ where
Finance: FinanceFeatureService,
Heart: HeartFeatureService,
Premium: PremiumFeatureService,
Course: CourseFeatureService,
Internal: InternalService,
{
pub async fn serve(self) -> anyhow::Result<()> {
Expand Down Expand Up @@ -162,6 +168,7 @@ where
routes::finance::TAG,
routes::heart::TAG,
routes::premium::TAG,
routes::course::TAG,
routes::internal::TAG,
]
.into_iter()
Expand Down Expand Up @@ -239,6 +246,7 @@ where
.merge(routes::finance::router(self.finance.into()))
.merge(routes::heart::router(self.heart.into()))
.merge(routes::premium::router(self.premium.into()))
.merge(routes::course::router(self.course.into()))
.merge(routes::internal::router(self.internal.into()))
}
}
Expand Down
46 changes: 46 additions & 0 deletions academy_api/rest/src/models/course.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use academy_models::{
course::{Course, CourseDescription, CourseId, CourseLanguage, CourseTitle},
url::Url,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ApiCourse {
pub id: CourseId,
pub title: CourseTitle,
pub description: Option<CourseDescription>,
pub updated_at: i64,
pub language: Option<ApiCourseLanguage>,
pub image: Option<Url>,
pub price: u32,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
pub enum ApiCourseLanguage {
English,
German,
}

impl From<Course> for ApiCourse {
fn from(value: Course) -> Self {
Self {
id: value.id,
title: value.title,
description: value.description,
updated_at: value.updated_at.timestamp(),
language: value.language.map(Into::into),
image: value.image,
price: value.price,
}
}
}

impl From<CourseLanguage> for ApiCourseLanguage {
fn from(value: CourseLanguage) -> Self {
match value {
CourseLanguage::English => Self::English,
CourseLanguage::German => Self::German,
}
}
}
1 change: 1 addition & 0 deletions academy_api/rest/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::const_schema;

pub mod coin;
pub mod contact;
pub mod course;
pub mod heart;
pub mod oauth2;
pub mod premium;
Expand Down
Loading

0 comments on commit bb0f9d4

Please sign in to comment.