Exemplo n.º 1
0
    def post(self):
        json_data = request.get_json()

        current_worker = get_jwt_identity()

        sale = Sale(name=json_data['name'],
                    description=json_data['description'],
                    date_of_sale=json_data['date_of_sale'],
                    sale_amount=json_data['sale_amount'],
                    who_sold=json_data['who_sold'],
                    worker_id=current_worker)

        sale.save()

        return sale.data(), HTTPStatus.CREATED
Exemplo n.º 2
0
def retrieveSales(watches):
    headers = {
        'user-agent':
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
        'referrer': 'https://google.com',
        'Accept':
        'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'en-US,en;q=0.9',
        'Pragma': 'no-cache',
    }
    sales = []

    for watch in watches:
        response = json.loads(requests.get(watch.link, headers=headers).text)
        print(watch)
        print(response)

        count = 0
        for sale in response:
            temp = Sale(watch.brand, watch.model, watch.version,
                        sale["amount"], sale["createdAt"], utils.CURRENCY_USD)
            print(temp)
            sales.append(temp)
            count += 1
        print(str(count))

    return sales
Exemplo n.º 3
0
    def get(self):

        sales = Sale.get_all_published()

        data = []

        for sale in sales:
            data.append(sale.data())

        return {'data': data}, HTTPStatus.OK
Exemplo n.º 4
0
    def get(self, sale_id):

        sale = Sale.get_by_id(sale_id=sale_id)

        if sale is None:
            return {'message': 'Sale not found'}, HTTPStatus.NOT_FOUND

        current_worker = get_jwt_identity()

        if sale.is_publish == False and sale.worker_id != current_worker:
            return {'message': 'Access is not allowed'}, HTTPStatus.FORBIDDEN

        return sale.data(), HTTPStatus.OK
Exemplo n.º 5
0
    def delete(self, sale_id):

        sale = Sale.get_by_id(sale_id=sale_id)

        if sale is None:
            return {'message': 'Sale not found'}, HTTPStatus.NOT_FOUND

        current_user = get_jwt_identity()

        if current_user != sale.user_id:
            return {'message': 'Access is not allowed'}, HTTPStatus.FORBIDDEN

        sale.delete()

        return {}, HTTPStatus.NO_CONTENT
Exemplo n.º 6
0
    def put(self, sale_id):

        json_data = request.get_json()

        sale = Sale.get_by_id(sale_id=sale_id)

        if sale is None:
            return {'message': 'Recipe not found'}, HTTPStatus.NOT_FOUND

        current_user = get_jwt_identity()

        if current_user != sale.user_id:
            return {'message': 'Access is not allowed'}, HTTPStatus.FORBIDDEN

        sale.name = json_data['name']
        sale.description = json_data['description']
        sale.date_of_sale = json_data['date_of_sale']
        sale.sale_amount = json_data['sale_amount']
        sale.who_sold = json_data['who_sold']

        sale.save()

        return sale.data(), HTTPStatus.OK
Exemplo n.º 7
0
from app import app, db
from models.business import Business
from models.category import Category
from models.customer import Customer
from models.sale import Sale

with app.app_context():
    db.drop_all()
    db.create_all()

test_business = Business(name='testing1', type='type1')
db.session.add(test_business)
db.session.commit()

test_category = Category(type='type')
db.session.add(test_category)

test_sale = Sale(title='title1',
                 content='content1',
                 business=test_business,
                 category=test_category)
db.session.add(test_sale)

test_customer = Customer(name='name1',
                         phone='phone1',
                         email='email1',
                         catagories=[test_category])
db.session.add(test_customer)

db.session.commit()
Exemplo n.º 8
0
    'lng': '-0.08771913159182532',
    'phone_number': '+447 123454322',
    'categories': [{
        'id': 2
    }],
    'is_merchant': 'False'
})
if errors:
    raise Exception(errors)

test_user100.save()

flash_sale_1 = Sale(
    user=joe_and_the_juice,
    title='Half price coffee',
    expiry_date='2019-05-01 9:22:54',
    content=
    'For three hours only, we will be serving the best coffee for half price',
    category=coffee)

flash_sale_1.save()

flash_sale_2 = Sale(
    user=zara,
    title='Winter collection 50% Off',
    expiry_date='2019-03-03 18:25:27',
    content=
    'Come and enjoy the latest winter collection at a ridiculous price!!! ',
    category=womens_clothes)

flash_sale_2.save()