diff --git a/src/multilang_translator/translator_api/endpoints_db.py b/src/multilang_translator/translator_api/endpoints_db.py index b7b86d1..4339c76 100644 --- a/src/multilang_translator/translator_api/endpoints_db.py +++ b/src/multilang_translator/translator_api/endpoints_db.py @@ -31,7 +31,7 @@ ENDPOINTS: dict[int: Endpoint] = { # for now make sure, .id and key are the same ), } -# Database of endpoint groups with default endpoints +# Database of endpoint groups with default endpoints ENDPOINT_GROUPS: dict[int:EndpointGroup] = { # for now make sure , .id and key are the same 0: EndpointGroup( id=0, @@ -127,7 +127,7 @@ def update_group(group_id: int, updated_group: EndpointGroup) -> EndpointGroup: # Validate that all referenced endpoints exist for endpoint in updated_group.endpoints: if endpoint.id not in ENDPOINTS.keys(): - raise ValueError(f"Endpoint {endpoint_id} not found") + raise ValueError(f"Endpoint with id {endpoint.id} not found") # Ensure the ID is preserved updated_group.id = group_id diff --git a/src/multilang_translator/translator_api/translator_api.py b/src/multilang_translator/translator_api/translator_api.py index e0199b0..c16b677 100644 --- a/src/multilang_translator/translator_api/translator_api.py +++ b/src/multilang_translator/translator_api/translator_api.py @@ -29,11 +29,7 @@ app.add_middleware( allow_headers=["*"], ) - -# Get available endpoints and languages from the database -AVAILABLE_ENDPOINTS = endpoints_db.get_all_endpoints() # TODO: this should pobably not be cached here -AVAILABLE_LANGUAGES = endpoints_db.get_available_languages() - +# Endpoint configuration cache CURRENT_ENDPOINT_CONFIG = {} def init_endpoint(endpoint: Endpoint, languages: list[str]): @@ -228,15 +224,6 @@ async def reset_endpoints_after_delay(endpoint_ids, delay_seconds): log.error(f"Failed to reset endpoint {endpoint_id}: {e}") -@app.get("/groups/{group_id}/state") # TODO: think about progress tracking -async def get_group_state(group_id: int): - """Get the status of a specific endpoint.""" - # Check if the endpoint exists - ep_group = endpoints_db.get_group_by_id(group_id) - if not ep_group: - raise HTTPException(status_code=404, detail=f"Endpoint {group_id} not found") - - return {"name": ep_group.current_state.name, "value": ep_group.current_state.value} @app.get("/groups") @@ -254,6 +241,16 @@ async def create_group(group: endpoints_db.EndpointGroup): except ValueError as e: raise HTTPException(status_code=400, detail=str(e)) +@app.get("/groups/{group_id}/state") # TODO: think about progress tracking +async def get_group_state(group_id: int): + """Get the status of a specific endpoint.""" + # Check if the endpoint exists + ep_group = endpoints_db.get_group_by_id(group_id) + if not ep_group: + raise HTTPException(status_code=404, detail=f"Endpoint {group_id} not found") + + return {"name": ep_group.current_state.name, "value": ep_group.current_state.value} + @app.put("/groups/{group_id}") async def update_group(group_id: int, updated_group: endpoints_db.EndpointGroup): @@ -297,20 +294,20 @@ async def start_announcement(text: str, group_id: int): @app.get("/endpoints") async def get_available_endpoints(): """Get all available endpoints with their capabilities.""" - return AVAILABLE_ENDPOINTS + return endpoints_db.get_all_endpoints() @app.get("/languages") async def get_available_languages(): """Get all available languages for announcements.""" - return AVAILABLE_LANGUAGES + return endpoints_db.get_available_languages() if __name__ == "__main__": import uvicorn log.basicConfig( - level=log.INFO, + level=log.DEBUG, format='%(module)s.py:%(lineno)d %(levelname)s: %(message)s' ) # with reload=True logging of modules does not function as expected