Acebots-AI / my-tiny-service

0 stars 1 forks source link

Add endpoint, time #40

Closed sprokofyev closed 7 months ago

sprokofyev commented 7 months ago

ISO format

acebots-ai[bot] commented 7 months ago

Based on the project outline, here's a plan for implementing the new endpoint that returns the current time in ISO format:

  1. Create a New Endpoint in the Root Router:

    • Add a new function in my_tiny_service/api/routers/root.py that returns the current time in ISO format. This function will use Python's datetime module to get the current time and format it accordingly.
  2. Update Router with the New Endpoint:

    • Update the router object in my_tiny_service/api/routers/root.py to include the new endpoint. This involves using the @router.get decorator to define the path and response model for the endpoint.
  3. Write Unit Tests:

    • Add new tests in tests/test_api.py to ensure the new endpoint behaves as expected. This includes testing the format of the returned time and the status code of the response.
  4. Update Documentation:

    • Ensure that the new endpoint is properly documented in the code comments. This includes a brief description of the endpoint, its path, and the format of the returned data.
  5. Review and Test:

    • Review the changes to ensure they meet the project's coding standards and test the new endpoint using the test client to ensure it behaves as expected.
sprokofyev commented 7 months ago

@acedev-ai ok let’s proceed

acebots-ai[bot] commented 7 months ago

It seems there was an issue with updating the root.py file directly due to the structure of the project and the operations performed. Given the constraints and the errors encountered, I recommend the following steps to manually implement the endpoint:

  1. Ensure Imports: Make sure that from datetime import datetime and from fastapi import APIRouter are present at the top of your my_tiny_service/api/routers/root.py file.

  2. Add the New Endpoint:

    • Below the existing endpoints in root.py, add the new endpoint function to return the current time in ISO format:
      @router.get("/time", tags=["Utility"], summary="Get current time in ISO format")
      def get_current_time() -> str:
       """Returns the current server time in ISO 8601 format."""
       current_time = datetime.utcnow().isoformat()
       return current_time
  3. Test the New Endpoint:

    • Add a new test function in tests/test_api.py to ensure the new endpoint returns the current time in the correct format and with a 200 status code.
  4. Review and Commit:

    • Review your changes for any syntax errors or typos.
    • Commit your changes to the feature/add-time-endpoint branch.
  5. Create a Pull Request:

    • Once you've tested and are satisfied with the new endpoint, create a pull request from feature/add-time-endpoint to the main branch for review.

This manual approach should guide you through adding the new endpoint successfully. If you encounter any specific issues or errors during this process, feel free to ask for further assistance.