예제 #1
0
파일: views.py 프로젝트: chuichin/foodapp
def approved_bookings():
    # Returns approved orders by Chef
    if get_jwt_header()['type'] == "Chef":
        current_chef = Chef.get_or_none(Chef.username == get_jwt_identity())
        bookings = Booking.select().where(Booking.chef_id == current_chef.id,
                                          Booking.active == True,
                                          Booking.confirmed == True)
        if bookings:
            return jsonify({
                "count":
                bookings.count(),
                "results": [
                    {
                        # not complete information
                        "booking_id": booking.id,
                        "user_id": booking.user_id,
                        "chef_id": booking.chef_id,
                        "price": booking.price,
                        "proposed_date": booking.proposed_date,
                        "booking_completed": booking.completed,
                        "booking_confirmed": booking.confirmed,
                        "booking_active": booking.active,
                    } for booking in bookings
                ]
            })
        else:
            return jsonify({
                "message": "There are no confirmed bookings for this chef",
                "status": "Failed"
            }), 400
    # Returns confirmed bookings for User
    else:
        current_user = User.get_or_none(User.username == get_jwt_identity())
        bookings = Booking.select().where(Booking.user_id == current_user.id,
                                          Booking.active == True,
                                          Booking.confirmed == True)
        if bookings:
            return jsonify({
                "count":
                bookings.count(),
                "results": [
                    {
                        # not complete information
                        "booking_id": booking.id,
                        "user_id": booking.user_id,
                        "chef_id": booking.chef_id,
                        "price": booking.price,
                        "proposed_date": booking.proposed_date,
                        "booking_completed": booking.completed,
                        "booking_confirmed": booking.confirmed,
                        "booking_active": booking.active,
                    } for booking in bookings
                ]
            })
        else:
            return jsonify({
                "message": "There are no confirmed bookings for this user",
                "status": "Failed"
            }), 400
예제 #2
0
def book():
    data = {}
    name = request.form['name']
    mobile = request.form['mobile']
    date_input = request.form['date']
    time = request.form['time']
    timestamp = date_input +  " " + time
    datetimeformat = dt.datetime.strptime(timestamp, '%d-%m-%Y %I:%M %p') 

    user = User.get_or_none(User.mobile_num == mobile)
    bookSlotValidate = Booking.select().where(Booking.booking_time == datetimeformat)
    if len(bookSlotValidate) > 0:
        slot_booked = check_slot_available(datetimeformat,[slot.booking_time for slot in bookSlotValidate])
        if slot_booked == 0:
            res = make_response(jsonify('Slot was Booked by Other user'),422)
            return res
        
    booking = Booking(booking_time = datetimeformat, user = user , slot =1 )
    booking.save()
       
    data['name'] = name
    data['mobile'] = mobile
    data['booking_time'] = datetimeformat
    # return redirect('users/new.html')
    res = make_response(jsonify(data),200)
    return res
예제 #3
0
def timeslot():
    data = {}
    dateinput = request.form['dateSend']
    start_time = dt.datetime.combine(dt.datetime.strptime(dateinput,'%d-%m-%Y'), time(9,0))
    bookedslot = Booking.select().where((Booking.booking_time >= start_time) &
                                        (Booking.booking_time <= start_time+timedelta(hours=10))
                                        ).order_by(Booking.booking_time)
    booking_list = [value.booking_time for value in bookedslot]
    data['timeslot'] = [{'time': (start_time+timedelta(minutes=i*30)).strftime('%I:%M %p') , 
                         'slot_available':check_slot_available(start_time+timedelta(minutes=i*30),booking_list)} for i in range (0,19) ] 
    data['date'] = dateinput
    # Simulate Loading Graphic.. put some delay.
    ti.sleep(0.1);
    return make_response(jsonify(data),200)
예제 #4
0
def user_bookings():
    existing_user = User.get_or_none(User.email == get_jwt_identity())
    if existing_user:
        all_bookings = Booking.select().where(Booking.user == existing_user.id)
        if all_bookings:
            booking = {
                "status": "success",
                "count": all_bookings.count(),
                "results": [{
                    "booking_id": booking.id,
                    "user": booking.user_id,
                    "chef": booking.chef_id,
                    "address": booking.address,
                    "service_type": booking.service_type,
                    "pax": booking.pax,
                    "meal_type": booking.meal_type,
                    "menu_type": booking.menu_type,
                    "hob_type": booking.hob_type,
                    "no_of_hob": booking.no_of_hob,
                    "oven": booking.oven,
                    "price": booking.price,
                    "diet_restrictions": booking.diet_restrictions, 
                    "proposed_date": booking.proposed_date,
                    "message": booking.message,
                    "completed": booking.completed,
                    "payment_status": booking.payment_status,
                    "confirmed": booking.confirmed,
                    "active": booking.active,
                    "cancelled": booking.cancelled
                } for booking in all_bookings]
            }
            return jsonify(booking), 200
        else:
            return jsonify({"results": []}), 200
    else:
        return jsonify({
            "message": "This user does not not exist",
            "status": "failed"
        }), 400