-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from GSA-TTS/submissions
Data Submissions
- Loading branch information
Showing
13 changed files
with
394 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,4 +160,7 @@ cython_debug/ | |
#.idea/ | ||
|
||
# Development databases | ||
*.sqlite3 | ||
*.sqlite3 | ||
|
||
# Development storage | ||
storage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
|
||
APP_ENV = os.getenv('APP_ENV') | ||
DATABASE_URL = os.getenv('DATABASE_URL') | ||
STORAGE_PATH = os.getenv('STORAGE_PATH') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
class DataProvider: | ||
def __init__(self, name: str, id: int = None): | ||
class Entity: | ||
def __init__(self, id: int = None): | ||
self.id = id | ||
self.created_at = None | ||
self.updated_at = None | ||
|
||
def set_created_at(self, created_at): | ||
self.created_at = created_at | ||
|
||
def set_updated_at(self, updated_at): | ||
self.updated_at = updated_at | ||
|
||
|
||
class DataProvider(Entity): | ||
def __init__(self, name: str, id: int = None): | ||
super().__init__(id) | ||
self.name = name | ||
|
||
def __repr__(self): | ||
return f'DataProvider {self.id}, {self.name} \ | ||
(created: {self.created_at}; updated: {self.updated_at})' | ||
|
||
class DataSubmission: | ||
def __init__(self, file_path: str, provider: DataProvider, id: int = None): | ||
self.id = id | ||
self.file_path = file_path | ||
|
||
class DataSubmission(Entity): | ||
def __init__( | ||
self, | ||
file_name: str, | ||
url: str, | ||
provider: DataProvider, | ||
id: int = None, | ||
): | ||
super().__init__(id) | ||
self.file_name = file_name | ||
self.url = url | ||
self.provider = provider | ||
|
||
def __repr__(self): | ||
return f'DataSubmission \ | ||
{self.id}, {self.file_name}, {self.url}, {self.provider} \ | ||
(created: {self.created_at}; updated: {self.updated_at})' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
from typing import Protocol | ||
from collections.abc import Iterable | ||
from nad_ch.domain.entities import DataProvider | ||
from nad_ch.domain.entities import DataProvider, DataSubmission | ||
|
||
|
||
class DataProviderRepository(Protocol): | ||
def add(self, provider: DataProvider) -> None: | ||
def add(self, provider: DataProvider) -> DataProvider: | ||
... | ||
|
||
def get_by_name(self, name: str) -> DataProvider: | ||
... | ||
|
||
def get_all(self) -> Iterable[DataProvider]: | ||
... | ||
|
||
|
||
class DataSubmissionRepository(Protocol): | ||
def add(self, submission: DataSubmission) -> DataSubmission: | ||
... | ||
|
||
def get_by_provider(self, provider: DataProvider) -> Iterable[DataSubmission]: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
import shutil | ||
|
||
|
||
class LocalStorage: | ||
def __init__(self, base_path: str): | ||
self.base_path = base_path | ||
|
||
def _full_path(self, path: str) -> str: | ||
return os.path.join(self.base_path, path) | ||
|
||
def upload(self, source: str, destination: str) -> None: | ||
shutil.copy(source, self._full_path(destination)) | ||
|
||
def delete(self, file_path: str) -> None: | ||
full_file_path = self._full_path(file_path) | ||
if os.path.exists(full_file_path): | ||
os.remove(full_file_path) | ||
|
||
def get_file_url(self, file_name: str) -> str: | ||
return file_name |
Oops, something went wrong.