示例#1
0
def find():
    user_id = get_jwt_identity()
    history = History.select().where(History.user_id == user_id).order_by(History.id.desc())
    
    if history: 
        latest = history[0]
        responseObj = {
            'status': 'success',
            'mall': Mall.get_by_id(Floor.get_by_id(Parking.get_by_id(latest.parking_id).floor_id).mall_id).outlet,
            'floor': Floor.get_by_id(Parking.get_by_id(latest.parking_id).floor_id).floor,
            'parking': Parking.get_by_id(latest.parking_id).parking_num,
            'date': latest.created_at.strftime('%A %d %b %Y'),
            'time': latest.created_at.strftime('%X %p'),
            'id': latest.id
        }

        return jsonify(responseObj), 200

    else: 
        responseObj = {
            'status': 'success',
            'message': 'No parking information!',
            'mall': 'N/A',
            'floor': 'N/A',
            'parking': 'N/A',
            'date': 'N/A',
            'time': 'N/A',
            'id': 'N/A'
        }

        return jsonify(responseObj), 200
示例#2
0
def history(): 
    user_id = get_jwt_identity()
    current_user = User.get_by_id(user_id)
    history_obj = History.select().where(History.user_id == current_user.id).order_by(History.id.desc())
    history_arr = []

    if history_obj: 
        for history in history_obj: 
            history_list = {
                'mall': Mall.get_by_id(Floor.get_by_id(Parking.get_by_id(history.parking_id).floor_id).mall_id).outlet,
                'floor': Floor.get_by_id(Parking.get_by_id(history.parking_id).floor_id).floor,
                'parking': Parking.get_by_id(history.parking_id).parking_num,
                'date': history.created_at.strftime('%A %d %b %Y'),
                'time': history.created_at.strftime('%X %p'),
                'id': history.id
            }
            history_arr.append(history_list)

        responseObj = {
            'status': 'success',
            'history': history_arr
        }

        return jsonify(responseObj), 200

    else: 
        responseObj = {
            'status': 'success',
            'history': history_arr
        }
        
        return jsonify(responseObj), 200
示例#3
0
def history_delete(id):
    user_id = get_jwt_identity()
    history = History.get_by_id(id)
    if history.delete_instance():
        history_obj = History.select().where(History.user_id == user_id)
        history_arr = []
        if history_obj: 
            for history in history_obj: 
                history_list = {
                    'mall': Mall.get_by_id(Floor.get_by_id(Parking.get_by_id(history.parking_id).floor_id).mall_id).outlet,
                    'floor': Floor.get_by_id(Parking.get_by_id(history.parking_id).floor_id).floor,
                    'parking': Parking.get_by_id(history.parking_id).parking_num,
                    'date': history.created_at.strftime('%A %d %b %Y'),
                    'time': history.created_at.strftime('%X %p'),
                    'id': history.id
                }
                history_arr.append(history_list)

        responseObj= {
            'status': 'success',
            'message': 'Successfully deleted parking history!',
            'history': history_arr 
        }

        return jsonify(responseObj), 200

    else: 
        responseObj = {
            'status': 'failed',
            'message': 'Failed to delete history!'
        
        }

        return jsonify(responseObj), 400
示例#4
0
def history_add():
    user_id = get_jwt_identity()
    user_inst = User.get_by_id(user_id)
    parking_id = request.json.get('parking_id')
    parking_inst = Parking.get_by_id(parking_id)
    floor_inst = Floor.get_by_id(parking_inst.floor_id) 
    mall_inst = Mall.get_by_id(floor_inst.mall_id)
    history_inst = History(user_id = user_id, parking_id = parking_id)

    if history_inst.save():
        responseData = client.send_message({
            'from': 'Nexmo',
            'to': user_inst.hp_number, 
            'text': 'RM0.00 EzPark: Your car is parked in Mall: [' + mall_inst.outlet + '], at Floor: [' + floor_inst.floor +  '], in Parking Bay: [' + parking_inst.parking_num + ']///'
        })

        # if responseData["messages"][0]["status"] == "0":
        responseObj = {
            'status': 'success',
            'message': 'Successfully saved your parking!'
        }
        return jsonify(responseObj), 200
        # else: 
        #     responseObj = {
        #         'status': 'failed',
        #         'message': 'Message sent failed'
        #     }
        #     return jsonify(responseObj), 400

    else: 
        responseObj = {
                'status': 'failed',
                'message': 'Parking failed to save!'
        }

        return jsonify(responseObj), 400