File tree Expand file tree Collapse file tree 5 files changed +25
-14
lines changed Expand file tree Collapse file tree 5 files changed +25
-14
lines changed Original file line number Diff line number Diff line change 8
8
Controller ,
9
9
Module ,
10
10
UseGuards ,
11
+ UseInterceptors ,
11
12
Version ,
12
13
exception_handler ,
13
14
extra_args ,
14
15
file ,
15
- interceptors ,
16
16
middleware ,
17
17
openapi_info ,
18
18
render ,
198
198
"IInterceptorsConsumer" ,
199
199
"IGuardsConsumer" ,
200
200
"EllarInterceptor" ,
201
- "interceptors " ,
201
+ "UseInterceptors " ,
202
202
]
203
203
204
204
Original file line number Diff line number Diff line change 7
7
from .file import file
8
8
from .guards import UseGuards
9
9
from .html import render , template_filter , template_global
10
- from .interceptor import interceptors
10
+ from .interceptor import UseInterceptors
11
11
from .middleware import middleware
12
12
from .modules import Module
13
13
from .openapi import openapi_info
29
29
"openapi_info" ,
30
30
"Module" ,
31
31
"extra_args" ,
32
- "interceptors " ,
32
+ "UseInterceptors " ,
33
33
]
34
34
35
35
Original file line number Diff line number Diff line change 8
8
from ellar .common import EllarInterceptor
9
9
10
10
11
- def interceptors (
11
+ def UseInterceptors (
12
12
* args : t .Union [t .Type ["EllarInterceptor" ], "EllarInterceptor" ]
13
13
) -> t .Callable :
14
14
"""
15
- =========FUNCTION DECORATOR ==============
15
+ =========CONTROLLER AND FUNCTION DECORATOR ==============
16
16
17
- Programmatically adds extra route function parameter.
18
- see https://github.com/eadwinCode/ellar/blob/main/tests/test_routing/test_extra_args.py for usages
19
- :param args: Collection EllarInterceptor
17
+ Decorator that binds interceptors to the scope of the controller or method,
18
+ depending on its context.
19
+
20
+ When `@UseInterceptors` is used at the controller level, the interceptor will
21
+ be applied to every handler (method) in the controller.
22
+
23
+ When `@UseInterceptors` is used at the individual handler level, the interceptor
24
+ will apply only to that specific method.
25
+
26
+ Note
27
+ Interceptors can also be set up globally for all controllers and routes
28
+ using `app.use_global_interceptors()`.
29
+
30
+ :param args: A single EllarInterceptor instance or class, or a list of EllarInterceptor instances or classes.
20
31
:return:
21
32
"""
22
33
return set_meta (ROUTE_INTERCEPTORS , list (args ))
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ def middleware() -> t.Callable:
16
16
"""
17
17
========= MODULE DECORATOR ==============
18
18
19
- Defines middle functions at module level
19
+ Defines middleware functions at @Module decorated class level
20
20
:return: Function
21
21
"""
22
22
Original file line number Diff line number Diff line change 5
5
ControllerBase ,
6
6
EllarInterceptor ,
7
7
IExecutionContext ,
8
+ UseInterceptors ,
8
9
get ,
9
- interceptors ,
10
10
ws_route ,
11
11
)
12
12
from ellar .di import injectable
@@ -41,19 +41,19 @@ async def intercept(
41
41
return {"message" : str (cex )}
42
42
43
43
44
+ @UseInterceptors (Interceptor1 )
44
45
@Controller ("" )
45
46
class InterceptorControllerTest (ControllerBase ):
46
- @interceptors (Interceptor1 )
47
+ @UseInterceptors (Interceptor1 )
47
48
@get ("/interceptor-1" )
48
49
async def interceptor_1 (self ):
49
50
return {"message" : "intercepted okay" }
50
51
51
- @interceptors (InterceptCustomException ())
52
+ @UseInterceptors (InterceptCustomException ())
52
53
@get ("/interceptor-exception" )
53
54
async def interceptor_exception (self ):
54
55
raise CustomException ("Wrong data!!" )
55
56
56
- @interceptors (Interceptor1 )
57
57
@ws_route ("/interceptor-ws" )
58
58
async def interceptor_1_ws (self ):
59
59
ws = self .context .switch_to_websocket ().get_client ()
You can’t perform that action at this time.
0 commit comments