From 171cba1e3db2f9af6d75332074e33d405db4d328 Mon Sep 17 00:00:00 2001 From: Andy Kuny Date: Tue, 16 Jan 2024 09:55:20 -0500 Subject: [PATCH] Move logic for generating filename to DataSubmission entity --- nad_ch/domain/entities.py | 9 +++++++++ nad_ch/use_cases.py | 5 +---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nad_ch/domain/entities.py b/nad_ch/domain/entities.py index ded1d29..0137374 100644 --- a/nad_ch/domain/entities.py +++ b/nad_ch/domain/entities.py @@ -1,3 +1,6 @@ +import datetime + + class Entity: def __init__(self, id: int = None): self.id = id @@ -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 diff --git a/nad_ch/use_cases.py b/nad_ch/use_cases.py index cc520d5..23d6be7 100644 --- a/nad_ch/use_cases.py +++ b/nad_ch/use_cases.py @@ -1,4 +1,3 @@ -import datetime import os from typing import List from nad_ch.application_context import ApplicationContext @@ -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)