From f7e39e1cc3b80166d53f7f732fc08893351a8396 Mon Sep 17 00:00:00 2001 From: herman dyrkorn <herman.dyrkorn@gmail.com> Date: Thu, 29 Apr 2021 12:04:45 +0200 Subject: [PATCH] returns for matched salamanders when edited --- api/endpoints/salamanderclass.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/api/endpoints/salamanderclass.py b/api/endpoints/salamanderclass.py index 15893b7..98579f4 100644 --- a/api/endpoints/salamanderclass.py +++ b/api/endpoints/salamanderclass.py @@ -109,7 +109,7 @@ class SalamanderClass(Resource): else: add_salamander(salamander.id, image_id, data['new_location'], data['new_species'], data['new_sex'], new_path_to_images, user_id, original_path, processed_path) - return handle_remaining_images(salamander, salamander_path, image_id, last_id) + return handle_remaining_images(salamander, salamander_path, image_id, last_id, True, result) else: return jsonify({"message": "Salamander image, " + data['image_id'] + " does not exist", 'status': 400}) # if last image was moved: @@ -117,7 +117,7 @@ class SalamanderClass(Resource): add_salamander(salamander.id, image_id, data['new_location'], data['new_species'], data['new_sex'], new_path_to_images, user_id, original_path, processed_path) - return handle_remaining_images(salamander, salamander_path, image_id, last_id) + return handle_remaining_images(salamander, salamander_path, image_id, last_id, False, 0) else: return jsonify({"message": "Image id, " + data['image_id'] + " does not exist in salamander_id, " + data['id'], 'status': 400}) else: @@ -137,13 +137,17 @@ def delete_growth_row(salamander_id, image_id): db.session.commit() -def handle_remaining_images(salamander, salamander_path: str, image_id: int, last_id: int, ): +def handle_remaining_images(salamander, salamander_path: str, image_id: int, last_id: int, match_bool, result): # if last image was moved: if len(os.listdir(salamander_path)) == 0: os.rmdir(salamander_path) db.session.delete(salamander) db.session.commit() - return jsonify({"id": salamander.id, "imageId": image_id, "message": "salamander moved", 'status': 200}) + if match_bool: + return jsonify({"id": result, "matching": "Yes", 'status': 200}) + else: + return jsonify({"id": salamander.id, "matching": "No", 'status': 200}) + else: if image_id != last_id: original_path = glob.glob(os.path.join(salamander_path, str(last_id) + '.*'))[0] @@ -156,7 +160,10 @@ def handle_remaining_images(salamander, salamander_path: str, image_id: int, las db.session.commit() os.rename(processed_path, os.path.join(salamander_path, str(image_id) + "_str" + processed_extension)) os.rename(original_path, os.path.join(salamander_path, str(image_id) + original_extension)) - return jsonify({"id": salamander.id, "message": "salamander moved", 'status': 200}) + if match_bool: + return jsonify({"id": result, "matching": "Yes", 'status': 200}) + else: + return jsonify({"id": salamander.id, "matching": "No", 'status': 200}) def lower_image_id_growth_row(salamander_id, old_id, new_id): -- GitLab