Skip to content

Commit

Permalink
better compliance with jsonapi relationship management responses
Browse files Browse the repository at this point in the history
  • Loading branch information
akira-dev committed May 11, 2018
1 parent ad0ad89 commit 0994495
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions flask_rest_jsonapi/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,22 +388,16 @@ def post(self, *args, **kwargs):
related_id_field,
kwargs)

qs = QSManager(request.args, self.schema)
includes = qs.include
if relationship_field not in qs.include:
includes.append(relationship_field)
schema = compute_schema(self.schema, dict(), qs, includes)
status_code = 200
result = {'meta': {'message': 'Relationship successfully created'}}

if updated is False:
return '', 204

result = schema.dump(obj_).data
if result.get('links', {}).get('self') is not None:
result['links']['self'] = request.path
result = ''
status_code = 204

self.after_post(result)

return result, 200
return result, status_code

@check_method_requirements
def patch(self, *args, **kwargs):
Expand Down Expand Up @@ -438,22 +432,16 @@ def patch(self, *args, **kwargs):
related_id_field,
kwargs)

qs = QSManager(request.args, self.schema)
includes = qs.include
if relationship_field not in qs.include:
includes.append(relationship_field)
schema = compute_schema(self.schema, dict(), qs, includes)
status_code = 200
result = {'meta': {'message': 'Relationship successfully updated'}}

if updated is False:
return '', 204

result = schema.dump(obj_).data
if result.get('links', {}).get('self') is not None:
result['links']['self'] = request.path
result = ''
status_code = 204

self.after_patch(result)

return result, 200
return result, status_code

@check_method_requirements
def delete(self, *args, **kwargs):
Expand Down Expand Up @@ -488,16 +476,12 @@ def delete(self, *args, **kwargs):
related_id_field,
kwargs)

qs = QSManager(request.args, self.schema)
includes = qs.include
if relationship_field not in qs.include:
includes.append(relationship_field)
schema = compute_schema(self.schema, dict(), qs, includes)

status_code = 200 if updated is True else 204
result = schema.dump(obj_).data
if result.get('links', {}).get('self') is not None:
result['links']['self'] = request.path
status_code = 200
result = {'meta': {'message': 'Relationship successfully updated'}}

if updated is False:
result = ''
status_code = 204

self.after_delete(result)

Expand Down

0 comments on commit 0994495

Please sign in to comment.