From 7f80ffb761c0188c6aedc97bb7552eaf8145905a Mon Sep 17 00:00:00 2001 From: tikitko Date: Fri, 14 Jul 2023 13:12:55 +0300 Subject: [PATCH] handlers for new screw --- .../src/endpoints/author/handler.rs | 22 +++-------- .../src/endpoints/author_me/handler.rs | 20 +--------- .../src/endpoints/authors/handler.rs | 34 ++++------------- .../src/endpoints/comments/handler.rs | 38 ++++--------------- .../src/endpoints/login/handler.rs | 23 +++-------- blog-server-api/src/endpoints/post/handler.rs | 19 +--------- .../src/endpoints/posts/handler.rs | 34 ++++------------- 7 files changed, 36 insertions(+), 154 deletions(-) diff --git a/blog-server-api/src/endpoints/author/handler.rs b/blog-server-api/src/endpoints/author/handler.rs index f98957b..b03e413 100644 --- a/blog-server-api/src/endpoints/author/handler.rs +++ b/blog-server-api/src/endpoints/author/handler.rs @@ -2,15 +2,12 @@ use super::request_content::AuthorRequestContent; use super::response_content_failure::AuthorResponseContentFailure; use super::response_content_failure::AuthorResponseContentFailure::*; use super::response_content_success::AuthorResponseContentSuccess; -use crate::extensions::Resolve; -use blog_server_services::traits::author_service::AuthorService; -use screw_api::request::ApiRequest; -use screw_api::response::ApiResponse; -use std::sync::Arc; -async fn handler( - slug: String, - author_service: Arc>, +pub async fn http_handler( + (AuthorRequestContent { + slug, + author_service, + },): (AuthorRequestContent,), ) -> Result { if slug.is_empty() { return Err(SlugEmpty); @@ -26,12 +23,3 @@ async fn handler( Ok(author.into()) } - -pub async fn http_handler( - request: ApiRequest, -) -> ApiResponse -where - Extensions: Resolve>>, -{ - ApiResponse::from(handler(request.content.slug, request.content.author_service).await) -} diff --git a/blog-server-api/src/endpoints/author_me/handler.rs b/blog-server-api/src/endpoints/author_me/handler.rs index ae76b6a..90f7822 100644 --- a/blog-server-api/src/endpoints/author_me/handler.rs +++ b/blog-server-api/src/endpoints/author_me/handler.rs @@ -2,16 +2,9 @@ use super::request_content::AuthorMeRequestContent; use super::response_content_failure::AuthorMeResponseContentFailure; use super::response_content_failure::AuthorMeResponseContentFailure::*; use super::response_content_success::AuthorMeResponseContentSuccess; -use crate::extensions::Resolve; -use crate::utils::auth; -use blog_server_services::traits::author_service::{Author, AuthorService}; -use screw_api::request::ApiRequest; -use screw_api::response::ApiResponse; -use screw_components::dyn_fn::DFuture; -use std::sync::Arc; -async fn handler( - auth_author_future: DFuture>, +pub async fn http_handler( + (AuthorMeRequestContent { auth_author_future },): (AuthorMeRequestContent,), ) -> Result { auth_author_future .await @@ -20,12 +13,3 @@ async fn handler( reason: e.to_string(), }) } - -pub async fn http_handler( - request: ApiRequest, -) -> ApiResponse -where - Extensions: Resolve>>, -{ - ApiResponse::from(handler(request.content.auth_author_future).await) -} diff --git a/blog-server-api/src/endpoints/authors/handler.rs b/blog-server-api/src/endpoints/authors/handler.rs index 392005e..a5503dd 100644 --- a/blog-server-api/src/endpoints/authors/handler.rs +++ b/blog-server-api/src/endpoints/authors/handler.rs @@ -2,17 +2,14 @@ use super::request_content::AuthorsRequestContent; use super::response_content_failure::AuthorsResponseContentFailure; use super::response_content_failure::AuthorsResponseContentFailure::*; use super::response_content_success::AuthorsResponseContentSuccess; -use crate::extensions::Resolve; -use blog_server_services::traits::author_service::AuthorService; -use screw_api::request::ApiRequest; -use screw_api::response::ApiResponse; -use std::sync::Arc; -async fn handler( - query: Option, - offset: Option, - limit: Option, - author_service: Arc>, +pub async fn http_handler( + (AuthorsRequestContent { + query, + offset, + limit, + author_service, + },): (AuthorsRequestContent,), ) -> Result { let offset = offset.unwrap_or(0).max(0); let limit = limit.unwrap_or(50).max(0).min(50); @@ -48,20 +45,3 @@ async fn handler( limit, }) } - -pub async fn http_handler( - request: ApiRequest, -) -> ApiResponse -where - Extensions: Resolve>>, -{ - ApiResponse::from( - handler( - request.content.query, - request.content.offset, - request.content.limit, - request.content.author_service, - ) - .await, - ) -} diff --git a/blog-server-api/src/endpoints/comments/handler.rs b/blog-server-api/src/endpoints/comments/handler.rs index 8544b2f..2b5d22a 100644 --- a/blog-server-api/src/endpoints/comments/handler.rs +++ b/blog-server-api/src/endpoints/comments/handler.rs @@ -2,19 +2,15 @@ use super::request_content::CommentsRequestContent; use super::response_content_failure::CommentsResponseContentFailure; use super::response_content_failure::CommentsResponseContentFailure::*; use super::response_content_success::CommentsResponseContentSuccess; -use crate::extensions::Resolve; -use blog_server_services::traits::comment_service::CommentService; -use blog_server_services::traits::post_service::PostService; -use screw_api::request::ApiRequest; -use screw_api::response::ApiResponse; -use std::sync::Arc; -async fn handler( - post_slug: String, - offset: Option, - limit: Option, - comment_service: Arc>, - post_service: Arc>, +pub async fn http_handler( + (CommentsRequestContent { + post_slug, + offset, + limit, + comment_service, + post_service, + },): (CommentsRequestContent,), ) -> Result { if post_slug.is_empty() { return Err(PostSlugEmpty); @@ -55,21 +51,3 @@ async fn handler( limit, }) } - -pub async fn http_handler( - request: ApiRequest, -) -> ApiResponse -where - Extensions: Resolve>> + Resolve>>, -{ - ApiResponse::from( - handler( - request.content.post_slug, - request.content.offset, - request.content.limit, - request.content.comment_service, - request.content.post_service, - ) - .await, - ) -} diff --git a/blog-server-api/src/endpoints/login/handler.rs b/blog-server-api/src/endpoints/login/handler.rs index fe40cbf..c24a8b2 100644 --- a/blog-server-api/src/endpoints/login/handler.rs +++ b/blog-server-api/src/endpoints/login/handler.rs @@ -2,18 +2,14 @@ use super::request_content::{LoginRequestContent, LoginRequestContentData}; use super::response_content_failure::LoginResponseContentFailure; use super::response_content_failure::LoginResponseContentFailure::*; use super::response_content_success::LoginResponseContentSuccess; -use crate::extensions::Resolve; use crate::utils::{auth, password}; -use blog_server_services::traits::author_service::AuthorService; use password_hash::Error; -use screw_api::request::ApiRequest; -use screw_api::response::ApiResponse; -use screw_components::dyn_result::DResult; -use std::sync::Arc; -async fn handler( - login_data: DResult, - author_service: Arc>, +pub async fn http_handler( + (LoginRequestContent { + login_data, + author_service, + },): (LoginRequestContent,), ) -> Result { let LoginRequestContentData { slug, password } = login_data.map_err(|e| ParamsDecodeError { reason: e.to_string(), @@ -44,12 +40,3 @@ async fn handler( Ok(token.into()) } - -pub async fn http_handler( - request: ApiRequest, -) -> ApiResponse -where - Extensions: Resolve>>, -{ - ApiResponse::from(handler(request.content.login_data, request.content.author_service).await) -} diff --git a/blog-server-api/src/endpoints/post/handler.rs b/blog-server-api/src/endpoints/post/handler.rs index 9a056cf..12e4a29 100644 --- a/blog-server-api/src/endpoints/post/handler.rs +++ b/blog-server-api/src/endpoints/post/handler.rs @@ -2,15 +2,9 @@ use super::request_content::PostRequestContent; use super::response_content_failure::PostResponseContentFailure; use super::response_content_failure::PostResponseContentFailure::*; use super::response_content_success::PostResponseContentSuccess; -use crate::extensions::Resolve; -use blog_server_services::traits::post_service::PostService; -use screw_api::request::ApiRequest; -use screw_api::response::ApiResponse; -use std::sync::Arc; -async fn handler( - slug: String, - post_service: Arc>, +pub async fn http_handler( + (PostRequestContent { slug, post_service },): (PostRequestContent,), ) -> Result { if slug.is_empty() { return Err(SlugEmpty); @@ -26,12 +20,3 @@ async fn handler( Ok(post.into()) } - -pub async fn http_handler( - request: ApiRequest, -) -> ApiResponse -where - Extensions: Resolve>>, -{ - ApiResponse::from(handler(request.content.slug, request.content.post_service).await) -} diff --git a/blog-server-api/src/endpoints/posts/handler.rs b/blog-server-api/src/endpoints/posts/handler.rs index 43cc57b..42e8feb 100644 --- a/blog-server-api/src/endpoints/posts/handler.rs +++ b/blog-server-api/src/endpoints/posts/handler.rs @@ -2,17 +2,14 @@ use super::request_content::PostsRequestContent; use super::response_content_failure::PostsResponseContentFailure; use super::response_content_failure::PostsResponseContentFailure::*; use super::response_content_success::PostsResponseContentSuccess; -use crate::extensions::Resolve; -use blog_server_services::traits::post_service::PostService; -use screw_api::request::ApiRequest; -use screw_api::response::ApiResponse; -use std::sync::Arc; -async fn handler( - query: Option, - offset: Option, - limit: Option, - post_service: Arc>, +pub async fn http_handler( + (PostsRequestContent { + query, + offset, + limit, + post_service, + },): (PostsRequestContent,), ) -> Result { let offset = offset.unwrap_or(0).max(0); let limit = limit.unwrap_or(50).max(0).min(50); @@ -48,20 +45,3 @@ async fn handler( limit, }) } - -pub async fn http_handler( - request: ApiRequest, -) -> ApiResponse -where - Extensions: Resolve>>, -{ - ApiResponse::from( - handler( - request.content.query, - request.content.offset, - request.content.limit, - request.content.post_service, - ) - .await, - ) -}