예제 #1
0
    def get(self, received):
        order_id = received.get('order_id')
        serial_number_str = received.get('serial_number')

        result = list()
        if order_id:
            order = OrderModel.get_by_id(order_id=received.get('order_id'))
            if order:
                db_result = SerialNumberModel.find_by_order(order=order)
                for item in db_result:
                    result.append({
                        'serial_number': item.serial_number,
                        'menu_id': item.menu.id,
                        'order_id': item.order.id
                    })
            else:
                return {'message': 'order_id not found'}, 404
        elif serial_number_str:
            serial = SerialNumberModel.get_by_serial_number(
                serial_number=serial_number_str)

            if serial:
                logging.error(serial.order.customized_message)
                result = {
                    'serial_number': serial.serial_number,
                    'customized_message': serial.order.customized_message
                }
            else:
                return {'message': 'serial_number not found'}, 404
        else:
            return {'message': 'order or serial is required.'}, 400

        return result
예제 #2
0
    def get(self, order_id=None):
        if not order_id:
            return {'message': 'user not found'}, 404

        order = OrderModel.get_by_id(order_id)
        if order:
            if order.is_obsolete and order.id != 1:
                return {'message': 'order was obsoleted'}, 400
            else:
                menu_list = list()
                for menu in order.menus:
                    menu_list.append({
                        'menu_id': menu.menu.id,
                        'menu_name': menu.menu.name,
                        'coffee_option': menu.menu.coffee_option,
                        'taste_level': menu.menu.taste_level,
                        'water_level': menu.menu.water_level,
                        'foam_level': menu.menu.foam_level,
                        'grind_size': menu.menu.grind_size,
                        'menu_type': menu.menu.menu_type,
                        'counts': menu.counts
                    })
                return {
                    'order_id': order.id,
                    'order_contents': menu_list,
                    'order_date':
                    order.create_date.strftime("%Y-%m-%d %H:%M:%S")
                }
        else:
            return {'message': 'order not found'}, 404
예제 #3
0
    def patch(self, order_id=None):
        if not order_id:
            return {'message': 'order not found'}, 404

        order = OrderModel.get_by_id(order_id)
        if order:
            order.is_obsolete = True
            order.save_to_db()
            return {'order_id': order.id, 'is_obsoleted': order.is_obsolete}
        else:
            return {'message': 'user not found'}, 404