Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweep: Feature Request: Migrate Database to MongoDB Atlas and Create Interoperable Functions (βœ“ Sandbox Passed) #12

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions API/config.py
Original file line number Diff line number Diff line change
@@ -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": "<Your MongoDB Atlas Connection String Here>",
"db_name": "ImageDB",
"USE_ATLAS": False
}
# URI for connecting to MongoDB Atlas - replace <Your MongoDB Atlas Connection String Here> 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
5 changes: 4 additions & 1 deletion API/database.py
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
13 changes: 13 additions & 0 deletions API/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Loading