Acebots-AI / my-tiny-service

0 stars 1 forks source link

Add new endpoint for exponentiation #65

Closed artmoskvin closed 3 months ago

artmoskvin commented 3 months ago

The endpoint should take 2 numbers A and B and return A^B.

acebots-ai-local[bot] commented 3 months ago

To add a new endpoint for exponentiation in the project, here's a detailed plan:

  1. Update maths.py in the my_tiny_service/api/routers directory:

    • Add a new endpoint function for exponentiation similar to the existing mathematical operations.
    • Define the endpoint with @router.post("/exponentiation", summary="Calculate the exponentiation of two numbers", response_model=MathsResult).
    • Implement the function to calculate A^B using the input model MathsIn and return a MathsResult instance.
  2. Update the input and output models if necessary:

    • If the existing models MathsIn and MathsResult in maths.py are sufficient for the exponentiation operation (i.e., they can handle the input and output data types), no changes are needed.
    • If not, modify or extend these models to suit the needs of the exponentiation operation.
  3. Update tests in test_api.py:

    • Add a new test function to tests/test_api.py to ensure the exponentiation endpoint works as expected.
    • The test should send a request to the /exponentiation endpoint with two numbers and verify the response matches the expected result of A^B.
  4. Ensure all changes are backward compatible:

    • Make sure the addition of the new endpoint does not affect the existing functionality of the API.
    • Run all existing tests to ensure they still pass after the changes.

Here's a code snippet for the new endpoint in 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)

And a test snippet for test_api.py:

def test_exponentiation(client: starlette.testclient.TestClient) -> None:
    """Test that the exponentiation endpoint correctly calculates A^B."""
    response = client.post("/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 specific requirements or constraints not covered, please let me know so I can adjust the plan accordingly.

artmoskvin commented 3 months ago

@acedev-dev-ai looks good, proceed with implementation

acebots-ai-local[bot] commented 3 months ago

The implementation for adding a new endpoint for exponentiation has been completed, and a pull request has been created. You can review and merge the changes through the following link: Pull Request #66.

This pull request includes:

Please review the changes, and if everything looks good, you can merge the pull request. If there are any further adjustments needed, feel free to let me know!