2024-01-08 20:03:51 +00:00
|
|
|
# this Class is for the scheduler
|
|
|
|
#this class will have a function that locates the upcomming events Using the Event service.
|
|
|
|
from services.EventService import EventService
|
2024-01-09 09:01:39 +00:00
|
|
|
from services.UserService import UserService
|
|
|
|
from models import UserEventAssociation, db
|
2024-01-08 20:03:51 +00:00
|
|
|
|
2024-01-09 08:23:57 +00:00
|
|
|
class EventNotifyerService:
|
2024-01-08 20:03:51 +00:00
|
|
|
def __init__(self):
|
|
|
|
pass
|
2024-01-09 09:01:39 +00:00
|
|
|
|
2024-01-09 08:25:38 +00:00
|
|
|
def notifyUpcommingEvents():
|
2024-01-09 09:01:39 +00:00
|
|
|
# this method will get the upcoming events from the event service
|
|
|
|
# foreach event, locate the users with the same location as the event but not the users that already been notifyed about the event
|
|
|
|
# foreach user, append to UserEventAssociation table that the user is been notified about the event
|
|
|
|
events = EventService.get_upcoming_events()
|
|
|
|
for event in events:
|
|
|
|
# locate users with the same location as the event but not the users that already been notifyed about the event (users with UserEventAssociation)
|
|
|
|
users = UserService.get_users_with_same_location_but_not_been_notifyed(event['location'])
|
|
|
|
if not users:
|
|
|
|
print("No user to notify")
|
|
|
|
continue
|
|
|
|
for user in users:
|
|
|
|
print("Found user to notify:", user)
|
|
|
|
if notify_user(user['email'], event):
|
|
|
|
user_event_association = UserEventAssociation(
|
|
|
|
user_id=user['id'],
|
|
|
|
event_id=event['id']
|
|
|
|
)
|
|
|
|
db.session.add(user_event_association)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
def notify_user(userEmail, event):
|
|
|
|
# send email to user is the email been sent, return true; otherwise, return false
|
|
|
|
return True
|
|
|
|
|
|
|
|
|