Skip to content

Commit

Permalink
new endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
optk2k committed Dec 11, 2023
1 parent eb14da8 commit 689aecc
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 5 deletions.
111 changes: 108 additions & 3 deletions df_designer/main.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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 ??
"""
Empty file added df_designer_front/fron_dir.txt
Empty file.
Empty file added static/for_static_file.txt
Empty file.
34 changes: 32 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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"
Expand Down

0 comments on commit 689aecc

Please sign in to comment.