added Service Class for MongoDB
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
from app_be.views.mongo_db import MongoManager
|
||||
from django.http import JsonResponse
|
||||
from app_be.services.hashservice import create_sha512
|
||||
|
||||
|
||||
class MongoDBService:
|
||||
|
||||
@staticmethod
|
||||
def getAll():
|
||||
instance = MongoManager.getInstance()
|
||||
|
||||
@@ -17,6 +19,7 @@ class MongoDBService:
|
||||
print("Could not find Metadata")
|
||||
return resp
|
||||
|
||||
@staticmethod
|
||||
def getSingle(identifier):
|
||||
|
||||
instance = MongoManager.getInstance()
|
||||
@@ -36,7 +39,8 @@ class MongoDBService:
|
||||
del metadata['_id']
|
||||
return metadata
|
||||
|
||||
def createSingle(metadata, identifier):
|
||||
@staticmethod
|
||||
def createSingle(metadata, identifier, decoded_image):
|
||||
instance = MongoManager.getInstance()
|
||||
|
||||
db = instance.AIC
|
||||
@@ -45,11 +49,13 @@ class MongoDBService:
|
||||
try:
|
||||
metadata['identifier'] = identifier
|
||||
metadata['location'] = [metadata['longitude'], metadata['latitude']]
|
||||
metadata['sha512'] = create_sha512(decoded_image)
|
||||
col.insert_one(metadata)
|
||||
|
||||
except:
|
||||
print("Could not insert Metadata")
|
||||
|
||||
@staticmethod
|
||||
def deleteSingle(identifier):
|
||||
instance = MongoManager.getInstance()
|
||||
|
||||
@@ -60,4 +66,9 @@ class MongoDBService:
|
||||
resp = col.delete_one({"identifier": identifier})
|
||||
except:
|
||||
print("Could not delete Metadata")
|
||||
return resp
|
||||
return resp
|
||||
|
||||
|
||||
@staticmethod
|
||||
def deleteAll():
|
||||
print("im Delete all")
|
||||
Reference in New Issue
Block a user