Add word break style
This commit is contained in:
@@ -15,14 +15,22 @@ def create_oborud(item: schemas.OborudCreate, db: Session = Depends(database.get
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
@oboruds.get("/", response_model=list[schemas.OborudRead])
|
@oboruds.get("/", response_model=list[schemas.OborudRead])
|
||||||
def list_oboruds(aud_id: Optional[int] = None, sort_by_inv: bool = False, db: Session = Depends(database.get_db)):
|
def list_oboruds(aud_id: Optional[int] = None, sort_by_inv: bool = False, unassigned: bool = False, db: Session = Depends(database.get_db)):
|
||||||
query = db.query(models.Oboruds)
|
query = db.query(models.Oboruds)
|
||||||
if aud_id is not None:
|
if unassigned:
|
||||||
|
query = query.filter(models.Oboruds.aud_id == None)
|
||||||
|
elif aud_id is not None:
|
||||||
query = query.filter(models.Oboruds.aud_id == aud_id)
|
query = query.filter(models.Oboruds.aud_id == aud_id)
|
||||||
if sort_by_inv:
|
if sort_by_inv:
|
||||||
query = query.order_by(models.Oboruds.invNumber.asc())
|
query = query.order_by(models.Oboruds.invNumber.asc())
|
||||||
return query.all()
|
return query.all()
|
||||||
|
|
||||||
|
@oboruds.get("/stats")
|
||||||
|
def oboruds_stats(db: Session = Depends(database.get_db)):
|
||||||
|
total = db.query(models.Oboruds).count()
|
||||||
|
unassigned = db.query(models.Oboruds).filter(models.Oboruds.aud_id == None).count()
|
||||||
|
return {"total": total, "unassigned": unassigned}
|
||||||
|
|
||||||
@oboruds.get("/{oborud_id}", response_model=schemas.OborudRead)
|
@oboruds.get("/{oborud_id}", response_model=schemas.OborudRead)
|
||||||
def get_oborud(oborud_id: int, db: Session = Depends(database.get_db)):
|
def get_oborud(oborud_id: int, db: Session = Depends(database.get_db)):
|
||||||
obj = db.query(models.Oboruds).filter(models.Oboruds.id == oborud_id).first()
|
obj = db.query(models.Oboruds).filter(models.Oboruds.id == oborud_id).first()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
from datetime import datetime, timezone
|
||||||
from .. import models, schemas, database
|
from .. import models, schemas, database
|
||||||
from ..security import require_roles
|
from ..security import require_roles
|
||||||
|
|
||||||
@@ -7,12 +8,25 @@ zametki = APIRouter(prefix="/zametki", tags=["zametki"])
|
|||||||
|
|
||||||
@zametki.post("/", response_model=schemas.ZametkaRead, dependencies=[Depends(require_roles(["admin", "editor"]))])
|
@zametki.post("/", response_model=schemas.ZametkaRead, dependencies=[Depends(require_roles(["admin", "editor"]))])
|
||||||
def create_zametka(item: schemas.ZametkaCreate, db: Session = Depends(database.get_db)):
|
def create_zametka(item: schemas.ZametkaCreate, db: Session = Depends(database.get_db)):
|
||||||
obj = models.Zametki(**item.dict())
|
obj = models.Zametki(txtzam=item.txtzam, created_date=datetime.now(timezone.utc))
|
||||||
db.add(obj)
|
db.add(obj)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(obj)
|
db.refresh(obj)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
@zametki.get("/", response_model=list[schemas.ZametkaRead])
|
@zametki.get("/", response_model=list[schemas.ZametkaRead])
|
||||||
def list_zametki(db: Session = Depends(database.get_db)):
|
def list_zametki(active_only: bool = True, db: Session = Depends(database.get_db)):
|
||||||
return db.query(models.Zametki).all()
|
query = db.query(models.Zametki)
|
||||||
|
if active_only:
|
||||||
|
query = query.filter(models.Zametki.rmdt == None)
|
||||||
|
return query.order_by(models.Zametki.created_date.desc()).all()
|
||||||
|
|
||||||
|
@zametki.patch("/{zametka_id}/resolve", response_model=schemas.ZametkaRead, dependencies=[Depends(require_roles(["admin", "editor"]))])
|
||||||
|
def resolve_zametka(zametka_id: int, db: Session = Depends(database.get_db)):
|
||||||
|
obj = db.query(models.Zametki).filter(models.Zametki.id == zametka_id).first()
|
||||||
|
if not obj:
|
||||||
|
raise HTTPException(status_code=404, detail="Zametka not found")
|
||||||
|
obj.rmdt = datetime.now(timezone.utc)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(obj)
|
||||||
|
return obj
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ class ZametkaCreate(ZametkaBase):
|
|||||||
|
|
||||||
class ZametkaRead(ZametkaBase):
|
class ZametkaRead(ZametkaBase):
|
||||||
id: int
|
id: int
|
||||||
created_date: datetime
|
created_date: Optional[datetime] = None
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
|||||||
Reference in New Issue
Block a user