Skip to content

Commit de40a40

Browse files
patch(endpoints): fix if-statement in tag post route for 24 files
1 parent e601a2c commit de40a40

File tree

23 files changed

+23
-24
lines changed
  • docs/docs
    • 07_sqlalchemy_many_to_many
    • 08_flask_jwt_extended
      • 04_flask_jwt_extended_setup
      • 05_user_model_and_schema
      • 06_registering_users_rest_api
      • 07_login_users_rest_api
      • 08_protect_resources_with_jwt_required
      • 09_jwt_claims_and_authorization
      • 10_logout_users_rest_api
      • 12_token_refreshing_flask_jwt_extended
  • project
    • 05-add-many-to-many/resources
    • 06-add-db-migrations/resources

23 files changed

+23
-24
lines changed

docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class TagsInStore(MethodView):
117117
@blp.arguments(TagSchema)
118118
@blp.response(201, TagSchema)
119119
def post(self, tag_data, store_id):
120-
if TagModel.query.filter(TagModel.store_id == store_id).first():
120+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
121121
abort(400, message="A tag with that name already exists in that store.")
122122

123123
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/07_sqlalchemy_many_to_many/02_one_to_many_review/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class TagsInStore(MethodView):
190190
@blp.arguments(TagSchema)
191191
@blp.response(201, TagSchema)
192192
def post(self, tag_data, store_id):
193-
if TagModel.query.filter(TagModel.store_id == store_id).first():
193+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
194194
abort(400, message="A tag with that name already exists in that store.")
195195

196196
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/07_sqlalchemy_many_to_many/03_many_to_many_relationships/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/04_flask_jwt_extended_setup/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/05_user_model_and_schema/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/05_user_model_and_schema/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/06_registering_users_rest_api/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/07_login_users_rest_api/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/07_login_users_rest_api/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/end/resources/tag.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
25-
2625
tag = TagModel(**tag_data, store_id=store_id)
2726

2827
try:

docs/docs/08_flask_jwt_extended/08_protect_resources_with_jwt_required/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/09_jwt_claims_and_authorization/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/10_logout_users_rest_api/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/end/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

docs/docs/08_flask_jwt_extended/12_token_refreshing_flask_jwt_extended/start/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

project/05-add-many-to-many/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

project/06-add-db-migrations/resources/tag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get(self, store_id):
2020
@blp.arguments(TagSchema)
2121
@blp.response(201, TagSchema)
2222
def post(self, tag_data, store_id):
23-
if TagModel.query.filter(TagModel.store_id == store_id).first():
23+
if TagModel.query.filter(TagModel.store_id == store_id, TagModel.name == tag_data["name"]).first():
2424
abort(400, message="A tag with that name already exists in that store.")
2525

2626
tag = TagModel(**tag_data, store_id=store_id)

0 commit comments

Comments
 (0)