Пример #1
0
def show(listing_id):
    schema = ListingSchema()
    listing = Listing.get(id=listing_id)

    if not listing:
        abort(404)

    return schema.dumps(listing)
Пример #2
0
def delete(listing_id):
    listing = Listing.get(id=listing_id)

    if not listing:
        abort(404)

    listing.delete()
    db.commit()

    return '', 204
Пример #3
0
 def __init__(self):
     listing_id_1 = "listing_1"
     self.listings = {
         listing_id_1: Listing(listing_id_1, "open", user_1_id, SKU_ACCOMMODATION_ID, SKU_ACCOMMODATION, 30000,
                               40000,
                               1619715600000,
                               1619820000000,
                               [
                                   Bid("bid_id_1", listing_id_1, user_2_id, 31000, 1619794800000),
                                   Bid("bid_id_2", listing_id_1, user_3_id, 32000, 1619791200000)
                               ])
     }
Пример #4
0
def create():
    schema = ListingSchema()

    try:
        data = schema.load(request.get_json())
        data['user'] = g.current_user
        listing = Listing(**data)
        db.commit()

    except ValidationError as err:
        return jsonify({'message': 'Validation failed', 'errors': err.messages}), 422

    return schema.dumps(listing), 201
Пример #5
0
def update(listing_id):
    schema = ListingSchema()
    listing = Listing.get(id=listing_id)

    if not listing:
        abort(404)

    try:
        data = schema.load(request.get_json())
        listing.set(**data)
        db.commit()

    except ValidationError as err:
        return jsonify({'message': 'Validation failed', 'errors': err.messages}), 422

    return schema.dumps(listing)
Пример #6
0
def create_listing(listingRepository: ListingRepository):
    abort_if_body_not_found()

    body = request.json
    new_listing = Listing(str(uuid.uuid1()),
                          "open",
                          body['creator_id'],
                          body['sku_id'],
                          body['sku'],
                          body['min_price'],
                          body['max_price'],
                          body['created_time'],
                          body['expiration_time'],
                          bids=[])
    listingRepository.add_listing(new_listing)
    return jsonify({new_listing.listing_id: new_listing})
Пример #7
0
    garden = Category(name='Garden')
    furniture = Category(name='Furniture')
    clothing = Category(name='Clothing')
    electrical = Category(name='Electrical')
    bags = Category(name='Bags')
    pets = Category(name='Pets')
    books = Category(name='Books')
    bicycles = Category(name='Bicycles')
    kitchen = Category(name='Kitchen')

    flower_vase = Listing(
        title='Flower vase',
        image=
        'https://images.unsplash.com/photo-1490312278390-ab64016e0aa9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80',
        description=
        'A vase made from an old water bottle and painted white.\n Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Aliquet sagittis id consectetur purus ut. Justo eget magna fermentum iaculis. Metus dictum at tempor commodo ullamcorper a lacus vestibulum. Odio tempor orci dapibus ultrices in iaculis nunc. Euismod elementum nisi quis eleifend quam adipiscing vitae proin sagittis. Adipiscing at in tellus integer feugiat scelerisque varius. Fermentum dui faucibus in ornare quam. Pharetra vel turpis nunc eget lorem dolor sed viverra ipsum. Tellus id interdum velit laoreet id donec. Justo eget magna fermentum iaculis eu non diam phasellus vestibulum. At elementum eu facilisis sed odio morbi quis commodo',
        price=10.00,
        postage=3.51,
        num_available=10,
        categories=[household],
        user=user1)

    armchairs = Listing(
        title='Two modern style armchairs',
        image=
        'https://images.unsplash.com/photo-1493150134366-cacb0bdc03fe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2850&q=80',
        description=
        'Two 1960s armchairs reupholstered in a modern yellow fabric. Perfect for any living room.A vase made from an old water bottle and painted white.\n Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Aliquet sagittis id consectetur purus ut. Justo eget magna fermentum iaculis. Metus dictum at tempor commodo ullamcorper a lacus vestibulum. Odio tempor orci dapibus ultrices in iaculis nunc. Euismod elementum nisi quis eleifend quam adipiscing vitae proin sagittis. Adipiscing at in tellus integer feugiat scelerisque varius. Fermentum dui faucibus in ornare quam. Pharetra vel turpis nunc eget lorem dolor sed viverra ipsum. Tellus id interdum velit laoreet id donec. Justo eget magna fermentum iaculis eu non diam phasellus vestibulum.',
        price=60.00,
        postage=20.00,
        num_available=1,
Пример #8
0
def index():
    schema = ListingSchema(many=True)
    listings = Listing.select()
    return schema.dumps(listings)
Пример #9
0
    def load_item(self, data):
        data['item'] = Listing.get(id=data['item_id'])
        del data['item_id']

        return data