async def create_partner_request(
    partner_request: PartnerRequestIn,
    user: UserInDB = Depends(get_current_active_user)):
    partner_request_dict = partner_request.dict()
    if not activities_collection.find_one({"_id": partner_request.activity_id
                                           }):
        raise HTTPException(
            400, detail="there is no activity category with this id.")

    partner_request_dict.update({
        "user_id": user.id,
        "created_datetime": datetime.utcnow(),
        "city": user.city,
        "country": user.country,
        "owner_full_name": user.full_name,
        "owner_username": user.username,
        "owner_profile_image": user.profile_image,
        "loc": user.loc
    })
    if user.loc:
        partner_request_dict["loc"] = user.loc
    else:
        partner_request_dict["loc"] = None

    result = partner_requests_collection.insert_one(partner_request_dict)
    created_partner_request = partner_requests_collection.find_one(
        {"_id": result.inserted_id})
    return {
        "result": True,
        "partner_request": PartnerRequestOut(**created_partner_request)
    }
async def get_partner_request(request_id: str):
    partner_request = partner_requests_collection.find_one({"id": request_id})
    request_owner = PartnerRequest(**partner_request).request_owner()

    return PartnerRequestOut(**partner_request,
                             owner_full_name=request_owner.full_name,
                             owner_username=request_owner.username,
                             owner_profile_image=request_owner.profile_image)
Example #3
0
 def save(self):
     users_collection.update_one({"_id": self.id}, {"$set": self.dict()})
     document = partner_requests_collection.find_one(
         {"document_id": self.id})
     return document