Skip to content
Open
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
57 changes: 0 additions & 57 deletions backend/python/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
# auth {
import firebase_admin
# } auth
# no-auth {
# file-storage {
import firebase_admin
# } file-storage
# } no-auth

from flask import Flask
from flask.cli import ScriptInfo
Expand Down Expand Up @@ -99,59 +94,7 @@ def create_app(config_name):
{"storageBucket": os.getenv("FIREBASE_STORAGE_DEFAULT_BUCKET")},
)
# } file-storage
# no-file-storage {
firebase_admin.initialize_app(
firebase_admin.credentials.Certificate(
{
"type": "service_account",
"project_id": os.getenv("FIREBASE_PROJECT_ID"),
"private_key_id": os.getenv("FIREBASE_SVC_ACCOUNT_PRIVATE_KEY_ID"),
"private_key": os.getenv("FIREBASE_SVC_ACCOUNT_PRIVATE_KEY").replace(
"\\n", "\n"
),
"client_email": os.getenv("FIREBASE_SVC_ACCOUNT_CLIENT_EMAIL"),
"client_id": os.getenv("FIREBASE_SVC_ACCOUNT_CLIENT_ID"),
"auth_uri": os.getenv("FIREBASE_SVC_ACCOUNT_AUTH_URI"),
"token_uri": os.getenv("FIREBASE_SVC_ACCOUNT_TOKEN_URI"),
"auth_provider_x509_cert_url": os.getenv(
"FIREBASE_SVC_ACCOUNT_AUTH_PROVIDER_X509_CERT_URL"
),
"client_x509_cert_url": os.getenv(
"FIREBASE_SVC_ACCOUNT_CLIENT_X509_CERT_URL"
),
}
),
)
# } no-file-storage

# } auth
# no-auth {
# file-storage {
firebase_admin.initialize_app(
firebase_admin.credentials.Certificate(
{
"type": "service_account",
"project_id": os.getenv("FIREBASE_PROJECT_ID"),
"private_key_id": os.getenv("FIREBASE_SVC_ACCOUNT_PRIVATE_KEY_ID"),
"private_key": os.getenv("FIREBASE_SVC_ACCOUNT_PRIVATE_KEY").replace(
"\\n", "\n"
),
"client_email": os.getenv("FIREBASE_SVC_ACCOUNT_CLIENT_EMAIL"),
"client_id": os.getenv("FIREBASE_SVC_ACCOUNT_CLIENT_ID"),
"auth_uri": os.getenv("FIREBASE_SVC_ACCOUNT_AUTH_URI"),
"token_uri": os.getenv("FIREBASE_SVC_ACCOUNT_TOKEN_URI"),
"auth_provider_x509_cert_url": os.getenv(
"FIREBASE_SVC_ACCOUNT_AUTH_PROVIDER_X509_CERT_URL"
),
"client_x509_cert_url": os.getenv(
"FIREBASE_SVC_ACCOUNT_CLIENT_X509_CERT_URL"
),
}
),
{"storageBucket": os.getenv("FIREBASE_STORAGE_DEFAULT_BUCKET")},
)
# } file-storage
# } no-auth
from . import models, rest

models.init_app(app)
Expand Down
3 changes: 0 additions & 3 deletions backend/python/app/middlewares/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ def wrapper(*args, **kwargs):
req["file"] = request.files.get("file", default=None)
dto = dtos[dto_class_name](**req)
# } file-storage
# no-file-storage {
dto = dtos[dto_class_name](**request.json)
# } no-file-storage
error_message = dto.validate()
if error_message:
return (
Expand Down
3 changes: 0 additions & 3 deletions backend/python/app/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ def init_app(app):
# auth {
from . import user_routes, auth_routes, entity_routes, documentation_routes
# } auth
# no-auth {
from . import entity_routes, documentation_routes
# } no-auth

# auth {
app.register_blueprint(user_routes.blueprint)
Expand Down
17 changes: 0 additions & 17 deletions backend/python/app/rest/entity_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
entity_service = EntityService(current_app.logger, file_storage_service)

# } file-storage
# no-file-storage {
# define instance of EntityService
entity_service = EntityService(current_app.logger)

# } no-file-storage
# defines a shared URL prefix for all routes
blueprint = Blueprint("entity", __name__, url_prefix="/entities")

Expand Down Expand Up @@ -89,9 +84,6 @@ def create_entity():
req["file"] = request.files.get("file", default=None)
body = EntityDTO(**req)
# } file-storage
# no-file-storage {
body = EntityDTO(**request.json)
# } no-file-storage
except Exception as e:
error_message = getattr(e, "message", None)
return jsonify({"error": (error_message if error_message else str(e))}), 500
Expand All @@ -116,9 +108,6 @@ def update_entity(id):
req_file = request.files.get("file", default=None)
body = EntityDTO(**req, file=req_file)
# } file-storage
# no-file-storage {
body = EntityDTO(**request.json)
# } no-file-storage
except Exception as e:
error_message = getattr(e, "message", None)
return jsonify({"error": (error_message if error_message else str(e))}), 500
Expand Down Expand Up @@ -183,9 +172,6 @@ def create_entity():
req["file"] = request.files.get("file", default=None)
body = EntityDTO(**req)
# } file-storage
# no-file-storage {
body = EntityDTO(**request.json)
# } no-file-storage
except Exception as e:
error_message = getattr(e, "message", None)
return jsonify({"error": (error_message if error_message else str(e))}), 500
Expand All @@ -210,9 +196,6 @@ def update_entity(id):
req["file"] = request.files.get("file", default=None)
body = EntityDTO(**req)
# } file-storage
# no-file-storage {
body = EntityDTO(**request.json)
# } no-file-storage
except Exception as e:
error_message = getattr(e, "message", None)
return jsonify({"error": (error_message if error_message else str(e))}), 500
Expand Down
18 changes: 0 additions & 18 deletions backend/python/app/services/implementations/entity_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ class EntityService(IEntityService):
# file-storage {
def __init__(self, logger, file_storage_service: IFileStorageService):
# } file-storage
# no-file-storage {
def __init__(self, logger):
# } no-file-storage
self.logger = logger
# file-storage {
self.file_storage_service = file_storage_service
Expand Down Expand Up @@ -45,9 +42,6 @@ def create_entity(self, entity):
entity.__dict__.pop("file", None)
new_entity = Entity(**entity.__dict__, file_name=file_name)
# } file-storage
# no-file-storage {
new_entity = Entity(**entity.__dict__)
# } no-file-storage
except Exception as error:
self.logger.error(str(error))
raise error
Expand Down Expand Up @@ -87,9 +81,6 @@ def update_entity(self, id, entity):

Entity.query.filter_by(id=id).update(entity_dict)
# } file-storage
# no-file-storage {
Entity.query.filter_by(id=id).update(entity.__dict__)
# } no-file-storage
updated_entity = Entity.query.get(id)
db.session.commit()

Expand Down Expand Up @@ -132,9 +123,6 @@ class EntityService(IEntityService):
# file-storage {
def __init__(self, logger, file_storage_service: IFileStorageService):
# } file-storage
# no-file-storage {
def __init__(self, logger):
# } no-file-storage
self.logger = logger
# file-storage {
self.file_storage_service = file_storage_service
Expand Down Expand Up @@ -170,9 +158,6 @@ def create_entity(self, entity):
entity.__dict__.pop("file", None)
new_entity = Entity(**entity.__dict__, file_name=file_name)
# } file-storage
# no-file-storage {
new_entity = Entity(**entity.__dict__)
# } no-file-storage
new_entity.save()
except Exception as error:
self.logger.error(str(error))
Expand Down Expand Up @@ -206,9 +191,6 @@ def update_entity(self, id, entity):
new=True, **entity.__dict__, file_name=file_name
)
# } file-storage
# no-file-storage {
updated_entity = Entity.objects(id=id).modify(new=True, **entity.__dict__)
# } no-file-storage

if updated_entity is None:
self.logger.error("Invalid id")
Expand Down