示例#1
0
 def put(self, fund_id):
     put_data = request.get_json()
     if not put_data:
         return UTILS.api_response(msg=UTILS.INVALID_PAYLD, code=400)
     name = put_data.get('name')
     try:
         fund = Fund.query.get(fund_id)
         existingFunds = Fund.query.filter_by(name=name).first()
         if existingFunds:
             return UTILS.api_response(msg=UTILS.EXISTS(TYPE, name),
                                       code=400,
                                       data=existingFunds.to_json())
         if fund:
             fund = UTILS.update(fund, 'name', name)
             return UTILS.api_response(msg=UTILS.UPDATED(TYPE, name),
                                       code=200,
                                       data=fund.to_json())
         else:
             return UTILS.api_response(
                 msg=UTILS.NOT_EXISTS(TYPE, fund_id),
                 code=404,
             )
     except exc.IntegrityError as e:
         db.session.rollback()
         return UTILS.api_response(
             msg=f'{UTILS.INTEGRITY_ERR} {self.__name__}',
             code=400,
             data=f'{str(e)}')
示例#2
0
 def post(self):
     post_data = request.get_json()
     if not post_data:
         return UTILS.api_response(msg=UTILS.INVALID_PAYLD,
                                   code=400,
                                   data=self.__name__)
     name = post_data.get('name')
     capital = post_data.get('capital')
     date_str = post_data.get('date')
     date = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%f%z')
     try:
         call = CapitalCall.query \
             .filter_by(name=name) \
             .first()
         if not call:
             call_i = UTILS.add_capitalcall(name, capital, date=date)
             return UTILS.api_response(msg=UTILS.ADDED(TYPE, name),
                                       code=201,
                                       data=call_i.to_json())
         else:
             return UTILS.api_response(msg=UTILS.EXISTS(TYPE, name),
                                       code=400,
                                       data=call.to_json())
     except exc.IntegrityError as e:
         db.session.rollback()
         return UTILS.api_response(
             msg=f'{UTILS.INTEGRITY_ERR} {self.__name__}',
             code=400,
             data=f'{str(e)}')
示例#3
0
 def get(self):
     """Get all capitalcalls"""
     calls = CapitalCall.query.all()
     return UTILS.api_response(
         msg=(UTILS.SUCCESS(TYPE, "")
              if calls else UTILS.SUCCESS(TYPE, "")),
         code=200 if calls else 404,
         data={'capitalcalls': [c.to_json() for c in calls]})
示例#4
0
 def get(self, fund_id):
     """Get single fund details"""
     try:
         fund = Fund.query.filter_by(id=int(fund_id)).first()
         if not fund:
             return UTILS.api_response(
                 msg=UTILS.NOT_EXISTS(TYPE, fund_id),
                 code=404,
             )
         else:
             return UTILS.api_response(msg=UTILS.SUCCESS(TYPE, fund.id),
                                       code=200,
                                       data=fund.to_json())
     except ValueError as e:
         return UTILS.api_response(msg=f'{UTILS.VALUE_ERR} {self.__name__}',
                                   code=404,
                                   data=f'{str(e)}')
示例#5
0
 def delete(self, fund_id):
     """Delete single fund details"""
     try:
         fund = Fund.query.filter_by(id=int(fund_id)).first()
         if not fund:
             return UTILS.api_response(
                 msg=UTILS.NOT_EXISTS(TYPE, fund_id),
                 code=404,
             )
         else:
             UTILS.delete(fund)
             return UTILS.api_response(msg=UTILS.DELETED(TYPE, fund.id),
                                       code=200)
     except ValueError as e:
         return UTILS.api_response(msg=f'{UTILS.VALUE_ERR} {self.__name__}',
                                   code=404,
                                   data=f'{str(e)}')
示例#6
0
 def get(self):
     """Get all funds"""
     funds = Fund.query.all()
     return UTILS.api_response(
         msg=UTILS.SUCCESS(TYPE, "") if funds else UTILS.NO_SUCCESS(
             TYPE, ""),
         code=200 if funds else 404,
         data={'funds': [fund.to_json() for fund in funds]})
示例#7
0
    def delete(self, investment_id):
        """Delete single investment details"""
        try:
            inv = Investment.query.filter_by(id=int(investment_id)).first()

            if not inv:
                return UTILS.api_response(
                    msg=UTILS.NOT_EXISTS(TYPE, investment_id),
                    code=404,
                )
            else:
                UTILS.delete(inv)
                return UTILS.api_response(msg=UTILS.DELETED(TYPE, inv.id),
                                          code=200)
        except ValueError as e:
            return UTILS.api_response(msg=f'{UTILS.VALUE_ERR} {self.__name__}',
                                      code=404,
                                      data=f'{str(e)}')
示例#8
0
 def get(self):
     """Get all committments"""
     committments = Committment.query. \
         order_by(asc(Committment.date)).all()
     return UTILS.api_response(
         msg=UTILS.SUCCESS(TYPE, "") if committments else UTILS.SUCCESS(
             TYPE, ""),
         code=200 if committments else 404,
         data={'committments': [c.to_json() for c in committments]})
示例#9
0
 def get(self, capitalcall_id):
     """Get single capitalcall details"""
     try:
         call = CapitalCall.query \
             .filter_by(id=int(capitalcall_id)).first()
         if not call:
             return UTILS.api_response(
                 msg=UTILS.NOT_EXISTS(TYPE, capitalcall_id),
                 code=404,
             )
         else:
             return UTILS.api_response(msg=UTILS.SUCCESS(TYPE, call.id),
                                       code=200,
                                       data=call.to_json())
     except ValueError as e:
         return UTILS.api_response(msg=f'{UTILS.VALUE_ERR} {self.__name__}',
                                   code=404,
                                   data=f'{str(e)}')
示例#10
0
 def get(self, committment_id):
     """Get single committment details"""
     try:
         committment = Committment.query \
             .filter_by(id=int(committment_id)).first()
         if not committment:
             return UTILS.api_response(
                 msg=UTILS.NOT_EXISTS(TYPE, committment_id),
                 code=404,
             )
         else:
             return UTILS.api_response(msg=UTILS.SUCCESS(
                 TYPE, committment.id),
                                       code=200,
                                       data=committment.to_json())
     except ValueError as e:
         return UTILS.api_response(msg=f'{UTILS.VALUE_ERR} {self.__name__}',
                                   code=404,
                                   data=f'{str(e)}')
示例#11
0
 def delete(self, capitalcall_id):
     """Delete single capitalcall details"""
     try:
         capitalcall = CapitalCall.query \
             .filter_by(id=int(capitalcall_id)).first()
         if not capitalcall:
             return UTILS.api_response(
                 msg=UTILS.NOT_EXISTS(TYPE, capitalcall_id),
                 code=404,
             )
         else:
             UTILS.delete(capitalcall)
             return UTILS.api_response(msg=UTILS.DELETED(
                 TYPE, capitalcall.id),
                                       code=200)
     except ValueError as e:
         return UTILS.api_response(msg=f'{UTILS.VALUE_ERR} {self.__name__}',
                                   code=404,
                                   data=f'{str(e)}')
示例#12
0
 def delete(self, committment_id):
     """Delete single committment details"""
     try:
         committment = Committment.query \
             .filter_by(id=int(committment_id)).first()
         if not committment:
             return UTILS.api_response(
                 msg=UTILS.NOT_EXISTS(TYPE, committment_id),
                 code=404,
             )
         else:
             UTILS.delete(committment)
             return UTILS.api_response(msg=UTILS.DELETED(
                 TYPE, committment.id),
                                       code=200)
     except ValueError as e:
         return UTILS.api_response(msg=f'{UTILS.VALUE_ERR} {self.__name__}',
                                   code=404,
                                   data=f'{str(e)}')
示例#13
0
    def get(self):
        """Get all investments"""
        investments = Investment.query.all()
        stmt = select([FundInvestments])
        res = db.session.execute(stmt).fetchall()
        obj = [create_obj(r, investments) for r in res]

        return UTILS.api_response(msg=UTILS.SUCCESS(TYPE, "") if investments
                                  else UTILS.NO_SUCCESS(TYPE, ""),
                                  code=200 if investments else 404,
                                  data={'fundinvestments': obj})
示例#14
0
 def post(self):
     post_data = request.get_json()
     if not post_data:
         return UTILS.api_response(msg=UTILS.INVALID_PAYLD,
                                   code=400,
                                   data=self.__name__)
     fund_id = post_data.get('fund_id')
     amount = post_data.get('amount')
     try:
         committment = UTILS.add_committment(fund_id, amount)
         return UTILS.api_response(msg=UTILS.ADDED(
             TYPE, f'{committment.id} in fund {fund_id}'),
                                   code=201,
                                   data=committment.to_json())
     except exc.IntegrityError as e:
         db.session.rollback()
         return UTILS.api_response(
             msg=f'{UTILS.INTEGRITY_ERR} {self.__name__}',
             code=400,
             data=f'{str(e)}')
示例#15
0
 def get(self, investment_id):
     """Get single investment details"""
     try:
         inv = Investment.query.filter_by(id=int(investment_id)).first()
         stmt = FundInvestments.select().where(
             FundInvestments.c.fundinvestment_id == int(investment_id))
         res = db.session.execute(stmt).fetchall()
         obj = [create_obj(r, [inv]) for r in res][0]
         if not inv:
             return UTILS.api_response(
                 msg=UTILS.NOT_EXISTS(TYPE, investment_id),
                 code=404,
             )
         else:
             return UTILS.api_response(msg=UTILS.SUCCESS(TYPE, inv.id),
                                       code=200,
                                       data=obj)
     except ValueError as e:
         return UTILS.api_response(msg=f'{UTILS.VALUE_ERR} {self.__name__}',
                                   code=404,
                                   data=f'{str(e)}')
示例#16
0
 def put(self, committment_id):
     """Update single committment details"""
     put_data = request.get_json()
     if not put_data:
         return UTILS.api_response(msg=UTILS.INVALID_PAYLD, code=400)
     fund_id = put_data.get('fund_id')
     amount = put_data.get("amount")
     try:
         c = Committment.query.get(committment_id)
         if c:
             if (fund_id and (fund_id == c.fund_id)) or \
                (amount and (amount == c.amount)):
                 return UTILS.api_response(
                     msg=UTILS.NO_CHANGE(TYPE,
                                         f'{c.id} in fund {c.fund_id}'),
                     code=400,
                     data=c.query.get(committment_id).to_json())
             if fund_id:
                 c = UTILS.update(c, 'fund_id', int(fund_id))
             if amount:
                 c = UTILS.update(c, 'amount', int(amount))
             return UTILS.api_response(msg=UTILS.UPDATED(
                 TYPE, f'{c.id} in fund {c.fund_id}'),
                                       code=200,
                                       data=c.to_json())
         else:
             return UTILS.api_response(
                 msg=UTILS.NOT_EXISTS(TYPE, committment_id),
                 code=404,
             )
     except exc.IntegrityError as e:
         db.session.rollback()
         return UTILS.api_response(
             msg=f'{UTILS.INTEGRITY_ERR} {self.__name__}',
             code=400,
             data=f'{str(e)}')
示例#17
0
    def post(self):
        post_data = request.get_json()
        if not post_data:
            return UTILS.api_response(msg=UTILS.INVALID_PAYLD,
                                      code=400,
                                      data=self.__name__)
        call_id = post_data.get('call_id')
        rule = post_data.get('rule')
        try:
            call = CapitalCall.query.filter_by(id=int(call_id)).first()
            committments = []
            if rule == 'fifo':
                committments = Committment.query \
                    .order_by(asc(Committment.date)).all()
            committments_used = logic(call, committments)
            fundinvestments = []
            for amount, committment in committments_used:
                fi = UTILS.add_fundinvestment(amount, committment, call)
                fundinvestments.append({
                    'fund_id': committment.fund_id,
                    'committment_id': committment.id,
                    'capitalcall_id': call.id,
                    'fundinvestment_id': fi.id,
                    'investment': fi.investment
                })

            return UTILS.api_response(
                msg=UTILS.ADDED(TYPE, f'for Capital Call ID {call.id}'),
                code=201,
                data={'fundinvestments': [fi for fi in fundinvestments]})
        except exc.IntegrityError as e:
            db.session.rollback()
            return UTILS.api_response(
                msg=f'{UTILS.INTEGRITY_ERR} {self.__name__}',
                code=400,
                data=f'{str(e)}')
示例#18
0
 def post(self):
     post_data = request.get_json()
     if not post_data:
         return UTILS.api_response(msg=UTILS.INVALID_PAYLD,
                                   code=400,
                                   data=self.__name__)
     name = post_data.get('name')
     try:
         fund = Fund.query.filter_by(name=name).first()
         if not fund:
             fund = UTILS.add_fund(name)
             return UTILS.api_response(msg=UTILS.ADDED(TYPE, name),
                                       code=201,
                                       data=fund.to_json())
         else:
             return UTILS.api_response(msg=UTILS.EXISTS(TYPE, name),
                                       code=400,
                                       data=fund.to_json())
     except exc.IntegrityError as e:
         db.session.rollback()
         return UTILS.api_response(
             msg=f'{UTILS.INTEGRITY_ERR} {self.__name__}',
             code=400,
             data=f'{str(e)}')
示例#19
0
 def put(self, capitalcall_id):
     put_data = request.get_json()
     if not put_data:
         return UTILS.api_response(msg=UTILS.INVALID_PAYLD, code=400)
     name = put_data.get('name')
     capital = put_data.get('capital')
     try:
         call = CapitalCall.query.get(capitalcall_id)
         existingCalls = CapitalCall.query \
             .filter_by(name=name).first()
         if existingCalls:
             return UTILS.api_response(msg=UTILS.EXISTS(TYPE, name),
                                       code=400,
                                       data=existingCalls.to_json())
         if call:
             if (capital and (capital == call.capital)):
                 return UTILS.api_response(msg=UTILS.NO_CHANGE(
                     TYPE, f'{call.name}'),
                                           code=400,
                                           data=call.to_json())
             if name:
                 call = UTILS.update(call, 'name', name)
             if capital:
                 call = UTILS.update(call, 'capital', capital)
             return UTILS.api_response(
                 msg=UTILS.UPDATED(TYPE, name),
                 code=200,
                 data=CapitalCall.query.get(capitalcall_id).to_json())
         else:
             return UTILS.api_response(
                 msg=UTILS.NOT_EXISTS(TYPE, capitalcall_id),
                 code=404,
             )
     except exc.IntegrityError as e:
         db.session.rollback()
         return UTILS.api_response(
             msg=f'{UTILS.INTEGRITY_ERR} {self.__name__}',
             code=400,
             data=f'{str(e)}')
示例#20
0
 def get(self):
     return UTILS.api_response(msg=UTILS.PING_SUCCESS,
                               code=200,
                               data=self.__name__)