예제 #1
0
def get_product(product_id):
    mongoConnect = mongodb.MongoDb()
    db = mongoConnect.getClient().unga
    product = db.products.find_one({"_id": product_id})
    mongoConnect.getClient().close()

    return jsonify({'id': product['_id'], 'type': product['type'], 'description': product['description'],
                    'pictures': product['pictures'], 'created': ut.timeToStr(product['created']),'published' : product['published']})
예제 #2
0
def get_products():
    output = []
    mongoConnect = mongodb.MongoDb()
    db = mongoConnect.getClient().unga
    products = db.products.find()
    mongoConnect.getClient().close()

    for product in products:
        output.append({'id': product['_id'], 'type': product['type'], 'description': product['description'],
                    'pictures': product['pictures'], 'created': ut.timeToStr(product['created']),'published' : product['published']})
    return jsonify(output)
예제 #3
0
def get_user(uid):
    mongoConnect = mongodb.MongoDb()
    db = mongoConnect.getClient().unga
    user = db.users.find_one({"_id": uid})
    mongoConnect.getClient().close()

    return jsonify({
        'first_name': user['first_name'],
        'email': user['email'],
        'uid': user['_id']
    })
예제 #4
0
def add_user():
    #Need to check password_1 == password_2

    user = u.User(request.json['fname'], request.json['lname'],
                  request.json['email'],
                  generate_password_hash(request.json['password_1']))

    mongoConnect = mongodb.MongoDb()
    db = mongoConnect.getClient().unga
    db.users.insert(user.serialize())
    mongoConnect.getClient().close()

    return jsonify({"user": "******" + user.getUid() + " created"})
예제 #5
0
def verify_password(username, password):
    mongoConnect = mongodb.MongoDb()
    db = mongoConnect.getClient().unga
    user = db.users.find_one({'email': username})
    mongoConnect.getClient().close()

    if user:
        print(user['password'])
        if check_password_hash(user['password'], password):

            return True

    return False
예제 #6
0
def get_advert(advert_uuid):
    output = []
    mongoConnect = mongodb.MongoDb()
    db = mongoConnect.getClient().unga
    advert = db.adverts.find_one({"_id": advert_uuid})
    mongoConnect.getClient().close()

    return jsonify({
        'id': advert['_id'],
        'message': advert['message'],
        'created': ut.timeToStr(advert['created']),
        'published': advert['published']
    })
예제 #7
0
def get_adverts():
    adverts = []
    mongoConnect = mongodb.MongoDb()
    db = mongoConnect.getClient().unga
    ads = db.adverts.find()
    mongoConnect.getClient().close()

    for ad in ads:
        adverts.append({
            'id': ad['_id'],
            'message': ad['message'],
            'created': ut.timeToStr(ad['created']),
            'published': ad['published']
        })
    return jsonify(adverts)
예제 #8
0
def get_users():
    output = []
    mongoConnect = mongodb.MongoDb()
    db = mongoConnect.getClient().unga
    users = db.users.find()
    mongoConnect.getClient().close()

    for user in users:
        output.append({
            'href': user['uri'],
            'first_name': user['first_name'],
            'email': user['email'],
            'uid': user['_id']
        })

    return jsonify({'users': output})
예제 #9
0
def create_dummy_data():
    fake = Faker()
    dummy = []
    mongoConnect = mongodb.MongoDb()
    db = mongoConnect.getClient().unga

    for i in range(0, 5):
        advert = ad.Advert(fake.text())
        db.adverts.insert(advert.serialize())
        dummy.append(advert.serialize())

        user = u.User(fake.name(), data.dummyPasswords[i], fake.email(),
                      generate_password_hash(data.dummyPasswords[i]))
        db.users.insert(user.serialize())
        dummy.append(user.serialize())

        product = prod.Product(data.dummyRentalTypes[i], fake.text())
        db.products.insert(product.serialize())
        dummy.append(product.serialize())

    mongoConnect.getClient().close()
    return jsonify(dummy)