Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from sqlalchemy.orm import Session
  2. from schemas.auction import CreateAuction
  3. from db.models.auction import Auction
  4. from db.repository.user import get_user_by_id
  5. from db.repository.vehicle import get_vehicle_by_id
  6. def get_all_auctions(db: Session):
  7. auctions = db.query(Auction).all()
  8. for auction in auctions:
  9. auction.car = auction.vehicle
  10. return auctions
  11. def get_auction_by_id(id: int, db: Session):
  12. auction = db.query(Auction).filter(Auction.Id == id).first()
  13. if not auction:
  14. return None
  15. auction.car = auction.vehicle
  16. return auction
  17. def create_new_auction(auction: CreateAuction, createId: int, db: Session):
  18. vehicle = get_vehicle_by_id(auction.carId, db)
  19. if vehicle is None:
  20. return "novehicle"
  21. auction_object = Auction(
  22. initialPrice=auction.initialPrice,
  23. minimalBet=auction.minimalBet,
  24. carID=auction.carId,
  25. creatorId=createId,
  26. dateStart=auction.dateStart,
  27. dateEnd=auction.dateEnd,
  28. )
  29. db.add(auction_object)
  30. db.commit()
  31. db.refresh(auction_object)
  32. return auction_object
  33. def delete_auction_by_id(id: int, db: Session):
  34. auction = db.query(Auction).filter(Auction.Id == id).first()
  35. if not auction:
  36. return "noauction"
  37. db.delete(auction)
  38. db.commit()
  39. return auction
  40. def edit_auction_by_id(id: int, auction: CreateAuction, db: Session):
  41. auction_db = db.query(Auction).filter(Auction.Id == id)
  42. auction_object = auction_db.first()
  43. if not auction_object:
  44. return "noauction"
  45. auction_object.initialPrice = auction.initialPrice
  46. auction_object.minimalBet = auction.minimalBet
  47. auction_object.carID = auction.carId
  48. auction_object.dateStart = auction.dateStart
  49. auction_object.dateEnd = auction.dateEnd
  50. db.add(auction_object)
  51. db.commit()
  52. db.refresh(auction_object)
  53. return auction_object