Closed artmoskvin closed 3 months ago
To add a new endpoint for exponentiation in the project, we will follow these steps:
Update my_tiny_service/api/routers/maths.py
:
@router.post
decorator, similar to the existing mathematical operations.MathsIn
input model for the two numbers A and B.exponentiation(maths_input: MathsIn) -> MathsResult
that calculates A^B
.responses
dictionary if necessary, and ensure proper error handling.Update tests/test_api.py
:
test_exponentiation
to ensure the new endpoint correctly calculates the exponentiation of two numbers.Ensure proper error handling:
exponentiation
function, handle cases like zero raised to a negative exponent, which should return an error response.Documentation and Comments:
maths.py
.In my_tiny_service/api/routers/maths.py
:
@router.post(
"/exponentiation",
summary="Calculate the exponentiation of two numbers",
response_model=MathsResult,
)
def exponentiation(maths_input: MathsIn) -> MathsResult:
"""Calculates the exponentiation of two whole numbers."""
result = maths_input.number1 ** maths_input.number2
return MathsResult(result=result)
In tests/test_api.py
:
def test_exponentiation(client: starlette.testclient.TestClient) -> None:
"""Test that the exponentiation endpoint correctly calculates A^B."""
response = client.post("/maths/exponentiation", json={"number1": 2, "number2": 3})
assert response.status_code == 200
assert response.json() == {"result": 8}
This plan outlines the necessary steps and code changes to implement the new exponentiation endpoint. If there are any questions or additional requirements, please let me know.
@acedev-dev-ai excellent! proceed with implementation
The endpoint should take 2 numbers A and B and return A^B.