crud_nft.py 1021 B

12345678910111213141516171819202122232425262728293031323334
  1. from typing import Any, Dict, List, Optional, Union
  2. from sqlalchemy.orm import Session
  3. from app.core.security import get_password_hash, verify_password
  4. from app.crud.base import CRUDBase
  5. from app.models.nft import nft
  6. from app.schemas.nft import NftBase, NftCreate, NftUpdate
  7. class CRUDUser(CRUDBase[nft, NftBase, NftCreate]):
  8. def get_multi_by_owner(
  9. self, db: Session, *, skip: int = 0, limit: int = 100, owner_id: str
  10. ) -> List[nft]:
  11. return db.query(nft).filter(nft.userid==owner_id).offset(skip).limit(limit).all()
  12. def create_with_owner(self, db: Session, *, obj_in: NftCreate, owner_id:str) -> nft:
  13. db_obj = nft(
  14. hash=obj_in.hash,
  15. imgurl=obj_in.imgurl,
  16. userid=owner_id,
  17. title=obj_in.title,
  18. context=obj_in.context,
  19. is_active=obj_in.is_active,
  20. category=obj_in.category
  21. )
  22. db.add(db_obj)
  23. db.commit()
  24. db.refresh(db_obj)
  25. return db_obj
  26. nft = CRUDUser(nft)