Skip to content

Commit

Permalink
Move logic for generating filename to DataSubmission entity
Browse files Browse the repository at this point in the history
  • Loading branch information
akuny committed Jan 16, 2024
1 parent 0fc1be3 commit 171cba1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 9 additions & 0 deletions nad_ch/domain/entities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import datetime


class Entity:
def __init__(self, id: int = None):
self.id = id
Expand Down Expand Up @@ -36,3 +39,9 @@ def __repr__(self):
return f"DataSubmission \
{self.id}, {self.filename}, {self.provider} \
(created: {self.created_at}; updated: {self.updated_at})"

@staticmethod
def generate_filename(provider: DataProvider) -> str:
datetime_str = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{provider.name}_{datetime_str}.zip"
return filename
5 changes: 1 addition & 4 deletions nad_ch/use_cases.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
import os
from typing import List
from nad_ch.application_context import ApplicationContext
Expand Down Expand Up @@ -46,10 +45,8 @@ def ingest_data_submission(
ctx.logger.error("Provider with that name does not exist")
return

datetime_str = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")

try:
filename = f"{provider.name}_{datetime_str}.zip"
filename = DataSubmission.generate_filename(provider)
ctx.storage.upload(file_path, filename)

submission = DataSubmission(filename, provider)
Expand Down

0 comments on commit 171cba1

Please sign in to comment.