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

[Issue #3536] Add saved opportunity notifications to backend job #3639

Merged

Conversation

mikehgrantsgov
Copy link
Collaborator

@mikehgrantsgov mikehgrantsgov commented Jan 24, 2025

Summary

Fixes #3536

Time to review: 15 mins

Changes proposed

Add last_notified_at to user_saved_opportunity
Collect opportunity notifications, log them out and test.

Context for reviewers

Can be merged, now that #3527 is wrapped up.

Additional information

See attached unit tests

mikehgrantsgov and others added 30 commits January 17, 2025 11:19
Co-authored-by: Michael Chouinard <[email protected]>
Co-authored-by: Michael Chouinard <[email protected]>
Co-authored-by: Michael Chouinard <[email protected]>
Comment on lines +32 to +34
log_records = [r for r in caplog.records if "Would send notification to user" in r.message]
assert len(log_records) == 1
extra = log_records[0].__dict__
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want tests that are a bit less log-focused at the moment, I did add the notification table which we'll use as a sort of auditing table. Could start populating that with something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some new tests here to and adding logs in generate_notifications.py

Opportunity,
UserSavedOpportunity.opportunity_id == Opportunity.opportunity_id,
)
.where(Opportunity.updated_at > UserSavedOpportunity.last_notified_at)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be compared against the timestamp from the updated_at column in the opportunity change log table from your other PR?

Copy link
Collaborator Author

@mikehgrantsgov mikehgrantsgov Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this, thanks

Comment on lines 64 to 67
select(User.user_id, UserSavedOpportunity.opportunity_id)
.join(
UserSavedOpportunity,
User.user_id == UserSavedOpportunity.user_id,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if this was select(UserSavedOpportunity)... with similar joins. You'd avoid needing to use mappings/specific columns since the UserSavedOpportunity record is the user_id + opportunity_id.

We should make the user_notification_map opportunity IDs instead just be this class object. Might also simplify the updates later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't totally follow the second part of this comment, but take a look and let me know what you think. I think the queries are simpler this way and I think corresponds to what you're going after.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you adjusted it like I was thinking

Base automatically changed from mikehgrantsgov/3527-modify-load-opp-logic-never-delete to main January 27, 2025 16:58
chouinar
chouinar previously approved these changes Jan 28, 2025
Copy link
Collaborator

@chouinar chouinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just adding an idea about a small TODO you had

Comment on lines 114 to 120
# Create notification log entry
# TODO: Use enum for notification reason?
notification_log = UserNotificationLog(
user_id=user_id,
notification_reason="opportunity_updates",
notification_sent=True,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the notification reason, I wasn't sure how notifications might evolve over time so left it pretty freeform. For this PR and the later one to add notifications for search, I'd probably just suggest adding some constants at the top of the file like:

class NotificationConstants:
     OPPORTUNITY_UPDATES = "opportunity_updates"

At least organizes it slightly kinda like an enum

chouinar
chouinar previously approved these changes Jan 28, 2025
@mikehgrantsgov mikehgrantsgov merged commit 0dd0466 into main Jan 29, 2025
@mikehgrantsgov mikehgrantsgov deleted the mikehgrantsgov/3536-add-saved-notifications-to-job branch January 29, 2025 20:35
DavidDudas-Intuitial pushed a commit that referenced this pull request Feb 7, 2025
## Summary
Fixes #3536

### Time to review: 15 mins

## Changes proposed
Add `last_notified_at` to `user_saved_opportunity`
Collect opportunity notifications, log them out and test.

## Context for reviewers
Can be merged, now that #3527 is wrapped up. 

## Additional information
See attached unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add saved opportunity notifications to backend job
3 participants