diff --git a/chatbot/api/v2/api.py b/chatbot/api/v2/api.py index 4f6fc7e..419e0c2 100644 --- a/chatbot/api/v2/api.py +++ b/chatbot/api/v2/api.py @@ -25,7 +25,7 @@ }) conflict_model = api.model('Conflict', { - 'conflict_id': fields.String(description='Document ID for conflict'), + 'id': fields.String(description='Document ID for conflict'), 'title': fields.String(description='Title of conflict content') }) @@ -87,14 +87,14 @@ class ConflictIDs(Resource): @api.marshal_with(conflict_model) def get(self): conflict_ids = factory.get_collection(conflict_col).find() - return [models.Conflict(conflict['conflict_id'], conflict['title']) + return [models.Conflict(conflict['id'], conflict['title']) for conflict in conflict_ids] @api.marshal_with(delete_model) @api.response(200, 'Success', delete_model) @api.response(404, 'Conflict not found') def delete(self, conflict_id): - result = factory.delete_document({"conflict_id": conflict_id}, + result = factory.delete_document({'id': conflict_id}, conflict_col) if result.deleted_count > 0: return result @@ -146,6 +146,9 @@ def delete(self, content_id): factory.update_document(query, {'manually_changed': False}, manual_col) factory.update_document(query, {'manually_changed': False}, prod_col) + # Delete conflict if there was one + factory.delete_document({'id': content_id}, conflict_col) + if result.deleted_count > 0: return result else: @@ -193,7 +196,7 @@ def put(self, content_id): .update(*index) # delete this document from the conflict collection - query = {"conflict_id": content_id} + query = {'id': content_id} factory.get_database().get_collection(conflict_col).delete_one(query) if new_document['updatedExisting']: diff --git a/chatbot/api/v2/models.py b/chatbot/api/v2/models.py index a40f690..c621526 100644 --- a/chatbot/api/v2/models.py +++ b/chatbot/api/v2/models.py @@ -20,7 +20,7 @@ def __init__(self, user_input='', response_format='plain'): class Conflict(object): def __init__(self, conflict_id, title): - self.conflict_id = conflict_id + self.id = conflict_id self.title = title diff --git a/chatbot/api/v2/test/test_v2_api.py b/chatbot/api/v2/test/test_v2_api.py index d62d9a0..4a17c1b 100644 --- a/chatbot/api/v2/test/test_v2_api.py +++ b/chatbot/api/v2/test/test_v2_api.py @@ -38,7 +38,7 @@ def test_response(client): def test_get_conflict_ids(client): # Setup two conflicts - conflicts = [{"conflict_id": "test_conflict_id_{}".format(i), + conflicts = [{"id": "test_conflict_id_{}".format(i), "title": "test_conflict_title_{}".format(i)} for i in range(2)] @@ -50,25 +50,26 @@ def test_get_conflict_ids(client): response_data = json.loads(response.data.decode()) for conflict in conflicts: - assert conflict['conflict_id'] in [response['conflict_id'] - for response in response_data] + assert conflict['id'] in [response['id'] + for response in response_data] finally: for conflict in conflicts: - factory.delete_document({'conflict_id': conflict['conflict_id']}, + factory.delete_document({'id': conflict['id']}, conflict_col) def test_delete_conflict_ids(client): - conflict = {'conflict_id': 'test conflict id', + conflict = {'id': 'test conflict id', 'title': 'test title'} factory.post_document(conflict, conflict_col) try: - idx = conflict['conflict_id'] + idx = conflict['id'] response = client.delete('/v2/conflict_ids/{}/'.format(idx)) + print(response.data.decode()) assert json.loads(response.data.decode())['deleted_count'] > 0 finally: - factory.delete_document({'conflict_id': 'test conflict id'}, + factory.delete_document({'id': 'test conflict id'}, conflict_col) diff --git a/chatbot/api/wsgi.py b/chatbot/api/wsgi.py new file mode 100644 index 0000000..10d37a2 --- /dev/null +++ b/chatbot/api/wsgi.py @@ -0,0 +1,4 @@ +from chatbot.api.server import app + +if __name__ == '__main__': + app.run() diff --git a/chatbot/chat/index.html b/chatbot/chat/index.html index 4a88db9..59f9507 100644 --- a/chatbot/chat/index.html +++ b/chatbot/chat/index.html @@ -13,6 +13,8 @@
Hei! Jeg er en chatbot som svarer for Boligadministrasjonen. Hva kan jeg hjelpe deg med?
+Jeg forstår korte og konsise spørsmål best!
Denne boten er en del av et pilot-prosjekt. Alle spørsmål vil bli + lagret - det frarådes derfor å oppgi personlige eller sensitiv data.
+