Пример #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