コード例 #1
0
    def post(self, storename):
        storename = storename.lower()
        if StoreModel.find_by_name(storename=storename):
            return {
                "message": f"A store with name {storename} already exists"
            }, 400

        data = Store.parser.parse_args()
        message = StoreModel.check_form_integrity(storename=storename,
                                                  data=data)
        if message: return message

        store = StoreModel(**data)
        try:
            store.save_to_db()
        except Exception as e:
            print(e)
            return {
                "message": "An error occured while creating the store."
            }, 500

        return store.json(), 201