Skip to content

Commit

Permalink
Remove address from individual requests and instead use ASP address (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shahanneda authored Jun 4, 2024
1 parent 91eacf2 commit ae41d22
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 93 deletions.
9 changes: 0 additions & 9 deletions backend/app/graphql/meal_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class MealRequestResponse(graphene.ObjectType):
requestor = graphene.Field(User)
status = graphene.Field(graphene.Enum.from_enum(MealStatus), required=True)
drop_off_datetime = graphene.DateTime()
drop_off_location = graphene.String()
meal_info = graphene.Field(MealInfoResponse)
onsite_contacts = graphene.List(OnsiteContact)
date_created = graphene.DateTime()
Expand All @@ -71,7 +70,6 @@ class Arguments:

meal_info = MealTypeInput(required=True)
drop_off_time = graphene.Time(required=True)
drop_off_location = graphene.String(required=True)
delivery_instructions = graphene.String(default_value=None)
onsite_contacts = graphene.List(graphene.String, default_value=[])

Expand All @@ -85,7 +83,6 @@ def mutate(
request_dates,
meal_info,
drop_off_time,
drop_off_location,
delivery_instructions,
onsite_contacts,
):
Expand All @@ -94,7 +91,6 @@ def mutate(
request_dates=request_dates,
meal_info=meal_info,
drop_off_time=drop_off_time,
drop_off_location=drop_off_location,
delivery_instructions=delivery_instructions,
onsite_contacts=onsite_contacts,
)
Expand Down Expand Up @@ -160,7 +156,6 @@ class Arguments:
requestor_id = graphene.ID(required=False)
drop_off_datetime = graphene.DateTime(required=False)
meal_info = MealTypeInput()
drop_off_location = graphene.String()
delivery_instructions = graphene.String()
onsite_contacts = graphene.List(graphene.String)

Expand All @@ -174,15 +169,13 @@ def mutate(
requestor_id: str,
drop_off_datetime=None,
meal_info=None,
drop_off_location=None,
delivery_instructions=None,
onsite_contacts=None,
):
result = services["meal_request_service"].update_meal_request(
requestor_id=requestor_id,
meal_info=meal_info,
drop_off_datetime=drop_off_datetime,
drop_off_location=drop_off_location,
delivery_instructions=delivery_instructions,
onsite_contacts=onsite_contacts,
meal_request_id=meal_request_id,
Expand Down Expand Up @@ -371,7 +364,6 @@ def resolve_getMealRequestsByRequestorId(
requestor=meal_request_dto.requestor,
status=meal_request_dto.status,
drop_off_datetime=meal_request_dto.drop_off_datetime,
drop_off_location=meal_request_dto.drop_off_location,
meal_info=meal_request_dto.meal_info,
onsite_contacts=meal_request_dto.onsite_contacts,
date_created=meal_request_dto.date_created,
Expand Down Expand Up @@ -425,7 +417,6 @@ def resolve_getMealRequestsByDonorId(
requestor=meal_request_dto.requestor,
status=meal_request_dto.status,
drop_off_datetime=meal_request_dto.drop_off_datetime,
drop_off_location=meal_request_dto.drop_off_location,
meal_info=meal_request_dto.meal_info,
onsite_contacts=meal_request_dto.onsite_contacts,
date_created=meal_request_dto.date_created,
Expand Down
1 change: 0 additions & 1 deletion backend/app/models/meal_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class MealRequest(mg.Document):
)

drop_off_datetime = mg.DateTimeField(required=True)
drop_off_location = mg.StringField(required=True)
meal_info = mg.EmbeddedDocumentField(MealInfo, required=True)

# https://docs.mongoengine.org/apireference.html#mongoengine.fields.ReferenceField
Expand Down
5 changes: 0 additions & 5 deletions backend/app/resources/meal_request_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __init__(
requestor,
status,
drop_off_datetime,
drop_off_location,
meal_info,
onsite_contacts,
date_created,
Expand All @@ -28,7 +27,6 @@ def __init__(
self.requestor = requestor
self.status = status
self.drop_off_datetime = drop_off_datetime
self.drop_off_location = drop_off_location
self.meal_info = meal_info
self.onsite_contacts = onsite_contacts
self.date_created = date_created
Expand Down Expand Up @@ -68,9 +66,6 @@ def validate(self):
"The drop_off_datetime supplied is not a datetime object."
)

if type(self.drop_off_location) is not str:
error_list.append("The drop_off_location supplied is not a string.")

validate_meal_info(self.meal_info, error_list)

for i, staff in enumerate(self.onsite_contacts):
Expand Down
22 changes: 10 additions & 12 deletions backend/app/services/implementations/meal_request_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def create_meal_request(
request_dates,
meal_info,
drop_off_time,
drop_off_location,
delivery_instructions,
onsite_contacts: List[str],
):
Expand Down Expand Up @@ -68,7 +67,6 @@ def create_meal_request(
drop_off_datetime=datetime.combine(
request_date, drop_off_time, timezone.utc
),
drop_off_location=drop_off_location,
delivery_instructions=delivery_instructions,
onsite_contacts=onsite_contacts,
)
Expand All @@ -92,7 +90,6 @@ def update_meal_request(
requestor_id,
meal_info,
drop_off_datetime,
drop_off_location,
delivery_instructions,
onsite_contacts,
meal_request_id,
Expand All @@ -115,9 +112,6 @@ def update_meal_request(
dietary_restrictions=meal_info.dietary_restrictions,
)

if drop_off_location is not None:
original_meal_request.drop_off_location = drop_off_location

if delivery_instructions is not None:
original_meal_request.delivery_instructions = delivery_instructions

Expand Down Expand Up @@ -194,9 +188,11 @@ def commit_to_meal_request(
meal_requestor_id = meal_request.requestor.id
meal_requestor = User.objects(id=meal_requestor_id).first()

self.send_donor_commit_email(meal_request, donor.info.email)
self.send_donor_commit_email(
meal_request, donor.info.email, meal_requestor
)
self.send_requestor_commit_email(
meal_request, meal_requestor.info.email
meal_request, meal_requestor.info.email, meal_requestor
)

meal_request.donation_info = DonationInfo(
Expand Down Expand Up @@ -366,7 +362,7 @@ def get_meal_requests_by_ids(self, ids: str) -> List[MealRequestDTO]:

return meal_request_dtos

def send_donor_commit_email(self, meal_request, email):
def send_donor_commit_email(self, meal_request, email, meal_requestor):
if not self.email_service:
error_message = """
Attempted to call committed_to_meal_request but this
Expand All @@ -376,10 +372,11 @@ def send_donor_commit_email(self, meal_request, email):
raise Exception(error_message)

try:
address = meal_requestor.info.organization_address
email_body = EmailService.read_email_template(
"email_templates/committed_to_meal_request.html"
).format(
dropoff_location=meal_request.drop_off_location,
dropoff_location=address,
dropoff_time=meal_request.drop_off_datetime,
num_meals=meal_request.meal_info.portions,
)
Expand All @@ -393,7 +390,7 @@ def send_donor_commit_email(self, meal_request, email):
)
raise e

def send_requestor_commit_email(self, meal_request, email):
def send_requestor_commit_email(self, meal_request, email, meal_requestor):
if not self.email_service:
error_message = """
Attempted to call meal_request_success but this
Expand All @@ -403,10 +400,11 @@ def send_requestor_commit_email(self, meal_request, email):
raise Exception(error_message)

try:
address = meal_requestor.info.organization_address
email_body = EmailService.read_email_template(
"email_templates/meal_request_success.html"
).format(
dropoff_location=meal_request.drop_off_location,
dropoff_location=address,
dropoff_time=meal_request.drop_off_datetime,
num_meals=meal_request.meal_info.portions,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def get_meal_requests_one_day_ago(self):

def send_email(self, email, meal_request, template_file_path, subject_line):
try:
address = meal_request.requestor.info.organization_address
email_body = EmailService.read_email_template(template_file_path).format(
dropoff_location=meal_request.drop_off_location,
dropoff_location=address,
dropoff_time=meal_request.drop_off_datetime,
num_meals=meal_request.meal_info.portions,
)
Expand Down
6 changes: 2 additions & 4 deletions backend/app/services/interfaces/meal_request_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def create_meal_request(
request_dates,
meal_info,
drop_off_time,
drop_off_location,
delivery_instructions,
onsite_contacts: List[str],
):
Expand All @@ -36,7 +35,6 @@ def update_meal_request(
requestor_id: str,
meal_info,
drop_off_datetime,
drop_off_location,
delivery_instructions,
onsite_contacts: List[str],
meal_request_id,
Expand Down Expand Up @@ -148,7 +146,7 @@ def get_meal_requests_by_donor_id(
pass

@abstractmethod
def send_donor_commit_email(self, meal_request_id, email):
def send_donor_commit_email(self, meal_request_id, email, meal_requestor):
"""
Sends an email to the user with the given email, notifying them that they have committed to a meal request
:param meal_request_id: the id of the meal request
Expand All @@ -157,7 +155,7 @@ def send_donor_commit_email(self, meal_request_id, email):
"""

@abstractmethod
def send_requestor_commit_email(self, meal_request_id, email):
def send_requestor_commit_email(self, meal_request_id, email, meal_requestor):
"""
Sends an email to the user with the given email, notifying them that their meal request was successful
:param meal_request_id: the id of the meal request
Expand Down
1 change: 0 additions & 1 deletion backend/tests/graphql/mock_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@
MOCK_MEALREQUEST1_SNAKE = {
"status": "Open",
"drop_off_datetime": "2025-03-31T00:00:00",
"drop_off_location": "Test location",
"meal_info": {
"portions": 10,
"dietary_restrictions": "Vegan",
Expand Down
Loading

0 comments on commit ae41d22

Please sign in to comment.