Skip to content

Commit

Permalink
Request Endpoint (#209)
Browse files Browse the repository at this point in the history
* fixes

* Request to omit obscure section

* remove errant nbsp

* checkbox fixes

* WIP - Add Request to omit endpoint, tests outstanding

* add postman test

* fix postman tests

* add tests

* fix lint

* add id field to request

* remove exception handling that was only removed to debug
  • Loading branch information
BrandonSharratt authored Oct 9, 2024
1 parent d25b509 commit c1afdea
Show file tree
Hide file tree
Showing 19 changed files with 1,165 additions and 1 deletion.
84 changes: 84 additions & 0 deletions btr-api/migrations/versions/20241009_1344_3b039edc1404_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""empty message
Revision ID: 3b039edc1404
Revises: 8d8279a86def
Create Date: 2024-10-09 13:44:54.558111
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '3b039edc1404'
down_revision = '8d8279a86def'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('request',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('uuid', sa.Uuid(), nullable=False),
sa.Column('full_name', sa.String(), nullable=False),
sa.Column('email', sa.String(), nullable=False),
sa.Column('birthdate', sa.Date(), nullable=False),
sa.Column('business_identifier', sa.String(), nullable=False),
sa.Column('information_to_omit', sa.Enum('ALL', 'FULL_NAME', 'BIRTH_YEAR', 'CITIZENSHIP_PR', name='informationtoomittype'), nullable=False),
sa.Column('individual_at_risk', sa.Enum('SI', 'HOUSEHOLD', name='individualatrisk'), nullable=False),
sa.Column('reasons', sa.String(), nullable=False),
sa.Column('completing_party', sa.Enum('SI', 'REPRESENTATIVE', name='completingparty'), nullable=False),
sa.Column('completing_name', sa.String(), nullable=False),
sa.Column('completing_email', sa.String(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.Column('version', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sqlite_autoincrement=True
)
with op.batch_alter_table('request', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_request_business_identifier'), ['business_identifier'], unique=False)
batch_op.create_index(batch_op.f('ix_request_uuid'), ['uuid'], unique=False)

op.create_table('request_history',
sa.Column('id', sa.Integer(), autoincrement=False, nullable=False),
sa.Column('uuid', sa.Uuid(), autoincrement=False, nullable=False),
sa.Column('full_name', sa.String(), autoincrement=False, nullable=False),
sa.Column('email', sa.String(), autoincrement=False, nullable=False),
sa.Column('birthdate', sa.Date(), autoincrement=False, nullable=False),
sa.Column('business_identifier', sa.String(), autoincrement=False, nullable=False),
sa.Column('information_to_omit', sa.Enum('ALL', 'FULL_NAME', 'BIRTH_YEAR', 'CITIZENSHIP_PR', name='informationtoomittype'), autoincrement=False, nullable=False),
sa.Column('individual_at_risk', sa.Enum('SI', 'HOUSEHOLD', name='individualatrisk'), autoincrement=False, nullable=False),
sa.Column('reasons', sa.String(), autoincrement=False, nullable=False),
sa.Column('completing_party', sa.Enum('SI', 'REPRESENTATIVE', name='completingparty'), autoincrement=False, nullable=False),
sa.Column('completing_name', sa.String(), autoincrement=False, nullable=False),
sa.Column('completing_email', sa.String(), autoincrement=False, nullable=False),
sa.Column('created_at', sa.DateTime(), autoincrement=False, nullable=False),
sa.Column('updated_at', sa.DateTime(), autoincrement=False, nullable=False),
sa.Column('version', sa.Integer(), autoincrement=False, nullable=False),
sa.Column('changed', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id', 'version'),
sqlite_autoincrement=True
)
with op.batch_alter_table('request_history', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_request_history_business_identifier'), ['business_identifier'], unique=False)
batch_op.create_index(batch_op.f('ix_request_history_uuid'), ['uuid'], unique=False)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###

with op.batch_alter_table('request_history', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_request_history_uuid'))
batch_op.drop_index(batch_op.f('ix_request_history_business_identifier'))

op.drop_table('request_history')
with op.batch_alter_table('request', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_request_uuid'))
batch_op.drop_index(batch_op.f('ix_request_business_identifier'))

op.drop_table('request')
# ### end Alembic commands ###
3 changes: 3 additions & 0 deletions btr-api/src/btr_api/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
from .log_level import LogLevel
from .redaction_types import RedactionType
from .user_types import UserType
from .completing_party import CompletingParty
from .individual_at_risk import IndividualAtRisk
from .information_to_omit_type import InformationToOmitType
42 changes: 42 additions & 0 deletions btr-api/src/btr_api/enums/completing_party.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright © 2024 Province of British Columbia
#
# Licensed under the BSD 3 Clause License, (the "License");
# you may not use this file except in compliance with the License.
# The template for the license can be found here
# https://opensource.org/license/bsd-3-clause/
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided that the
# following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
"""Enum for email type."""
from btr_api.common.enum import BaseEnum, auto


class CompletingParty(BaseEnum):
"""Enum for the email type."""

SI = auto()
REPRESENTATIVE = auto()
42 changes: 42 additions & 0 deletions btr-api/src/btr_api/enums/individual_at_risk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright © 2024 Province of British Columbia
#
# Licensed under the BSD 3 Clause License, (the "License");
# you may not use this file except in compliance with the License.
# The template for the license can be found here
# https://opensource.org/license/bsd-3-clause/
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided that the
# following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
"""Enum for email type."""
from btr_api.common.enum import BaseEnum, auto


class IndividualAtRisk(BaseEnum):
"""Enum for the email type."""

SI = auto()
HOUSEHOLD = auto()
44 changes: 44 additions & 0 deletions btr-api/src/btr_api/enums/information_to_omit_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright © 2024 Province of British Columbia
#
# Licensed under the BSD 3 Clause License, (the "License");
# you may not use this file except in compliance with the License.
# The template for the license can be found here
# https://opensource.org/license/bsd-3-clause/
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided that the
# following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
"""Enum for email type."""
from btr_api.common.enum import BaseEnum, auto


class InformationToOmitType(BaseEnum):
"""Enum for the email type."""

ALL = auto()
FULL_NAME = auto()
BIRTH_YEAR = auto()
CITIZENSHIP_PR = auto()
2 changes: 2 additions & 0 deletions btr-api/src/btr_api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from .submission import SubmissionType
from .user import User
from .user import UserRoles
from .request import Request


__all__ = (
Expand All @@ -49,4 +50,5 @@
"SubmissionType",
"User",
"UserRoles",
"Request",
)
150 changes: 150 additions & 0 deletions btr-api/src/btr_api/models/request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Copyright © 2024 Province of British Columbia
#
# Licensed under the BSD 3 Clause License, (the "License");
# you may not use this file except in compliance with the License.
# The template for the license can be found here
# https://opensource.org/license/bsd-3-clause/
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided that the
# following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
"""Manages Request (to omit) data."""
from __future__ import annotations

import uuid
from datetime import date, datetime

from sqlalchemy.orm import Mapped, mapped_column
from sql_versioning import Versioned

from btr_api.enums import InformationToOmitType
from btr_api.enums import IndividualAtRisk
from btr_api.enums import CompletingParty

from .base import Base


class Request(Versioned, Base):
"""Stores request (to omit) data."""

__tablename__ = 'request'
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
uuid: Mapped[uuid.UUID] = mapped_column(index=True)
full_name: Mapped[str] = mapped_column(nullable=False)
email: Mapped[str] = mapped_column(nullable=False)
birthdate: Mapped[date] = mapped_column(nullable=False)
business_identifier: Mapped[str] = mapped_column(nullable=False, index=True)
information_to_omit: Mapped[InformationToOmitType] = mapped_column(nullable=False)
individual_at_risk: Mapped[IndividualAtRisk] = mapped_column(nullable=False)
reasons: Mapped[str] = mapped_column(nullable=False)
completing_party: Mapped[CompletingParty] = mapped_column(nullable=False)
completing_name: Mapped[str] = mapped_column(nullable=False)
completing_email: Mapped[str] = mapped_column(nullable=False)
created_at: Mapped[datetime] = mapped_column(nullable=False, default=datetime.now())
updated_at: Mapped[datetime] = mapped_column(nullable=False, default=datetime.now())

def __init__(self, data):
self.uuid = uuid.uuid4()
self.full_name = data['fullName']
self.email = data['email']
self.birthdate = data['birthdate']
self.business_identifier = data['businessIdentifier']
self.information_to_omit = data['informationToOmit']
self.individual_at_risk = data['individualAtRisk']
self.reasons = data['reasons']
self.completing_party = data['completingParty']
self.completing_name = data['completingName']
self.completing_email = data['completingEmail']

@classmethod
def find_by_uuid(cls, request_id: int) -> Request | None:
"""Return the person by id."""
return cls.query.filter_by(uuid=request_id).one_or_none()

@classmethod
def __setitem__(cls, key, value):
match key:
case 'id':
cls.id = value
case 'uuid':
cls.uuid = value
case 'email':
cls.email = value
case 'birthdate':
cls.birthdate = value
case 'reasons':
cls.reasons = value
case 'fullName':
print('hi')
print(value)
print(cls.full_name)
cls.full_name = value
print('hi2 ' + value + " " + cls.full_name)
case 'businessIdentifier':
cls.business_identifier = value
case 'informationToOmit':
cls.information_to_omit = value
case 'individualAtRisk':
cls.individual_at_risk = value
case 'completingParty':
cls.completing_party = value
case 'completingEmail':
cls.completing_email = value
case 'completingName':
cls.completing_name = value
case 'createdAt':
cls.created_at = value
case 'updatedAt':
cls.updated_at = value


class RequestSerializer:
"""Serializer for requests. Can convert to dict, string from request model. """

@staticmethod
def to_str(request: Request):
"""Return string representation of request model."""
return str(RequestSerializer.to_dict(request))

@staticmethod
def to_dict(request: Request) -> dict:
"""Return the request class as a dict for response purposes."""
return {
'id': request.id,
'uuid': request.uuid,
'fullName': request.full_name,
'email': request.email,
'birthdate': request.birthdate,
'businessIdentifier': request.business_identifier,
'informationToOmit': request.information_to_omit,
'individualAtRisk': request.individual_at_risk,
'reasons': request.reasons,
'completingParty': request.completing_party,
'completingEmail': request.completing_email,
'completingName': request.completing_name,
'createdAt': request.created_at.isoformat(),
'updatedAt': request.updated_at.isoformat(),
}
Loading

0 comments on commit c1afdea

Please sign in to comment.