diff --git a/API/config.py b/API/config.py new file mode 100644 index 0000000..5823b70 --- /dev/null +++ b/API/config.py @@ -0,0 +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 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] 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"}