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

Subscribed email searches #170

Merged
merged 8 commits into from
Jul 31, 2024
Merged

Subscribed email searches #170

merged 8 commits into from
Jul 31, 2024

Conversation

KlaraK94
Copy link
Contributor

Added the endpoints for subscribing to email notifications for subscribed searches.
Added two migration files, one for adding columns for the receive_email in search_subscription and Search. And one for deleting all entries in the tables search and search_subscription.

Klara Krag added 2 commits July 26, 2024 14:44
@KlaraK94 KlaraK94 requested a review from mircealungu July 26, 2024 18:54
user = User.find_by_id(flask.g.user_id)
receive_email = True
SearchSubscription.update_receive_email(db_session, user, search, receive_email)
Search.update_receive_email(db_session, search_terms, receive_email)
Copy link
Member

Choose a reason for hiding this comment

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

I do not understand this. Why does Search have a receive_email attribute? It should only be the Subscription that knows about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added it to Search because you use search to show data in the UI. So if it is not added, I will not be able to see the changes made to the receive_email. Most endpoints use this, return json_result(search.as_dictionary()), they do not use search_subscription.

Copy link
Member

Choose a reason for hiding this comment

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

Ah! In that case we should really refactor the UI to use Subscription instead of Search. I already observed that we should do that in the PR for the Web, but I thought we can delay it for after Wednesday. But in this case we should prioritize this straight away.

Copy link
Member

Choose a reason for hiding this comment

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

Do you think you can do it, or should we try to do a brief pair-programming session this afternoon to fix this?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, we already have a meeting tomorrow @ 10am. We could use that too. But it might be a bit more than one hour.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would appreciate some help to fix this. Tomorrows meeting works fine for me, and I can do more than one hour.

Copy link
Member

Choose a reason for hiding this comment

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

let's do that then!

receive_email = False
SearchSubscription.update_receive_email(db_session, user, search, receive_email)

Search.update_receive_email(db_session, search_terms, receive_email)
Copy link
Member

Choose a reason for hiding this comment

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

this should also not be needed!

previous_day_datetime = current_datetime - datetime.timedelta(days=1)

for subscription in all_subscriptions:
for search in all_searches:
Copy link
Member

@mircealungu mircealungu Jul 29, 2024

Choose a reason for hiding this comment

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

you should be able to simply say subscription.search because the search is defined inside of the SearchSubscription class as a relationship! Thus, you don't have to iterate over all the searches to find the matching search. Just say subscriptio.search.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So like this instead?

for subscription in all_subscriptions:
articles = article_search_for_user(subscription.user_id, 2, subscription.search, page = 0)
new_articles_found = [article for article in articles if article.published > previous_day_datetime]

    if new_articles_found:
            user = User.find_by_id(subscription.user_id)
            send_mail_new_articles_search(user.email, search)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, use subscription.search. And also in your last line send_mail_new_articles_search(user.email, search) you'll probably have to use the same.

Copy link
Member

@mircealungu mircealungu left a comment

Choose a reason for hiding this comment

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

let's merge this!

@mircealungu mircealungu merged commit 0bc1c3f into master Jul 31, 2024
2 of 3 checks passed
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.

3 participants