Skip to content

Commit

Permalink
addressing pr comment
Browse files Browse the repository at this point in the history
  • Loading branch information
asinn134 committed Dec 17, 2024
1 parent 77f7ff1 commit a417e93
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from app.extensions import api, cache
from app.api.mines.explosives_permit.models.explosives_permit import ExplosivesPermit
from app.api.mines.explosives_permit_amendment.models.explosives_permit_amendment import ExplosivesPermitAmendment
from app.api.mines.explosives_permit.models.explosives_permit_document_type import ExplosivesPermitDocumentType
from app.api.utils.resources_mixins import UserMixin
from app.api.utils.include.user_info import User
Expand Down Expand Up @@ -71,7 +72,18 @@ def post(self, document_type_code):

explosives_permit_guid = data['explosives_permit_guid']
explosives_permit = ExplosivesPermit.find_by_explosives_permit_guid(explosives_permit_guid)
explosives_permit_id = explosives_permit.explosives_permit_id
explosives_permit_amendment_id = data.get('explosives_permit_amendment_id', None)
explosives_permit_amendments = ExplosivesPermitAmendment.find_by_explosives_permit_id(explosives_permit_id)
if explosives_permit_amendment_id:
is_amendment_matched_with_permit = any(
amendments.explosives_permit_amendment_id == int(explosives_permit_amendment_id)
for amendments in explosives_permit_amendments
)

if is_amendment_matched_with_permit == False:
raise MineException("Provided Explosive Permit Amendment Id does not exist under this Explosive Permit", status_code = 400)

if not explosives_permit:
raise MineException("Explosives Permit not found",
status_code = 404)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ def delete(self, commit=True):
def find_by_explosives_permit_amendment_guid(cls, explosives_permit_amendment_guid):
return cls.query.filter_by(
explosives_permit_amendment_guid=explosives_permit_amendment_guid, deleted_ind=False).one_or_none()

@classmethod
def find_by_explosives_permit_id(cls, explosives_permit_id):
return cls.query.filter_by(
explosives_permit_id=explosives_permit_id, deleted_ind=False).all()

def update(self,
amendment_no,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tests.factories import ExplosivesPermitAmendmentFactory
from tests.factories import (ExplosivesPermitAmendmentFactory, ExplosivesPermitFactory)

from app.api.mines.explosives_permit_amendment.models.explosives_permit_amendment import ExplosivesPermitAmendment

Expand All @@ -7,3 +7,9 @@ def test_explosives_permit_amendment_find_by_explosives_permit_amendment_guid(db
explosives_permit_amendment_guid = explosives_permit_amendment.explosives_permit_amendment_guid
explosives_permit_amendment = ExplosivesPermitAmendment.find_by_explosives_permit_amendment_guid(str(explosives_permit_amendment_guid))
assert explosives_permit_amendment.explosives_permit_amendment_guid == explosives_permit_amendment_guid

def test_explosives_permit_amendment_find_by_explosives_permit_id(db_session):
explosives_permit_amendment = ExplosivesPermitAmendmentFactory()
explosives_permit_id = explosives_permit_amendment.explosives_permit_id
explosives_permit_amendments = ExplosivesPermitAmendment.find_by_explosives_permit_id(explosives_permit_id)
assert any(amendment.explosives_permit_id == explosives_permit_id for amendment in explosives_permit_amendments)

0 comments on commit a417e93

Please sign in to comment.