-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged with branch 63-MSME-application-endpoints
- Loading branch information
Showing
37 changed files
with
1,152 additions
and
591 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 |
---|---|---|
@@ -1,18 +1,21 @@ | ||
COGNITO_CLIENT_ID=********\*\********* | ||
AWS_ACCESS_KEY=********\*\********* | ||
AWS_CLIENT_SECRET=********\*\********* | ||
AWS_REGION=********\*\********* | ||
COGNITO_POOL_ID=********\*\********* | ||
EMAIL_SENDER_ADDRESS=********\*\********* | ||
DATABASE_URL=********\*\********* | ||
SECOP_APP_TOKEN=********\*\********* | ||
COLOMBIA_SECOP_APP_TOKEN=********\*\********* | ||
FRONTEND_URL=********\*\********* | ||
HASH_KEY=********\*\********* | ||
FRONT_PUBLIC_IMAGES_ES = ********\*\********* | ||
FRONT_PUBLIC_IMAGES_EN = ********\*\********* | ||
TEMPORAL_BUCKET = ********\*\********* | ||
FACEBOOK_LINK = ********\*\********* | ||
TWITTER_LINK = ********\*\********* | ||
LINK_LINK = ********\*\********* | ||
AWS_ACCESS_KEY = XXXXXX | ||
AWS_CLIENT_SECRET = XXXXXX | ||
AWS_REGION = XXXXXX | ||
COGNITO_POOL_ID = XXXXXX | ||
COGNITO_CLIENT_ID = XXXXXX | ||
COGNITO_CLIENT_SECRE = XXXXXX | ||
EMAIL_SENDER_ADDRESS = XXXXXX | ||
FRONTEND_URL = XXXXXX | ||
SENTRY_DNS = XXXXXX | ||
DATABASE_URL = XXXXXX | ||
|
||
COLOMBIA_SECOP_APP_TOKEN = XXXXXX | ||
SECOP_PAGINATION_LIMIT = XXXXXX | ||
HASH_KEY = XXXXXX | ||
TEST_MAIL_RECEIVER = XXXXXX | ||
|
||
|
||
IMAGES_LANG_SUBPATH = XXXXXX | ||
FACEBOOK_LINK = XXXXXX | ||
TWITTER_LINK = XXXXXX | ||
LINK_LINK = XXXXXX |
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
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,17 +1,26 @@ | ||
# | ||
FROM python:3.9 | ||
FROM python:3.11.3-alpine3.18 | ||
|
||
# | ||
WORKDIR /code | ||
|
||
# | ||
# | ||
|
||
COPY ./requirements.txt /code/requirements.txt | ||
RUN pip install --ignore-installed uvicorn==0.22.0 | ||
# | ||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt | ||
RUN \ | ||
apk add --no-cache python3 postgresql-libs && \ | ||
apk add --no-cache --virtual .build-deps gcc python3-dev musl-dev postgresql-dev libffi-dev openssl-dev && \ | ||
pip install --ignore-installed uvicorn==0.22.0 && \ | ||
pip install --no-cache-dir --upgrade -r /code/requirements.txt && \ | ||
apk --purge del .build-deps | ||
|
||
# | ||
|
||
COPY ./.env /code/.env | ||
COPY ./alembic.ini /code/alembic.ini | ||
COPY ./migrations /code/migrations | ||
COPY ./app /code/app | ||
|
||
# Run Alembic migrations | ||
RUN alembic upgrade head | ||
# | ||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] |
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
Empty file.
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,75 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from sqlalchemy.orm.session import Session | ||
|
||
from app.db.session import app_settings | ||
from app.schema.core import Application, Message, MessageType | ||
|
||
from . import background_utils | ||
|
||
|
||
def insert_application(application: Application, session: Session): | ||
obj_db = Application(**application) | ||
obj_db.created_at = datetime.utcnow() | ||
|
||
session.add(obj_db) | ||
session.flush() | ||
|
||
return obj_db | ||
|
||
|
||
def insert_message(application: Application, session: Session): | ||
obj_db = Message(application=application, type=MessageType.BORROWER_INVITACION) | ||
obj_db.created_at = datetime.utcnow() | ||
|
||
session.add(obj_db) | ||
session.flush() | ||
|
||
return obj_db | ||
|
||
|
||
def get_existing_application(award_borrower_identifier: str, session: Session): | ||
application = ( | ||
session.query(Application) | ||
.filter(Application.award_borrower_identifier == award_borrower_identifier) | ||
.first() | ||
) | ||
|
||
return application | ||
|
||
|
||
def create_application( | ||
award_id, borrower_id, email, legal_identifier, source_contract_id, session: Session | ||
) -> Application: | ||
award_borrower_identifier: str = background_utils.get_secret_hash( | ||
legal_identifier + source_contract_id | ||
) | ||
|
||
# if application already exists | ||
application = get_existing_application(award_borrower_identifier, session) | ||
if application: | ||
error_data = { | ||
"legal_identifier": legal_identifier, | ||
"source_contract_id": source_contract_id, | ||
"application_id": application.id, | ||
} | ||
|
||
background_utils.raise_sentry_error( | ||
f"Skipping Award - Application ID {application.id} already exists on for award {source_contract_id}", | ||
error_data, | ||
) | ||
|
||
new_uuid: str = background_utils.generate_uuid(award_borrower_identifier) | ||
application = { | ||
"award_id": award_id, | ||
"borrower_id": borrower_id, | ||
"primary_email": email, | ||
"award_borrower_identifier": award_borrower_identifier, | ||
"uuid": new_uuid, | ||
"expired_at": datetime.utcnow() | ||
+ timedelta(days=app_settings.application_expiration_days), | ||
} | ||
|
||
application = insert_application(application, session) | ||
|
||
return application |
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,82 @@ | ||
from contextlib import contextmanager | ||
from datetime import datetime | ||
|
||
from sqlalchemy import desc | ||
from sqlalchemy.orm.session import Session | ||
|
||
from app.db.session import get_db | ||
from app.schema.core import Award | ||
|
||
from . import background_utils | ||
from . import colombia_data_access as data_access | ||
|
||
|
||
def get_existing_award(source_contract_id: str, session: Session): | ||
award = ( | ||
session.query(Award) | ||
.filter(Award.source_contract_id == source_contract_id) | ||
.first() | ||
) | ||
|
||
return award | ||
|
||
|
||
def get_last_updated_award_date(): | ||
with contextmanager(get_db)() as session: | ||
award = ( | ||
session.query(Award).order_by(desc(Award.source_last_updated_at)).first() | ||
) | ||
|
||
if not award: | ||
return None | ||
|
||
return award.source_last_updated_at | ||
|
||
|
||
def insert_award(award: Award, session: Session): | ||
obj_db = Award(**award) | ||
obj_db.created_at = datetime.utcnow() | ||
obj_db.missing_data = background_utils.get_missing_data_keys(award) | ||
|
||
session.add(obj_db) | ||
session.flush() | ||
return obj_db | ||
|
||
|
||
def create_new_award( | ||
source_contract_id: str, | ||
entry: dict, | ||
borrower_id: int = None, | ||
previous: bool = False, | ||
) -> dict: | ||
return data_access.create_new_award( | ||
source_contract_id, entry, borrower_id, previous | ||
) | ||
|
||
|
||
def get_new_contracts(index: int, last_updated_award_date): | ||
return data_access.get_new_contracts(index, last_updated_award_date) | ||
|
||
|
||
def get_previous_contracts(documento_proveedor): | ||
return data_access.get_previous_contracts(documento_proveedor) | ||
|
||
|
||
def get_source_contract_id(entry): | ||
return data_access.get_source_contract_id(entry) | ||
|
||
|
||
def create_award(entry, session: Session, borrower_id=None, previous=False) -> Award: | ||
source_contract_id = get_source_contract_id(entry) | ||
|
||
# if award already exists | ||
if get_existing_award(source_contract_id, session): | ||
background_utils.raise_sentry_error( | ||
f"Skipping Award [previous {previous}] - Already exists on database", entry | ||
) | ||
|
||
new_award = create_new_award(source_contract_id, entry, borrower_id, previous) | ||
|
||
award = insert_award(new_award, session) | ||
|
||
return award |
Oops, something went wrong.