-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prime-domain): added canonical impl
- Loading branch information
1 parent
2928edb
commit 963bff9
Showing
8 changed files
with
114 additions
and
610 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use hex::health; | ||
use models::{Photo, PhotoCreateRequest, PhotoRecordId}; | ||
use repos::FetchModelError; | ||
|
||
use crate::PrimeDomainService; | ||
|
||
/// The canonical implementation of [`PrimeDomainService`]. | ||
pub struct PrimeDomainServiceCanonical< | ||
PR: repos::ModelRepository< | ||
Model = Photo, | ||
ModelCreateRequest = PhotoCreateRequest, | ||
CreateError = repos::CreateModelError, | ||
>, | ||
> { | ||
photo_repo: PR, | ||
} | ||
|
||
impl<PR> PrimeDomainServiceCanonical<PR> | ||
where | ||
PR: repos::ModelRepository< | ||
Model = Photo, | ||
ModelCreateRequest = PhotoCreateRequest, | ||
CreateError = repos::CreateModelError, | ||
>, | ||
{ | ||
/// Creates a new [`PrimeDomainServiceCanonical`] with the given photo | ||
/// repository. | ||
pub fn new(photo_repo: PR) -> Self { Self { photo_repo } } | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl<PR> PrimeDomainService for PrimeDomainServiceCanonical<PR> | ||
where | ||
PR: repos::ModelRepository< | ||
Model = Photo, | ||
ModelCreateRequest = PhotoCreateRequest, | ||
CreateError = repos::CreateModelError, | ||
>, | ||
{ | ||
async fn fetch_photo_by_id( | ||
&self, | ||
id: PhotoRecordId, | ||
) -> Result<Option<Photo>, FetchModelError> { | ||
self.photo_repo.fetch_model_by_id(id).await | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl<PR> health::HealthReporter for PrimeDomainServiceCanonical<PR> | ||
where | ||
PR: repos::ModelRepository< | ||
Model = Photo, | ||
ModelCreateRequest = PhotoCreateRequest, | ||
CreateError = repos::CreateModelError, | ||
>, | ||
{ | ||
fn name(&self) -> &'static str { stringify!(PrimeDomainServiceCanonical) } | ||
async fn health_check(&self) -> health::ComponentHealth { | ||
health::AdditiveComponentHealth::from_futures(vec![self | ||
.photo_repo | ||
.health_report()]) | ||
.await | ||
.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters