Projekt

Obecné

Profil

Stáhnout (1.65 KB) Statistiky
| Větev: | Tag: | Revize:
1
from typing import List
2

    
3
from fastapi import Depends, FastAPI, HTTPException, APIRouter
4
from sqlalchemy.orm import Session
5
from datetime import date
6
from sql_app import crud, models, schemas
7
from ..database import SessionLocal, engine
8
from fastapi import FastAPI, Request
9
from fastapi.responses import HTMLResponse
10
from fastapi.staticfiles import StaticFiles
11
from fastapi.templating import Jinja2Templates
12

    
13
models.Base.metadata.create_all(bind=engine)
14
templates = Jinja2Templates(directory="templates/licenses")
15

    
16
licenses = APIRouter()
17

    
18

    
19
# Dependency
20
def get_db():
21
    db = SessionLocal()
22
    try:
23
        yield db
24
    finally:
25
        db.close()
26

    
27

    
28
@licenses.get("/licenses-web/", response_class=HTMLResponse)
29
async def read_pcs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
30
    licenses = crud.get_licenses(db, skip=skip, limit=limit)
31
    return templates.TemplateResponse("licenses.html", {"request": request, "licenses": licenses})
32

    
33

    
34
@licenses.post("/license/", response_model=schemas.License)
35
def create_license(license: schemas.LicenseCreate, db: Session = Depends(get_db)):
36
    print(crud.create_license(db=db, name=license.name, expdate=license.expiration_date))
37

    
38

    
39
@licenses.get("/licenses/", response_model=List[schemas.License])
40
def read_licenses(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
41
    licenses = crud.get_licenses(db, skip=skip, limit=limit)
42
    return licenses
43

    
44

    
45
@licenses.post("/device-license/", response_model=schemas.DeviceLicense)
46
def create_device_license(device_license: schemas.DeviceLicenseCreate, db: Session = Depends(get_db)):
47
    print(crud.create_device_license(db=db, device_license=device_license))
(3-3/6)