Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete convictions and charges #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions server/core/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,22 @@ def update_client(client_id):

@core_bp.route('/clients/<int:client_id>', methods=['DELETE'])
def delete_client(client_id):
pass
client = models.Client.query.get(client_id)

if client is None:
return Response("Client with ID {}".format(client_id), status=404, mimetype='text/plain')

convictions = client.convictions

for conviction in convictions:
charges = conviction.charges
for charge in charges:
dbs.session.delete(charge)
dbs.session.delete(conviction)

dbs.session.delete(client)
dbs.session.commit()
return Response("Success", status=200, mimetype='text/plain')


@core_bp.route('/clients/<int:client_id>/convictions', methods=['GET'])
Expand Down Expand Up @@ -285,7 +300,17 @@ def update_conviction(conviction_id):
@core_bp.route('/convictions/<int:conviction_id>', methods=['DELETE'])
def delete_conviction(conviction_id):
conviction = models.Conviction.query.get(conviction_id)
pass

if conviction is None:
return Response("Could not find convictions with ID {}".format(conviction_id), status=404, mimetype='text/plain')

charges = conviction.charges
for charge in charges:
dbs.session.delete(charge)

dbs.session.delete(conviction)
dbs.session.commit()
return Response("Success", status=200, mimetype='text/plain')


@core_bp.route('/clients/<int:client_id>/convictions/<int:conviction_id>/charges', methods=['GET'])
Expand Down Expand Up @@ -379,4 +404,10 @@ def update_charge(charge_id):

@core_bp.route('/charges/<int:charge_id>', methods=['DELETE'])
def delete_charge(charge_id):
pass
charge = models.Charge.query.get(charge_id)
if charge is None:
return Response("Charge with ID {} not found".format(charge_id), status=404, mimetype='text/plain')

dbs.session.delete(charge)
dbs.session.commit()
return Response("Success", status=200, mimetype='text/plain')