From c1270da5267161f5c4ce4cc63b171121f4c427af Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:51:22 +0000 Subject: [PATCH 1/4] feat: Add config.py for flexible MongoDB connectio --- API/config.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 API/config.py diff --git a/API/config.py b/API/config.py new file mode 100644 index 0000000..19bcb83 --- /dev/null +++ b/API/config.py @@ -0,0 +1,6 @@ +DB_CONFIG = { + "local_uri": "mongodb://localhost:27017/", + "atlas_uri": "", + "db_name": "ImageDB", + "USE_ATLAS": False +} From d9d0accd3030b85782801750bda3908f71a9ffdc Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:52:31 +0000 Subject: [PATCH 2/4] feat: Updated API/database.py --- API/database.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/API/database.py b/API/database.py index ccdfc98..eb1b4b8 100644 --- a/API/database.py +++ b/API/database.py @@ -1,10 +1,13 @@ from datetime import datetime +from config import DB_CONFIG from pymongo import MongoClient class Database: - def __init__(self, uri="mongodb://localhost:27017/", db_name="ImageDB"): + def __init__(self, uri=None, db_name=None): + uri = DB_CONFIG['atlas_uri'] if DB_CONFIG['USE_ATLAS'] else DB_CONFIG['local_uri'] + db_name = db_name or DB_CONFIG['db_name'] self.client = MongoClient(uri) self.db = self.client[db_name] From 55b8c5024f2744d34a0d5ca0230c7c8ead9e2560 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:53:22 +0000 Subject: [PATCH 3/4] feat: Updated API/route.py --- API/route.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/API/route.py b/API/route.py index 940015c..ba25114 100644 --- a/API/route.py +++ b/API/route.py @@ -267,3 +267,16 @@ async def delete_employees(EmployeeCode: int): client.find_one_and_delete(collection, {"EmployeeCode": EmployeeCode}) return {"Message": "Successfully Deleted"} +@router.post("/recognise_face") +async def recognise_face(): + """ + Recognise a face using MongoDB Atlas regardless of the USE_ATLAS flag's value. + + Returns: + dict: A dictionary containing the recognition result. + """ + # Explicitly connect to MongoDB Atlas + atlas_client = Database(uri=DB_CONFIG['atlas_uri']) + # Perform database operations using atlas_client + # Example: atlas_client.find(...) + return {"message": "Face recognition completed"} From bd6768b0e7c83bb3799de86dc7b3215c2e25f777 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:54:10 +0000 Subject: [PATCH 4/4] feat: Updated API/config.py --- API/config.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/API/config.py b/API/config.py index 19bcb83..5823b70 100644 --- a/API/config.py +++ b/API/config.py @@ -1,6 +1,12 @@ +# Configuration settings for database connections DB_CONFIG = { +# URI for connecting to the local MongoDB instance "local_uri": "mongodb://localhost:27017/", "atlas_uri": "", "db_name": "ImageDB", "USE_ATLAS": False } +# URI for connecting to MongoDB Atlas - replace with your actual connection string. +# You can obtain this string from your MongoDB Atlas dashboard under the 'Connect' section of your cluster. +# Name of the database to be used +# Flag to toggle the use of MongoDB Atlas; set to True to use Atlas or False to use the local database