added Service Class for MongoDB
This commit is contained in:
parent
e6f54951e6
commit
bd5247f21e
@ -1,9 +1,11 @@
|
|||||||
from app_be.views.mongo_db import MongoManager
|
from app_be.views.mongo_db import MongoManager
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
|
from app_be.services.hashservice import create_sha512
|
||||||
|
|
||||||
|
|
||||||
class MongoDBService:
|
class MongoDBService:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def getAll():
|
def getAll():
|
||||||
instance = MongoManager.getInstance()
|
instance = MongoManager.getInstance()
|
||||||
|
|
||||||
@ -17,6 +19,7 @@ class MongoDBService:
|
|||||||
print("Could not find Metadata")
|
print("Could not find Metadata")
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def getSingle(identifier):
|
def getSingle(identifier):
|
||||||
|
|
||||||
instance = MongoManager.getInstance()
|
instance = MongoManager.getInstance()
|
||||||
@ -36,7 +39,8 @@ class MongoDBService:
|
|||||||
del metadata['_id']
|
del metadata['_id']
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
def createSingle(metadata, identifier):
|
@staticmethod
|
||||||
|
def createSingle(metadata, identifier, decoded_image):
|
||||||
instance = MongoManager.getInstance()
|
instance = MongoManager.getInstance()
|
||||||
|
|
||||||
db = instance.AIC
|
db = instance.AIC
|
||||||
@ -45,11 +49,13 @@ class MongoDBService:
|
|||||||
try:
|
try:
|
||||||
metadata['identifier'] = identifier
|
metadata['identifier'] = identifier
|
||||||
metadata['location'] = [metadata['longitude'], metadata['latitude']]
|
metadata['location'] = [metadata['longitude'], metadata['latitude']]
|
||||||
|
metadata['sha512'] = create_sha512(decoded_image)
|
||||||
col.insert_one(metadata)
|
col.insert_one(metadata)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print("Could not insert Metadata")
|
print("Could not insert Metadata")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def deleteSingle(identifier):
|
def deleteSingle(identifier):
|
||||||
instance = MongoManager.getInstance()
|
instance = MongoManager.getInstance()
|
||||||
|
|
||||||
@ -61,3 +67,8 @@ class MongoDBService:
|
|||||||
except:
|
except:
|
||||||
print("Could not delete Metadata")
|
print("Could not delete Metadata")
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def deleteAll():
|
||||||
|
print("im Delete all")
|
||||||
@ -54,6 +54,7 @@ class ImageEndpoint:
|
|||||||
safe=False)
|
safe=False)
|
||||||
|
|
||||||
stored_hash = metadata.get('sha512', '')
|
stored_hash = metadata.get('sha512', '')
|
||||||
|
print(stored_hash)
|
||||||
actual_dropbox_hash = create_sha512(dropbox_image_bytes)
|
actual_dropbox_hash = create_sha512(dropbox_image_bytes)
|
||||||
|
|
||||||
if stored_hash != actual_dropbox_hash:
|
if stored_hash != actual_dropbox_hash:
|
||||||
@ -84,11 +85,9 @@ class ImageEndpoint:
|
|||||||
metadata = payload['metadata']
|
metadata = payload['metadata']
|
||||||
filename = payload['metadata']['filename']
|
filename = payload['metadata']['filename']
|
||||||
|
|
||||||
|
|
||||||
decoded_image = WrapperService.unwrap_file(b64encoded_image)
|
decoded_image = WrapperService.unwrap_file(b64encoded_image)
|
||||||
metadata['sha512'] = create_sha512(decoded_image)
|
|
||||||
|
|
||||||
MongoDBService.createSingle(metadata,identifier)
|
MongoDBService.createSingle(metadata,identifier,decoded_image)
|
||||||
|
|
||||||
if not DropboxService.create_file(filename, decoded_image):
|
if not DropboxService.create_file(filename, decoded_image):
|
||||||
print("Could not save image to dropbox")
|
print("Could not save image to dropbox")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user