From 689aeccfe799becb301ca791672d2d1a0ddd4c21 Mon Sep 17 00:00:00 2001 From: optk2k Date: Mon, 11 Dec 2023 10:22:51 +0300 Subject: [PATCH] new endpoints --- df_designer/main.py | 111 ++++++++++++++++++++++++++++++++- df_designer_front/fron_dir.txt | 0 static/for_static_file.txt | 0 tests/test_main.py | 34 +++++++++- 4 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 df_designer_front/fron_dir.txt create mode 100644 static/for_static_file.txt diff --git a/df_designer/main.py b/df_designer/main.py index bc7507a6..eac031e9 100644 --- a/df_designer/main.py +++ b/df_designer/main.py @@ -1,15 +1,23 @@ +import dff from fastapi import FastAPI, Request -from fastapi.responses import RedirectResponse +from fastapi.responses import HTMLResponse +from fastapi.staticfiles import StaticFiles from df_designer.logic import get_data, save_data app = FastAPI() +app.mount("/static", StaticFiles(directory="static"), name="static") + +# TODO: добавить версию v1 +# TODO: заглушка для dff +# TODO: тесты дописать @app.get("/") -async def main_page() -> RedirectResponse: +async def main_page() -> HTMLResponse: """Main.""" - return RedirectResponse("/alive") + html = "main page" + return HTMLResponse(content=html, status_code=200) @app.get("/alive") @@ -30,3 +38,100 @@ async def get(): """Get data.""" result = await get_data() return result + + +################################################################ +# new methods +################################################################ + + +# /projects +@app.get("/projects") +async def projects_get() -> dict[str, str]: + """(get projects from db) - returns JSON of all saved projects""" + return {"status": "ok"} + + +@app.post("/projects") +async def projects_post() -> dict[str, str]: + """(add new project) - receives JSON of new project""" + return {"status": "ok"} + + +@app.patch("/projects") +async def projects_patch() -> dict[str, str]: + """(edit all projects list) - receives JSON of edited projects""" + return {"status": "ok"} + + +@app.delete("/projects") +async def projects_delete() -> dict[str, str]: + """@delete (delete project) - receives projectID by query param""" + return {"status": "ok"} + + +@app.post("/projects/upload") +async def projects_upload_post() -> dict[str, str]: + """upload""" + return {"status": "ok"} + + +@app.get("/projects/download") +async def projects_download_get() -> dict[str, str]: + """upload""" + return {"status": "ok"} + + +# /service +@app.get("/service/health") +async def service_health_get() -> dict[str, str]: + """(get health status from server)""" + return {"status": "ok"} + + +@app.get("/service/version") +async def service_version_get() -> dict[str, str]: + """(get dff curr version)""" + version = dff.__version__ + return {"status": "ok", "version": version} + + +# /library +@app.get("/library/functions") +async def library_functions_get() -> dict[str, str]: + """(get base functions) - ?? JSON""" + return {"status": "ok"} + + +@app.get("/library/llms") +async def library_llms_get() -> dict[str, str]: + """(get available llm models) - JSON of llm models""" + return {"status": "ok"} + + +# /dff +@app.post("/dff/tests/prompt") +async def dff_tests_prompt_post() -> dict[str, str]: + """(get response by user prompt) - receives user prompt, returns dff response""" + return {"status": "ok"} + + +@app.post("/dff/tests/condition") +async def dff_tests_condition_post() -> dict[str, str]: + """(test condition by user prompt) - receive user prompt, returns dff response ?and condition status""" + return {"status": "ok"} + + +# /build +@app.post("/build") +async def build_post() -> dict[str, str]: + """(send flag to compile and connect user's bot ??)""" + return {"status": "ok"} + + +""" +/git ?? + +/git/stars @get ?? +/git/forks @get ?? +""" diff --git a/df_designer_front/fron_dir.txt b/df_designer_front/fron_dir.txt new file mode 100644 index 00000000..e69de29b diff --git a/static/for_static_file.txt b/static/for_static_file.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_main.py b/tests/test_main.py index 2f2a7a00..e5298146 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -9,8 +9,8 @@ def test_main_main_page(): - response = client.get("/", follow_redirects=False) - assert response.status_code == 307 + response = client.get("/") + assert response.status_code == 200 def test_main_alive(): @@ -31,6 +31,36 @@ def test_main_get(): # assert response.json() == {"status": "true"} # make mock request +def test_projects_get(): + response = client.get("/projects") + assert response.status_code == 200 + + +def test_projects_post(): + response = client.post("/projects") + assert response.status_code == 200 + + +def test_projects_patch(): + response = client.patch("/projects") + assert response.status_code == 200 + + +def test_projects_delete(): + response = client.delete("/projects") + assert response.status_code == 200 + + +def test_projects_upload_post(): + response = client.post("/projects/upload") + assert response.status_code == 200 + + +def test_projects_download_get(): + response = client.get("/projects/download") + assert response.status_code == 200 + + def test_settings(): assert settings.app == "df_designer.main:app" assert settings.host == "127.0.0.1"