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 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")
|
||||
@ -54,6 +54,7 @@ class ImageEndpoint:
|
||||
safe=False)
|
||||
|
||||
stored_hash = metadata.get('sha512', '')
|
||||
print(stored_hash)
|
||||
actual_dropbox_hash = create_sha512(dropbox_image_bytes)
|
||||
|
||||
if stored_hash != actual_dropbox_hash:
|
||||
@ -84,11 +85,9 @@ class ImageEndpoint:
|
||||
metadata = payload['metadata']
|
||||
filename = payload['metadata']['filename']
|
||||
|
||||
|
||||
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):
|
||||
print("Could not save image to dropbox")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user