Ejemplo n.º 1
0
 async def create_offer_for_cleaning(self, *,
                                     new_offer: OfferCreate) -> OfferInDB:
     created_offer = await self.db.fetch_one(
         query=CREATE_OFFER_FOR_CLEANING_QUERY,
         values={
             **new_offer.dict(), "status": "pending"
         })
     return OfferInDB(**created_offer)
Ejemplo n.º 2
0
 async def create_offer_for_cleaning(self, *,
                                     new_offer: OfferCreate) -> OfferInDB:
     try:
         created_offer = await self.db.fetch_one(
             query=CREATE_OFFER_FOR_CLEANING_QUERY,
             values={
                 **new_offer.dict(), "status": "pending"
             })
         return OfferInDB(**created_offer)
     except UniqueViolationError:
         raise HTTPException(
             status_code=status.HTTP_400_BAD_REQUEST,
             detail=
             "Users aren't allowed create more than one offer for a cleaning job.",
         )
Ejemplo n.º 3
0
    async def create_offer_for_cleaning(self, *, new_offer: OfferCreate) -> OfferInDB:
        try:
            created_offer = await self.db.fetch_one(
                query=CREATE_OFFER_FOR_CLEANING_QUERY, values={**new_offer.dict(), "status": "pending"}
            )
            return OfferInDB(**created_offer)

        # this looks very familiar to the 403 unauthorized request we've refactored all
        # over the place into its own dependency. Catching a UniqueViolationError as a
        # way to prevent duplicate entries is another permissions issue. When we see
        # this, our thinking should go directly to dependencies.
        except UniqueViolationError:
            raise HTTPException(
                status_code=status.HTTP_400_BAD_REQUEST,
                detail="Users aren't allowed create more than one offer for a cleaning job.",
            )