Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17144 - updated changes for query, and json read #1448

Merged
merged 7 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/namex/VERSION.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.1.31'
__version__ = '1.1.32'
17 changes: 17 additions & 0 deletions api/namex/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,23 @@ def find_name_by_choice(cls, nr_id, choice):
name_by_choice = next((name for name in names if name.choice == choice), None)
return name_by_choice

@classmethod
def find_existing_name_by_user(cls, user_name_search_string, request_owner):
Rajandeep98 marked this conversation as resolved.
Show resolved Hide resolved
"""
Gets requests submited by user with given name choice in state draft
"""
existing_nr = db.session.query(Request). \
join(Applicant, and_(Applicant.nrId == Request.id)). \
filter(
Applicant.emailAddress == request_owner,
(Request.stateCd == 'DRAFT') | (Request.stateCd == 'PENDING_PAYMENT') ,
(Request.nameSearch == ('('+user_name_search_string+')')) | ( Request.nameSearch == user_name_search_string )). \
one_or_none()

if(existing_nr):
return True
return False

@classmethod
def validNRFormat(cls, nr):
"""NR should be of the format 'NR 1234567'"""
Expand Down
18 changes: 17 additions & 1 deletion api/namex/resources/name_requests/name_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from namex.services.name_request.name_request_state import get_nr_state_actions
from namex.services.name_request.utils import get_mapped_entity_and_action_code
from namex.services.name_request.exceptions import \
NameRequestException, InvalidInputError
NameRequestException, InvalidInputError, NameRequestIsAlreadySubmittedError
from namex.services.statistics.wait_time_statistics import WaitTimeStatsService

from .api_namespace import api
Expand Down Expand Up @@ -145,6 +145,22 @@ def post(self):
self.initialize()
nr_svc = self.nr_service

name_search_string = ""
user_email = ""
# user id
submitter=nr_svc.request_data.get("applicants")
Rajandeep98 marked this conversation as resolved.
Show resolved Hide resolved
for item, index in zip(submitter, range(len(submitter))):
user_email=item.get("emailAddress")

# collect submitted user data names choices
customer_data = nr_svc.request_names
# loop through the list of choices obtained
for item, index in zip(customer_data, range(len(customer_data))):
#concat them with format saving as namesearch
name_search_string += f'|{index + 1}{item.get("name")}{index + 1}|'
#if same user submitted the request of same name choices again raise exception otherwise continue creating nr
if(Request().find_existing_name_by_user(name_search_string,user_email)):
Rajandeep98 marked this conversation as resolved.
Show resolved Hide resolved
raise NameRequestIsAlreadySubmittedError()
# Create a new DRAFT name request
nr_model = nr_svc.create_name_request()

Expand Down
5 changes: 5 additions & 0 deletions api/namex/services/name_request/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,8 @@ def __init__(self, wrapped_err=None, message="Error getting user id."):
class VirtualWordConditionServiceError(NameRequestException):
def __init__(self, wrapped_err=None, message="Error initializing VirtualWordCondition Service."):
super().__init__(wrapped_err, message)

# exception raising for existing request by same name and by same user email
class NameRequestIsAlreadySubmittedError(NameRequestException):
def __init__(self, wrapped_err=None, message="The request with same name is already submitted."):
super().__init__(wrapped_err, message)