Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: TT-384 implemented the reading of the storage blob to the endpo…
…int and repository
  • Loading branch information
Jobzi authored Nov 8, 2021
commit 054798b568c99e3faa576f65e9726d031480ad48
24 changes: 22 additions & 2 deletions time_tracker_api/activities/activities_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from commons.data_access_layer.database import EventContext
from utils.enums.status import Status
from utils.query_builder import CosmosDBQueryBuilder

from commons.data_access_layer.file_stream import FileStream

class ActivityDao(CRUDDao):
pass
Expand Down Expand Up @@ -113,6 +113,21 @@ def find_all(
function_mapper = self.get_mapper_or_dict(mapper)
return list(map(function_mapper, result))

def find_all_from_blob_storage(
self,
event_context: EventContext,
mapper: Callable = None,
file_name: str = "activity.json",
):
tenant_id_value = self.find_partition_key_value(event_context)
function_mapper = self.get_mapper_or_dict(mapper)
if tenant_id_value is None:
return []

import json
fs = FileStream("storageaccounteystr82c5","tt-common-files")
result = fs.get_file_stream(file_name)
return list(map(function_mapper, json.load(result))) if result is not None else []

class ActivityCosmosDBDao(APICosmosDBDao, ActivityDao):
def __init__(self, repository):
Expand All @@ -128,7 +143,7 @@ def get_all_with_id_in_list(
activity_ids,
)

def get_all(
def get_all_old(
self,
conditions: dict = None,
activities_id: List = None,
Expand All @@ -147,6 +162,11 @@ def get_all(
)
return activities

def get_all(self, conditions: dict = None) -> list:
event_ctx = self.create_event_context("read-many")
activities = self.repository.find_all_from_blob_storage(event_context=event_ctx)
return activities

def create(self, activity_payload: dict):
event_ctx = self.create_event_context('create')
activity_payload['status'] = Status.ACTIVE.value
Expand Down