File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed
sample_fastapi/app/resources Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -4,11 +4,17 @@ def __init__(self):
44 pass
55
66 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+ """
812 return hex (value )
913
1014 def hex2dec (self , value : str ) -> int :
1115 """Convert hexadecimal string (with or without prefix) into integer.
1216
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"""
1420 return int (value , 16 )
Original file line number Diff line number Diff line change 1+ from typing import Annotated
2+
13from fastapi import Depends , HTTPException , status
24
35from .models import ConversionDecResponse , ConversionHexResponse
46from .services import ConverterService
57
68
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 :
812 """Convert integer input into hexadecimal string"""
913 return ConversionHexResponse (
1014 value = converter .dec2hex (value ),
1115 )
1216
1317
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 :
1521 """Convert hexadecimal string input into integer"""
1622 try :
1723 return ConversionDecResponse (
Original file line number Diff line number Diff line change 1+ from typing import Annotated
2+
13from fastapi import Query
24
35from .models import HelloMessage
@@ -8,6 +10,6 @@ async def respond_hello() -> HelloMessage:
810 return HelloMessage (message = "Hello, World!" )
911
1012
11- async def respond_name_greet (name : str = Query ()) -> HelloMessage :
13+ async def respond_name_greet (name : Annotated [ str , Query ()] ) -> HelloMessage :
1214 """Respond with "Hello, <name>!" message in a JSON"""
1315 return HelloMessage (message = f"Hello, { name } !" )
You can’t perform that action at this time.
0 commit comments