Skip to content

Commit

Permalink
adding soft delete in now_submissions document table
Browse files Browse the repository at this point in the history
  • Loading branch information
asinn134 committed Oct 6, 2023
1 parent c4c0e72 commit ae00817
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE
now_submissions.document
ADD
COLUMN IF NOT EXISTS deleted_ind boolean DEFAULT false NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from app.api.now_applications.models.now_application_document_identity_xref import NOWApplicationDocumentIdentityXref
from app.api.utils.custom_reqparser import CustomReqparser
from app.api.mines.response_models import MINE_DOCUMENT_MODEL
from app.api.now_submissions.models.document import Document


class NOWApplicationDocumentUploadResource(Resource, UserMixin):
Expand Down Expand Up @@ -83,8 +84,8 @@ class NOWApplicationDocumentResource(Resource, UserMixin):
@requires_role_edit_permit
def delete(self, application_guid, mine_document_guid):
mine_document = MineDocument.find_by_mine_document_guid(mine_document_guid)
now_app_doc_xref_exists = mine_document.now_application_document_xref is not None
now_app_doc_id_xref_exists = mine_document.now_application_document_identity_xref is not None
now_app_doc_xref_exists = mine_document and mine_document.now_application_document_xref is not None
now_app_doc_id_xref_exists = mine_document and mine_document.now_application_document_identity_xref is not None

if not mine_document or (now_app_doc_xref_exists
and application_guid != str(
Expand All @@ -106,6 +107,13 @@ def delete(self, application_guid, mine_document_guid):
if now_app_doc_xref_exists:
mine_document.now_application_document_xref.delete(True)
elif now_app_doc_id_xref_exists:
now_submission_document = Document.find_by_messageid_and_filename(
mine_document.now_application_document_identity_xref.messageid,
mine_document.now_application_document_identity_xref.filename
)

if now_submission_document is not None:
now_submission_document.delete(True)
mine_document.now_application_document_identity_xref.delete(True)

return None, 204
Expand Down
13 changes: 10 additions & 3 deletions services/core-api/app/api/now_submissions/models/document.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from sqlalchemy.schema import FetchedValue

from app.api.utils.models_mixins import Base
from app.api.utils.models_mixins import Base, SoftDeleteMixin
from app.extensions import db
from sqlalchemy.dialects.postgresql import UUID
from app.api.constants import *


class Document(Base):
class Document(SoftDeleteMixin, Base):
__tablename__ = "document"
__table_args__ = {"schema": "now_submissions"}
_edit_groups = [NOW_APPLICATION_EDIT_GROUP]
Expand All @@ -23,4 +23,11 @@ def __repr__(self):

@classmethod
def find_by_id(cls, id):
return cls.query.filter_by(id=id).one_or_none()
return cls.query.filter_by(id=id).one_or_none()

@classmethod
def find_by_messageid_and_filename(cls, messageid, filename):
return cls.query.filter_by(messageid=messageid, filename=filename).first()

def delete(self, commit=True):
super(Document, self).delete(commit)

0 comments on commit ae00817

Please sign in to comment.