Skip to content

Commit

Permalink
issue #74: Last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxence Guindon committed Apr 25, 2024
1 parent 3bc4fd0 commit 9affecc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
10 changes: 5 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
from collections import namedtuple
from cryptography.fernet import Fernet

load_dotenv()

import model.inference as inference
from model import request_function
import storage.azure_storage_api as azure_storage_api
from datastore import azure_storage_api
import storage.datastore_storage_api as datastore


Expand Down Expand Up @@ -74,7 +76,6 @@ class ImageWarning(APIWarnings):
class MaxContentLengthWarning(APIWarnings):
pass

load_dotenv()

connection_string_regex = r"^DefaultEndpointsProtocol=https?;.*;FileEndpoint=https://[a-zA-Z0-9]+\.file\.core\.windows\.net/;$"
pipeline_version_regex = r"\d.\d.\d"
Expand Down Expand Up @@ -564,9 +565,8 @@ def validate_and_upload_data(email, picture_set, data):
raise EmailNotSendError("the user email is not provided")
if not picture_set:
raise EmptyPictureSetError("no picture set provided")
cursor = app.config["DB"].cursor()
user_id = datastore.is_user_registered(cursor, email)
picture_id = datastore.upload_picture_set(cursor, user_id=user_id, **data)
user_id = datastore.validate_user(email)
picture_id = datastore.upload_picture_set(user_id=user_id, **data)
return picture_id

async def fetch_json(repo_URL, key, file_path):
Expand Down
35 changes: 29 additions & 6 deletions storage/datastore_storage_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,55 @@
This module provide an absraction to the nachet-datastore interface.
"""
import datastore
from datastore import db
import datastore.bin.deployment_mass_import

import datastore.bin.upload_picture_set
import datastore.db.queries.seed as seed_queries
# import datastore.db.queries.user as user_queries
# import datastore.db.queries.picture as picture_queries
from datastore import db, user


class DatastoreError(Exception):
pass


class SeedNotFoundError(DatastoreError):
pass

def get_connection():
return db.connect_db()

def get_cursor(connection):
def get_cursor():
db.connect_db()
return db.cursor()


def get_all_seeds_names() -> list:

"""
Return all seeds name register in the Datastore.
"""
try:
return db.queries.seed.get_all_seeds_names(get_cursor)
return seed_queries.get_all_seeds_names(get_cursor())
except Exception as error: # TODO modify Exception for more specific exception
raise SeedNotFoundError(error.args[0])


def get_seeds(expression: str) -> list:
"""
Return a list of all seed that contains the expression
"""
return list(filter(lambda x: expression in x, get_all_seeds_names(get_cursor)))
return list(filter(lambda x: expression in x, get_all_seeds_names(get_cursor())))


def validate_user(email: str) -> datastore.User:
"""
Return True if user is valid, False otherwise
"""

cursor = get_cursor()
if user.is_user_registered(cursor, email):
return datastore.get_User(email, cursor)


def upload_picture_set(**kwargs):
return datastore.bin.upload_picture_set.upload_picture_set(get_cursor(), **kwargs)

0 comments on commit 9affecc

Please sign in to comment.