utilityendpoints.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:Restaurant-API-V2 作者: RobusGauli 项目源码 文件源码
def setDineTable():
    '''This function is used to store the new DineTable in the database
        Example : POST /api/v1/dinetables HTTP/1.1
        { "capicity": 4, "alias" : "Table1", "status" : "empty"}

        Result : {
                    "meta": {
                    "code": 200,
                    "message": "Created Successfully"
                    }
                }
    '''
    with SessionManager(Session) as session:
        try:

            capacity = request.json['capacity']
            alias = request.json['alias']
            status = request.json.get('status', 'empty')
            dine_table = DineTable(capacity=capacity, alias=alias, status=status)
            session.add(dine_table)
            session.commit()
            return jsonify(post_envelop(200, data = request.json))

        except DataError: #this excepyion might probably occur if the value key has a value of non integer
            return jsonify(error_envelop(400, 'DataError', 'Use the correct value'))

        except IntegrityError:
            return jsonify(error_envelop(400, 'IntegrityError','Value : {0} already exists'.format(alias)))

        except:
            return jsonify(error_envelop(400,'UnknownError','Error need to be identified'))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号