File tree 3 files changed +19
-5
lines changed
sample_fastapi/app/resources
3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -4,11 +4,17 @@ def __init__(self):
4
4
pass
5
5
6
6
def dec2hex (self , value : int ) -> str :
7
- """Convert integer to hexadecimal string with '0x' prefix"""
7
+ """Convert integer to hexadecimal string with '0x' prefix.
8
+
9
+ :param int value: Integer value to convert (can be negative, zero and positive)
10
+ :return str: The converted hexadecimal with '0x' prefix
11
+ """
8
12
return hex (value )
9
13
10
14
def hex2dec (self , value : str ) -> int :
11
15
"""Convert hexadecimal string (with or without prefix) into integer.
12
16
13
- Raises `ValueError` for incorrect input"""
17
+ :param str value: Hexadecimal value to convert
18
+ :return int: The converted integer if `value` is a valid hexadecimal string
19
+ :raises ValueError: Raised for incorrect input"""
14
20
return int (value , 16 )
Original file line number Diff line number Diff line change
1
+ from typing import Annotated
2
+
1
3
from fastapi import Depends , HTTPException , status
2
4
3
5
from .models import ConversionDecResponse , ConversionHexResponse
4
6
from .services import ConverterService
5
7
6
8
7
- async def conv_dec2hex (value : int , converter : ConverterService = Depends (ConverterService )) -> ConversionHexResponse :
9
+ async def conv_dec2hex (
10
+ value : int , converter : Annotated [ConverterService , Depends (ConverterService )]
11
+ ) -> ConversionHexResponse :
8
12
"""Convert integer input into hexadecimal string"""
9
13
return ConversionHexResponse (
10
14
value = converter .dec2hex (value ),
11
15
)
12
16
13
17
14
- async def conv_hex2dec (value : str , converter : ConverterService = Depends (ConverterService )) -> ConversionDecResponse :
18
+ async def conv_hex2dec (
19
+ value : str , converter : Annotated [ConverterService , Depends (ConverterService )]
20
+ ) -> ConversionDecResponse :
15
21
"""Convert hexadecimal string input into integer"""
16
22
try :
17
23
return ConversionDecResponse (
Original file line number Diff line number Diff line change
1
+ from typing import Annotated
2
+
1
3
from fastapi import Query
2
4
3
5
from .models import HelloMessage
@@ -8,6 +10,6 @@ async def respond_hello() -> HelloMessage:
8
10
return HelloMessage (message = "Hello, World!" )
9
11
10
12
11
- async def respond_name_greet (name : str = Query ()) -> HelloMessage :
13
+ async def respond_name_greet (name : Annotated [ str , Query ()] ) -> HelloMessage :
12
14
"""Respond with "Hello, <name>!" message in a JSON"""
13
15
return HelloMessage (message = f"Hello, { name } !" )
You can’t perform that action at this time.
0 commit comments