This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
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.
- Loading branch information
Showing
6 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ use crate::Id; | |
|
||
pub mod data; | ||
pub mod db_entry; | ||
pub mod mapped; | ||
pub mod pipeline; | ||
pub mod provider; | ||
|
||
|
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,51 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
|
||
use crate::comment::data::CommentData; | ||
use crate::comment::mapped::MappedCommentData; | ||
use crate::comment::pipeline::del::CommentDelPipeline; | ||
use crate::comment::pipeline::get::CommentGetPipeline; | ||
use crate::comment::pipeline::ini::CommentIniPipeline; | ||
use crate::comment::pipeline::set::CommentSetPipeline; | ||
use crate::Id; | ||
|
||
#[async_trait] | ||
pub trait CommentProvider { | ||
async fn get_comment(&self, id: Id) -> Result<MappedCommentData>; | ||
async fn ini_comment(&self, data: CommentData) -> Result<Id>; | ||
async fn del_comment(&self, id: Id) -> Result<()>; | ||
} | ||
|
||
pub struct DefaultCommentProvider { | ||
ini: Box<dyn CommentIniPipeline>, | ||
get: Box<dyn CommentGetPipeline>, | ||
set: Box<dyn CommentSetPipeline>, | ||
del: Box<dyn CommentDelPipeline> | ||
} | ||
|
||
impl DefaultCommentProvider { | ||
pub fn new( | ||
ini: Box<dyn CommentIniPipeline>, | ||
get: Box<dyn CommentGetPipeline>, | ||
set: Box<dyn CommentSetPipeline>, | ||
del: Box<dyn CommentDelPipeline> | ||
) -> Self { | ||
DefaultCommentProvider { ini, get, set, del } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl CommentProvider for DefaultCommentProvider { | ||
async fn get_comment(&self, id: Id) -> Result<MappedCommentData> { | ||
//self.get.get_data(id).await | ||
todo!() | ||
} | ||
|
||
async fn ini_comment(&self, data: CommentData) -> Result<Id> { | ||
self.ini.call(data).await | ||
} | ||
|
||
async fn del_comment(&self, id: Id) -> Result<()> { | ||
self.del.call(id).await | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ use crate::Id; | |
|
||
pub mod data; | ||
pub mod db_entry; | ||
pub mod mapped; | ||
pub mod pipeline; | ||
pub mod provider; | ||
|
||
|
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,49 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
|
||
use crate::post::data::PostData; | ||
use crate::post::mapped::MappedPostData; | ||
use crate::post::pipeline::del::PostDelPipeline; | ||
use crate::post::pipeline::get::PostGetPipeline; | ||
use crate::post::pipeline::ini::PostIniPipeline; | ||
use crate::post::pipeline::set::PostSetPipeline; | ||
use crate::Id; | ||
|
||
#[async_trait] | ||
pub trait PostProvider { | ||
async fn get_post(&self, id: Id) -> Result<MappedPostData>; | ||
async fn ini_post(&self, data: PostData) -> Result<Id>; | ||
async fn del_post(&self, id: Id) -> Result<()>; | ||
} | ||
|
||
pub struct DefaultPostProvider { | ||
ini: Box<dyn PostIniPipeline>, | ||
get: Box<dyn PostGetPipeline>, | ||
set: Box<dyn PostSetPipeline>, | ||
del: Box<dyn PostDelPipeline> | ||
} | ||
|
||
impl DefaultPostProvider { | ||
pub fn new( | ||
ini: Box<dyn PostIniPipeline>, | ||
get: Box<dyn PostGetPipeline>, | ||
set: Box<dyn PostSetPipeline>, | ||
del: Box<dyn PostDelPipeline> | ||
) -> Self { | ||
DefaultPostProvider { ini, get, set, del } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl PostProvider for DefaultPostProvider { | ||
async fn get_post(&self, id: Id) -> Result<MappedPostData> { | ||
//self.get.get_data(id).await | ||
todo!() | ||
} | ||
|
||
async fn ini_post(&self, data: PostData) -> Result<Id> { | ||
self.ini.call(data).await | ||
} | ||
|
||
async fn del_post(&self, id: Id) -> Result<()> { self.del.call(id).await } | ||
} |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ use crate::Id; | |
|
||
pub mod data; | ||
pub mod db_entry; | ||
pub mod mapped; | ||
pub mod pipeline; | ||
pub mod provider; | ||
|
||
|
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,49 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
|
||
use crate::user::data::UserData; | ||
use crate::user::mapped::MappedUserData; | ||
use crate::user::pipeline::del::UserDelPipeline; | ||
use crate::user::pipeline::get::UserGetPipeline; | ||
use crate::user::pipeline::ini::UserIniPipeline; | ||
use crate::user::pipeline::set::UserSetPipeline; | ||
use crate::Id; | ||
|
||
#[async_trait] | ||
pub trait UserProvider { | ||
async fn get_user(&self, id: Id) -> Result<MappedUserData>; | ||
async fn ini_user(&self, data: UserData) -> Result<Id>; | ||
async fn del_user(&self, id: Id) -> Result<()>; | ||
} | ||
|
||
pub struct DefaultUserProvider { | ||
ini: Box<dyn UserIniPipeline>, | ||
get: Box<dyn UserGetPipeline>, | ||
set: Box<dyn UserSetPipeline>, | ||
del: Box<dyn UserDelPipeline> | ||
} | ||
|
||
impl DefaultUserProvider { | ||
pub fn new( | ||
ini: Box<dyn UserIniPipeline>, | ||
get: Box<dyn UserGetPipeline>, | ||
set: Box<dyn UserSetPipeline>, | ||
del: Box<dyn UserDelPipeline> | ||
) -> Self { | ||
DefaultUserProvider { ini, get, set, del } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl UserProvider for DefaultUserProvider { | ||
async fn get_user(&self, id: Id) -> Result<MappedUserData> { | ||
//self.get.get_data(id).await | ||
todo!() | ||
} | ||
|
||
async fn ini_user(&self, data: UserData) -> Result<Id> { | ||
self.ini.call(data).await | ||
} | ||
|
||
async fn del_user(&self, id: Id) -> Result<()> { self.del.call(id).await } | ||
} |