Beispiel #1
0
    def post(self):
        args = parser.parse_args()
        print(args)

        username = args.get('username')
        # find if username exists
        results = session.query(User).filter(User.username == username)

        if results.count() > 0:
            print('user already found')

            raise BadRequest()
            return {'response': 'failure', 'reason': 'User already exists'}
        else:
            print('user not found, creating new account')

            password = args.get('password')
            pwd_hash = bcrypt.generate_password_hash(password)

            user = User(fname=args.get('fname'), lname=args.get(
                'lname'), username=username, password=pwd_hash, email=args.get('email'))
            session.add(user)
            session.commit()

            return {'response': 'success'}
    def post(self):
        args = CreateReview.parser.parse_args()

        review = Review(revOfferId=args.get('revOfferId'), score=args.get('score'),
                          description=args.get('description'))
        session.add(review)
        session.commit()

        return {'response': 'success'}
    def post(self):
        args = CreateRequest.parser.parse_args()

        request = Request(user_email=args.get('user_email'), quantity=args.get('quantity'),
                          urgency=args.get('urgency'), item=args.get('item'), is_surplus=args.get('is_surplus'))
        session.add(request)
        session.commit()

        return {'response': 'success'}
Beispiel #4
0
    def post(self):
        args = CreateOffer.parser.parse_args()
        offer = Offer(user_email=args.get('user_email'),
                      quantity=args.get('quantity'),
                      requestId=args.get('requestId'),
                      price=args.get('price'),
                      willing_to_transport=args.get('willing_to_transport'),
                      image=args.get('image'))
        session.add(offer)
        session.commit()

        return {'response': 'success'}
Beispiel #5
0
    def post(self):
        args = SetConfirmed.parser.parse_args()
        session.query(Offer).filter(
            Offer.offerId == args.get('offerId')).update(
                {'isConfirmed': args.get('confirm')})
        session.query(Offer).filter(
            Offer.offerId == args.get('offerId')).update({'isPending': False})

        offer = session.query(Offer).filter(
            Offer.offerId == args.get('offerId')).first()
        offer_request = session.query(Request).filter(
            Request.requestId == offer.requestId).first()
        if offer_request.quantity < offer.quantity:
            session.query(Request).filter(Request.requestId == offer.requestId).\
                update({'quantity': offer_request.quantity - offer.quantity})
        else:
            session.query(Request).filter(Request.requestId == offer.requestId). \
                update({'fulfilled': True})

        session.commit()

        return {'response': 'success'}
    def post(self):
        args = SetFulfilled.parser.parse_args()
        request = session.query(Request).filter(Request.requestId == args.get('requestId')).update({'fulfilled': True})
        session.commit()

        return {'response': 'success'}