Revize 4911f0ea
Přidáno uživatelem Matěj Zeman před asi 2 roky(ů)
server/sql_app/api/pcs_web.py | ||
---|---|---|
9 | 9 |
from fastapi.templating import Jinja2Templates |
10 | 10 |
|
11 | 11 |
models.Base.metadata.create_all(bind=engine) |
12 |
templates = Jinja2Templates(directory="templates/pcs") |
|
13 | 12 |
|
13 |
# Path to html templates used in this file |
|
14 |
templates = Jinja2Templates(directory="../templates/pcs") |
|
15 |
|
|
16 |
# prefix used for all endpoints in this file |
|
14 | 17 |
pcs_web = APIRouter(prefix="/api/v1") |
15 | 18 |
|
16 | 19 |
|
... | ... | |
25 | 28 |
|
26 | 29 |
@pcs_web.get("/pcs-web", response_class=HTMLResponse) |
27 | 30 |
async def read_pcs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
31 |
""" |
|
32 |
Returns template with all pcs currently saved in database |
|
33 |
""" |
|
28 | 34 |
pcs = crud.get_pcs(db, skip=skip, limit=limit) |
29 | 35 |
return templates.TemplateResponse("pcs.html", {"request": request, "pcs": pcs}) |
30 | 36 |
|
31 | 37 |
|
32 | 38 |
@pcs_web.get("/pc-team/{pc_id}", response_class=HTMLResponse) |
33 | 39 |
async def connect_pc_team(request: Request, pc_id: int, db: Session = Depends(get_db)): |
40 |
""" |
|
41 |
Returns template with Form for connecting pc with team |
|
42 |
""" |
|
34 | 43 |
pc = crud.get_pc(db, pc_id) |
35 | 44 |
teams = crud.get_teams(db, 0, 100) |
36 | 45 |
return templates.TemplateResponse("pcteam.html", |
... | ... | |
40 | 49 |
@pcs_web.post("/pcs-web/{pc_id}", response_class=HTMLResponse) |
41 | 50 |
async def connect_post(request: Request, pc_id: int, team: str = Form(...), skip: int = 0, limit: int = 100, |
42 | 51 |
db: Session = Depends(get_db)): |
52 |
""" |
|
53 |
Endpoint called from within form for connecting pc with team. Updates certain pc with new team. |
|
54 |
""" |
|
43 | 55 |
old_pc = crud.update_pc(db, pc_id, team) |
44 | 56 |
pcs = crud.get_pcs(db, skip=skip, limit=limit) |
45 | 57 |
return templates.TemplateResponse("pcs.html", {"request": request, "pcs": pcs}) |
Také k dispozici: Unified diff
re #9577 Api code documentation.