コード例 #1
0
ファイル: store.py プロジェクト: minikiller/REST_API_Flask
    def post(self, product):
        product = StoreModel.find_by_product(product)
        if product:
            return {'message': 'Product already in database!'}
        else:
            parser = reqparse.RequestParser()
            parser.add_argument('product',
                                type=str,
                                required=True,
                                help='This field is mandatory!')
            parser.add_argument('price',
                                type=float,
                                required=True,
                                help='This field is mandatory!')

            data_payload = parser.parse_args()

            StoreModel.add_product(data_payload['product'],
                                   data_payload['price'])
            return {'message': 'Product successfully added to database!'}, 201