Reindex subsequent quotes on deletion

master
Nikola Forró 6 years ago
parent 85046a0f75
commit 605073ba23

@ -112,3 +112,5 @@ DELETE /quotes/:id
```BASH ```BASH
curl --request DELETE --header 'X-Quotes-API-Key: $API_KEY' 'https://ladylilia.com/quotes/api/quotes/666' curl --request DELETE --header 'X-Quotes-API-Key: $API_KEY' 'https://ladylilia.com/quotes/api/quotes/666'
``` ```
*Note: all subsequent quotes are reindexed*

@ -109,6 +109,10 @@ class QuoteResource(flask_restful.Resource):
flask_restful.abort(404, message='Quote {0} does not exist'.format(id)) flask_restful.abort(404, message='Quote {0} does not exist'.format(id))
db.session.delete(quote) db.session.delete(quote)
db.session.commit() db.session.commit()
q = db.session.query(Quote).filter(Quote.id > id)
for quote in q.all():
quote.id -= 1
db.session.commit()
return None, 204 return None, 204

Loading…
Cancel
Save