@@ -4,41 +4,28 @@ use crate::{
44 error:: ShieldError ,
55 form:: Form ,
66 provider:: Provider ,
7- request:: Request ,
7+ request:: { Request , RequestMethod } ,
88 response:: Response ,
99 session:: { BaseSession , MethodSession } ,
1010} ;
1111use async_trait:: async_trait;
1212use serde:: { Deserialize , Serialize } ;
13- #[ cfg( feature = "utoipa" ) ]
14- use utoipa:: openapi:: HttpMethod ;
15-
16- #[ derive( Clone , Debug , Eq , Hash , Ord , PartialEq , PartialOrd ) ]
17- pub enum ActionMethod {
18- Get ,
19- Post ,
20- Put ,
21- Delete ,
22- Options ,
23- Head ,
24- Patch ,
25- Trace ,
26- }
2713
28- #[ cfg( feature = "utoipa" ) ]
29- impl From < ActionMethod > for HttpMethod {
30- fn from ( value : ActionMethod ) -> Self {
31- match value {
32- ActionMethod :: Get => Self :: Get ,
33- ActionMethod :: Post => Self :: Post ,
34- ActionMethod :: Put => Self :: Put ,
35- ActionMethod :: Delete => Self :: Delete ,
36- ActionMethod :: Options => Self :: Options ,
37- ActionMethod :: Head => Self :: Head ,
38- ActionMethod :: Patch => Self :: Patch ,
39- ActionMethod :: Trace => Self :: Trace ,
40- }
41- }
14+ #[ async_trait]
15+ pub trait Action : Send + Sync {
16+ fn id ( & self ) -> & ' static str ;
17+
18+ fn name ( & self ) -> & ' static str ;
19+
20+ fn openapi_summary ( & self ) -> & ' static str ;
21+
22+ fn openapi_description ( & self ) -> & ' static str ;
23+
24+ fn method ( & self ) -> RequestMethod ;
25+
26+ async fn forms ( & self ) -> Result < Vec < Form > , ShieldError > ;
27+
28+ async fn call ( & self , session : & BaseSession , request : Request ) -> Result < Response , ShieldError > ;
4229}
4330
4431// TODO: Think of a better name.
@@ -48,6 +35,7 @@ impl From<ActionMethod> for HttpMethod {
4835pub struct ActionForms {
4936 pub id : String ,
5037 pub name : String ,
38+ pub forms : Vec < Form > ,
5139 pub method_forms : Vec < ActionMethodForm > ,
5240}
5341
@@ -70,7 +58,7 @@ pub struct ActionProviderForm {
7058}
7159
7260#[ async_trait]
73- pub trait Action < P : Provider , S > : ErasedAction + Send + Sync {
61+ pub trait MethodAction < P : Provider , S > : ErasedMethodAction + Send + Sync {
7462 fn id ( & self ) -> String ;
7563
7664 fn name ( & self ) -> String ;
@@ -79,7 +67,7 @@ pub trait Action<P: Provider, S>: ErasedAction + Send + Sync {
7967
8068 fn openapi_description ( & self ) -> & ' static str ;
8169
82- fn method ( & self ) -> ActionMethod ;
70+ fn method ( & self ) -> RequestMethod ;
8371
8472 fn condition ( & self , _provider : & P , _session : & MethodSession < S > ) -> Result < bool , ShieldError > {
8573 Ok ( true )
@@ -96,7 +84,7 @@ pub trait Action<P: Provider, S>: ErasedAction + Send + Sync {
9684}
9785
9886#[ async_trait]
99- pub trait ErasedAction : Send + Sync {
87+ pub trait ErasedMethodAction : Send + Sync {
10088 fn erased_id ( & self ) -> String ;
10189
10290 fn erased_name ( & self ) -> String ;
@@ -105,7 +93,7 @@ pub trait ErasedAction: Send + Sync {
10593
10694 fn erased_openapi_description ( & self ) -> & ' static str ;
10795
108- fn erased_method ( & self ) -> ActionMethod ;
96+ fn erased_method ( & self ) -> RequestMethod ;
10997
11098 fn erased_condition (
11199 & self ,
@@ -129,10 +117,10 @@ pub trait ErasedAction: Send + Sync {
129117}
130118
131119#[ macro_export]
132- macro_rules! erased_action {
120+ macro_rules! erased_method_action {
133121 ( $action: ident $( , < $( $generic_name: ident : $generic_type: ident ) ,+ > ) * ) => {
134122 #[ async_trait]
135- impl $( < $( $generic_name: $generic_type + ' static ) ,+ > ) * $crate:: ErasedAction for $action $( < $( $generic_name ) ,+ > ) * {
123+ impl $( < $( $generic_name: $generic_type + ' static ) ,+ > ) * $crate:: ErasedMethodAction for $action $( < $( $generic_name ) ,+ > ) * {
136124 fn erased_id( & self ) -> String {
137125 self . id( )
138126 }
@@ -149,7 +137,7 @@ macro_rules! erased_action {
149137 self . openapi_description( )
150138 }
151139
152- fn erased_method( & self ) -> $crate:: ActionMethod {
140+ fn erased_method( & self ) -> $crate:: RequestMethod {
153141 self . method( )
154142 }
155143
0 commit comments