コード例 #1
0
def create_business(
        *,
        db: Session = Depends(get_db),
        full_name: str = Body(None),
        main_administrator: EmailStr = Body(None),
        licenses_to_purchase: int = Body(None),
        current_user: DBUser = Depends(get_current_active_user),
):
    business = crud.business.get_by_business_name(db, full_name=full_name)
    if business:
        raise HTTPException(
            status_code=400,
            detail="A business with this name already exists in the system.",
        )

    try:
        business_in = Business(full_name=full_name,
                               licenses_to_purchase=licenses_to_purchase,
                               created_by=current_user.id,
                               modified_by=current_user.id)

        business = crud.business.create(db,
                                        main_administrator,
                                        business_in=business_in)
        return business
    except Exception as e:
        print(e)
        raise HTTPException(
            status_code=400,
            detail=str(e),
        )
コード例 #2
0
    def setUp(self):
        """Instantiate the Business class so that it can be reused by other test cases."""

        self.business = Business()
        self.business.create_business(1, 'Cosmas', 'Cosma Tech', 'Nairobi',
                                      'Technology', 'Masters of ecommerce')
        self.business.create_business(2, 'John', 'John Corporate', 'Kitale',
                                      'Fishing', 'Process fish')
コード例 #3
0
 def register_business(self, user_id, business):
     """docstring for register business"""
     fields = ["name", "category", "location"]
     result = self.check_req_fields(business, fields)
     if result["success"]:
         Business(user_id=user_id, name=business["name"], category=business["category"],
                  location=business["location"]).register_business()
         return jsonify({"success":True, "message":"Business Created"}), 201
     return jsonify(result), 422
コード例 #4
0
    def post(self):
        """
        Creating an Business ad
        """
        business_schema = BusinessSchema()

        business_data = request.get_json()

        validated_business_data, errors = business_schema.load(business_data)

        if errors:
            return dict(status='fail', message=errors), 400

        business = Business(**validated_business_data)

        saved_business = business.save()

        if not saved_business:
            return dict(status='fail', message='Internal Server Error'), 500

        new_business_data, errors = business_schema.dumps(business)

        return dict(status='success',
                    data=dict(business=json.loads(new_business_data))), 201
コード例 #5
0
from app.models.business import Business

business = Business()
コード例 #6
0
    def setUp(self):
        """Instantiate the Business class so that it can be reused by other test cases."""

        self.business = Business()