Projekt

Obecné

Profil

Stáhnout (1021 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1
from typing import List
2

    
3
from fastapi import Depends, FastAPI, HTTPException, APIRouter, Form
4
from sqlalchemy.orm import Session
5
from datetime import datetime
6
from sql_app import crud, models, schemas
7
from ..database import SessionLocal, engine
8

    
9
models.Base.metadata.create_all(bind=engine)
10

    
11
licenses = APIRouter(prefix="/api/v1")
12

    
13

    
14
# Dependency
15
def get_db():
16
    db = SessionLocal()
17
    try:
18
        yield db
19
    finally:
20
        db.close()
21

    
22

    
23
@licenses.get("/licenses", response_model=List[schemas.License])
24
def read_licenses(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
25
    licenses = crud.get_licenses(db, skip=skip, limit=limit)
26
    return licenses
27

    
28

    
29
@licenses.post("/device-license", response_model=schemas.DeviceLicense)
30
def create_device_license(device_license: schemas.DeviceLicenseCreate, db: Session = Depends(get_db)):
31
    print(crud.create_device_license(db=db, device=device_license.device_id, license=device_license.license_id,
32
                                     time=datetime.now()))
(4-4/11)