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
|
||||
|
||||
@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)
|
||||
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)
|
||||
if sort_by_inv:
|
||||
query = query.order_by(models.Oboruds.invNumber.asc())
|
||||
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)
|
||||
def get_oborud(oborud_id: int, db: Session = Depends(database.get_db)):
|
||||
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 datetime import datetime, timezone
|
||||
from .. import models, schemas, database
|
||||
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"]))])
|
||||
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.commit()
|
||||
db.refresh(obj)
|
||||
return obj
|
||||
|
||||
@zametki.get("/", response_model=list[schemas.ZametkaRead])
|
||||
def list_zametki(db: Session = Depends(database.get_db)):
|
||||
return db.query(models.Zametki).all()
|
||||
def list_zametki(active_only: bool = True, db: Session = Depends(database.get_db)):
|
||||
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):
|
||||
id: int
|
||||
created_date: datetime
|
||||
created_date: Optional[datetime] = None
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
Reference in New Issue
Block a user