Skip to content

Commit

Permalink
basic service tests
Browse files Browse the repository at this point in the history
start of datatable api
start of data table implementation in templates
  • Loading branch information
madeinoz67 committed May 24, 2021
1 parent d656a03 commit 370e039
Show file tree
Hide file tree
Showing 21 changed files with 1,219 additions and 907 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
run: |
pip install poetry
poetry install --no-dev
- name: Run Test
run: |
pytest --no-cov
# - name: Install Node dependencies
# run: npm install
# - run: cp .env.example .env
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ maker_hub/static/cache_manifest.json
!.vscode/launch.json

site/*
app/coverage.xml
coverage.xml
htmlcov
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.9"
File renamed without changes.
30 changes: 30 additions & 0 deletions app/api/part_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import fastapi
from fastapi.param_functions import Depends

from app.schema.datatable import FormRequest
from app.services import part_service

api = fastapi.APIRouter()


@api.post("/api/part/table")
def table_datasource(request: FormRequest = Depends):
"""Parts Datatable Source
Returns:
[TableResponse]: [DataTable Ajax Response]
"""

draw = request.draw

# search_str = request.query_params["search[value]"]
# is_regex = bool(request.query_params["search[regex]"])
# start = int(request.query_params["start"])
# limit = int(request.query_params["length"])
data = part_service.latest_parts(limit=30)
return {
"draw": draw,
"recordsTotal": 100,
"recordsFiltered": 100,
"data": data,
}
8 changes: 7 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import fastapi
import fastapi_chameleon
import uvicorn

from starlette.staticfiles import StaticFiles
from dotenv import load_dotenv

Expand All @@ -11,6 +11,7 @@
from app.views import storage
from app.views import reports

from app.api import part_api

app = fastapi.FastAPI()

Expand All @@ -37,6 +38,11 @@ def configure_routes():
static_folder = os.path.join(folder, "static")
static_folder = os.path.abspath(static_folder)
app.mount("/static", StaticFiles(directory=static_folder), name="static")

# API endpoints
app.include_router(part_api.api)

# Webpages
app.include_router(home.router)
app.include_router(parts.router)
app.include_router(projects.router)
Expand Down
Empty file added app/schema/__init__.py
Empty file.
52 changes: 52 additions & 0 deletions app/schema/datatable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from typing import List

from fastapi import Form
from pydantic import BaseModel


class Search(BaseModel):
value: str = ""
regex: bool = False


class Order(BaseModel):
column: int = 1
dir: str = "asc"


class Column(BaseModel):
name: str = ""
data: str = ""
searchable: bool = True
orderable: bool = True
search: Search


class DataTableBase(BaseModel):
draw: int


class TableRequest(DataTableBase):
start: int
length: int
search: Search
order: Order
columns: List[Column] = []


class TableResponse(DataTableBase):
recordsTotal: int
recordsFiltered: int
data: list
error: str


class FormRequest(BaseModel):
draw: int
start: int
length: int

def __init__(
self, draw: str = Form(...), start: int = Form(...), length: int = Form(...)
):
super().__init__(draw, start, length)
7 changes: 7 additions & 0 deletions app/schema/part.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pydantic import BaseModel


class Part(BaseModel):
id: str
name: str
description: str
Loading

0 comments on commit 370e039

Please sign in to comment.