-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementa rotas para acesso ao dados de arquivos com diários agregad…
…os (#73) Implementação da rota para consulta de meta dados dos arquivos agregados. A rota devolve todas as informações relevantes mantidas na tabela 'aggregates', que são: - territory_id, - state_code, - url_zip, - year, - last_updated, - hash_info, - file_size
- Loading branch information
Showing
9 changed files
with
232 additions
and
38 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
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,7 @@ | ||
from .aggregates_access import ( | ||
AggregatesAccess, | ||
AggregatesAccessInterface, | ||
AggregatesDatabaseInterface, | ||
create_aggregates_interface, | ||
Aggregates | ||
) |
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,67 @@ | ||
import abc | ||
from typing import Optional, Dict | ||
|
||
class AggregatesDatabaseInterface(abc.ABC): | ||
""" | ||
Interface to access data from aggregates. | ||
""" | ||
|
||
@abc.abstractmethod | ||
def get_aggregates(self, territory_id: Optional[str] = None, state_code: str = ""): | ||
""" | ||
Get information about a aggregate. | ||
""" | ||
|
||
class AggregatesAccessInterface(abc.ABC): | ||
""" | ||
Interface to access data from aggregates. | ||
""" | ||
|
||
@abc.abstractmethod | ||
def get_aggregates(self, territory_id: Optional[str] = None, state_code: str = ""): | ||
""" | ||
Get information about a aggregate. | ||
""" | ||
|
||
class AggregatesAccess(AggregatesAccessInterface): | ||
_database_gateway = None | ||
|
||
def __init__(self, database_gateway=None): | ||
self._database_gateway = database_gateway | ||
|
||
def get_aggregates(self, territory_id: Optional[str] = None, state_code: str = ""): | ||
aggregate_info = self._database_gateway.get_aggregates(territory_id, state_code) | ||
return aggregate_info | ||
|
||
class Aggregates: | ||
""" | ||
Item to represente a aggregate in memory inside the module | ||
""" | ||
|
||
def __init__( | ||
self, | ||
territory_id, | ||
state_code, | ||
file_path, | ||
year, | ||
last_updated, | ||
hash_info, | ||
file_size_mb, | ||
): | ||
self.territory_id = territory_id | ||
self.state_code = state_code | ||
self.file_path = file_path | ||
self.year = year | ||
self.last_updated = last_updated | ||
self.hash_info = hash_info | ||
self.file_size_mb = file_size_mb | ||
|
||
def __repr__(self): | ||
return f"Aggregates(territory_id={self.territory_id}, state_code={self.state_code}, file_path={self.file_path}, year={self.year}, last_updated={self.last_updated}, hash_info={self.hash_info}, file_size_mb={self.file_size_mb})" | ||
|
||
def create_aggregates_interface(database_gateway: AggregatesDatabaseInterface) -> AggregatesAccessInterface: | ||
if not isinstance(database_gateway, AggregatesDatabaseInterface): | ||
raise Exception( | ||
"Database gateway should implement the AggregatesDatabaseInterface interface" | ||
) | ||
return AggregatesAccess(database_gateway) |
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
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 |
---|---|---|
|
@@ -8,11 +8,17 @@ [email protected] | |
QUERIDO_DIARIO_SUGGESTION_RECIPIENT_NAME=Recipient Name | ||
QUERIDO_DIARIO_SUGGESTION_RECIPIENT_EMAIL=[email protected] | ||
QUERIDO_DIARIO_SUGGESTION_MAILJET_CUSTOM_ID=AppCustomID | ||
POSTGRES_USER=companies | ||
POSTGRES_PASSWORD=companies | ||
POSTGRES_DB=companiesdb | ||
POSTGRES_HOST=localhost | ||
POSTGRES_PORT=5432 | ||
QUERIDO_DIARIO_FILES_ENDPOINT=http://localhost:9000/queridodiariobucket/ | ||
POSTGRES_COMPANIES_USER=companies | ||
POSTGRES_COMPANIES_PASSWORD=companies | ||
POSTGRES_COMPANIES_DB=companiesdb | ||
POSTGRES_COMPANIES_HOST=localhost | ||
POSTGRES_COMPANIES_PORT=5432 | ||
POSTGRES_AGGREGATES_USER=queridodiario | ||
POSTGRES_AGGREGATES_PASSWORD=queridodiario | ||
POSTGRES_AGGREGATES_DB=queridodiariodb | ||
POSTGRES_AGGREGATES_HOST=localhost | ||
POSTGRES_AGGREGATES_PORT=5432 | ||
CITY_DATABASE_CSV=censo.csv | ||
GAZETTE_OPENSEARCH_INDEX=querido-diario | ||
GAZETTE_CONTENT_FIELD=source_text | ||
|
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,9 +1,16 @@ | ||
from companies import CompaniesDatabaseInterface | ||
from aggregates import AggregatesDatabaseInterface | ||
|
||
from .postgresql import PostgreSQLDatabase | ||
from .postgresql import PostgreSQLDatabaseCompanies, PostgreSQLDatabaseAggregates | ||
|
||
|
||
def create_companies_database_interface( | ||
db_host, db_name, db_user, db_pass, db_port | ||
) -> CompaniesDatabaseInterface: | ||
return PostgreSQLDatabase(db_host, db_name, db_user, db_pass, db_port) | ||
return PostgreSQLDatabaseCompanies(db_host, db_name, db_user, db_pass, db_port) | ||
|
||
|
||
def create_aggregates_database_interface( | ||
db_host, db_name, db_user, db_pass, db_port | ||
) -> AggregatesDatabaseInterface: | ||
return PostgreSQLDatabaseAggregates(db_host, db_name, db_user, db_pass, db_port) |
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
Oops, something went wrong.