Acebots-AI / my-tiny-service

0 stars 1 forks source link

Add new endpoint for exponentiation #69

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 plan that outlines the steps and changes needed:

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

    • Add a new endpoint function for exponentiation similar to the existing mathematical operation endpoints.
    • The function should take two numbers, A and B, and return A^B. Use the MathsIn class for input and MathsResult for output.
    • Example code snippet:
      @router.post(
       "/exponentiation",
       summary="Calculate the exponentiation of a base number to a power",
       response_model=MathsResult,
      )
      def exponentiation(maths_input: MathsIn) -> MathsResult:
       """Calculates the exponentiation of a base number to a power."""
       result = maths_input.a ** maths_input.b
       return MathsResult(result=result)
  2. Update the Pydantic models if necessary:

    • If the existing MathsIn and MathsResult classes in maths.py meet the requirements for the exponentiation endpoint (which they likely do, as they are designed for mathematical operations), no changes are needed here.
  3. Update tests in test_api.py in the tests directory:

    • Add a new test function to ensure the exponentiation endpoint works as expected.
    • Example code snippet:
      def test_exponentiation(client: starlette.testclient.TestClient) -> None:
       """Test that the exponentiation endpoint correctly calculates the power of a number."""
       response = client.post("/exponentiation", json={"a": 2, "b": 3})
       assert response.status_code == 200
       assert response.json() == {"result": 8}
  4. Ensure all changes are properly documented:

    • Update the API documentation comments and any external documentation to include the new exponentiation endpoint.

This plan focuses on adding the new endpoint in a way that is consistent with the existing project structure and coding conventions. The changes are localized to the maths.py file for the endpoint implementation and the test_api.py file for testing, minimizing the impact on the rest of the project.

artmoskvin commented 3 months ago

@acedev-dev-ai could you double-check the MathsIn schema to verify the fields?

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

After reviewing the MathsIn schema, it appears that the fields are named number1 and number2, not a and b as initially mentioned. Here's the updated plan with the correct field names:

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

    • Add a new endpoint function for exponentiation. Use the MathsIn class for input and MathsResult for output, adjusting for the correct field names.
    • Example code snippet:
      @router.post(
       "/exponentiation",
       summary="Calculate the exponentiation of a base number to a power",
       response_model=MathsResult,
      )
      def exponentiation(maths_input: MathsIn) -> MathsResult:
       """Calculates the exponentiation of a base number to a power."""
       result = maths_input.number1 ** maths_input.number2
       return MathsResult(result=result)
  2. No changes needed for Pydantic models:

    • The existing MathsIn and MathsResult classes are suitable for the exponentiation endpoint.
  3. Update tests in test_api.py in the tests directory:

    • Add a new test function for the exponentiation endpoint, using the correct field names.
    • Example code snippet:
      def test_exponentiation(client: starlette.testclient.TestClient) -> None:
       """Test that the exponentiation endpoint correctly calculates the power of a number."""
       response = client.post("/exponentiation", json={"number1": 2, "number2": 3})
       assert response.status_code == 200
       assert response.json() == {"result": 8}
  4. Ensure all changes are properly documented:

    • Update the API documentation comments and any external documentation to include the new exponentiation endpoint with the correct field names.

This updated plan corrects the field names in the MathsIn schema, ensuring the implementation aligns with the existing project structure.

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 via the following link: Pull Request #70.