diff --git a/src/comment.rs b/src/comment.rs index a87de3b..e7ea416 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -8,6 +8,7 @@ use crate::Id; pub mod data; pub mod db_entry; +pub mod mapped; pub mod pipeline; pub mod provider; diff --git a/src/comment/provider.rs b/src/comment/provider.rs new file mode 100644 index 0000000..7f045a1 --- /dev/null +++ b/src/comment/provider.rs @@ -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; + async fn ini_comment(&self, data: CommentData) -> Result; + async fn del_comment(&self, id: Id) -> Result<()>; +} + +pub struct DefaultCommentProvider { + ini: Box, + get: Box, + set: Box, + del: Box +} + +impl DefaultCommentProvider { + pub fn new( + ini: Box, + get: Box, + set: Box, + del: Box + ) -> Self { + DefaultCommentProvider { ini, get, set, del } + } +} + +#[async_trait] +impl CommentProvider for DefaultCommentProvider { + async fn get_comment(&self, id: Id) -> Result { + //self.get.get_data(id).await + todo!() + } + + async fn ini_comment(&self, data: CommentData) -> Result { + self.ini.call(data).await + } + + async fn del_comment(&self, id: Id) -> Result<()> { + self.del.call(id).await + } +} diff --git a/src/post.rs b/src/post.rs index 7d69ad1..0196f69 100644 --- a/src/post.rs +++ b/src/post.rs @@ -8,6 +8,7 @@ use crate::Id; pub mod data; pub mod db_entry; +pub mod mapped; pub mod pipeline; pub mod provider; diff --git a/src/post/provider.rs b/src/post/provider.rs new file mode 100644 index 0000000..e5db426 --- /dev/null +++ b/src/post/provider.rs @@ -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; + async fn ini_post(&self, data: PostData) -> Result; + async fn del_post(&self, id: Id) -> Result<()>; +} + +pub struct DefaultPostProvider { + ini: Box, + get: Box, + set: Box, + del: Box +} + +impl DefaultPostProvider { + pub fn new( + ini: Box, + get: Box, + set: Box, + del: Box + ) -> Self { + DefaultPostProvider { ini, get, set, del } + } +} + +#[async_trait] +impl PostProvider for DefaultPostProvider { + async fn get_post(&self, id: Id) -> Result { + //self.get.get_data(id).await + todo!() + } + + async fn ini_post(&self, data: PostData) -> Result { + self.ini.call(data).await + } + + async fn del_post(&self, id: Id) -> Result<()> { self.del.call(id).await } +} diff --git a/src/user.rs b/src/user.rs index 6451dd1..b6727ca 100644 --- a/src/user.rs +++ b/src/user.rs @@ -10,6 +10,7 @@ use crate::Id; pub mod data; pub mod db_entry; +pub mod mapped; pub mod pipeline; pub mod provider; diff --git a/src/user/provider.rs b/src/user/provider.rs new file mode 100644 index 0000000..b08b743 --- /dev/null +++ b/src/user/provider.rs @@ -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; + async fn ini_user(&self, data: UserData) -> Result; + async fn del_user(&self, id: Id) -> Result<()>; +} + +pub struct DefaultUserProvider { + ini: Box, + get: Box, + set: Box, + del: Box +} + +impl DefaultUserProvider { + pub fn new( + ini: Box, + get: Box, + set: Box, + del: Box + ) -> Self { + DefaultUserProvider { ini, get, set, del } + } +} + +#[async_trait] +impl UserProvider for DefaultUserProvider { + async fn get_user(&self, id: Id) -> Result { + //self.get.get_data(id).await + todo!() + } + + async fn ini_user(&self, data: UserData) -> Result { + self.ini.call(data).await + } + + async fn del_user(&self, id: Id) -> Result<()> { self.del.call(id).await } +}