Compare commits
No commits in common. "573fbcc7ea4d0da590dd3e996fcf9c954764771b" and "212b18a47a53275df0d47bce0fc74021f9123631" have entirely different histories.
573fbcc7ea
...
212b18a47a
4 changed files with 83 additions and 49 deletions
|
@ -65,9 +65,4 @@ update, delete, and be reminded of events with additional advanced features.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# how to run?
|
|
||||||
- pip install -r requirements.txt
|
|
||||||
- flask db upgrade
|
|
||||||
- flask run
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
alembic==1.13.1
|
|
||||||
amqp==5.2.0
|
|
||||||
aniso8601==9.0.1
|
|
||||||
APScheduler==3.10.4
|
|
||||||
bcrypt==4.1.2
|
|
||||||
bidict==0.22.1
|
|
||||||
billiard==4.2.0
|
|
||||||
blinker==1.7.0
|
|
||||||
click==8.1.7
|
|
||||||
click-didyoumean==0.3.0
|
|
||||||
click-plugins==1.1.1
|
|
||||||
click-repl==0.3.0
|
|
||||||
Flask==3.0.0
|
|
||||||
Flask-APScheduler==1.13.1
|
|
||||||
Flask-Bcrypt==1.0.1
|
|
||||||
Flask-JWT-Extended==4.6.0
|
|
||||||
Flask-Migrate==4.0.5
|
|
||||||
Flask-RESTful==0.3.10
|
|
||||||
Flask-SQLAlchemy==3.1.1
|
|
||||||
greenlet==3.0.3
|
|
||||||
h11==0.14.0
|
|
||||||
iniconfig==2.0.0
|
|
||||||
itsdangerous==2.1.2
|
|
||||||
Jinja2==3.1.2
|
|
||||||
kombu==5.3.4
|
|
||||||
Mako==1.3.0
|
|
||||||
MarkupSafe==2.1.3
|
|
||||||
packaging==23.2
|
|
||||||
pluggy==1.3.0
|
|
||||||
prompt-toolkit==3.0.43
|
|
||||||
PyJWT==2.8.0
|
|
||||||
pytest==7.4.4
|
|
||||||
python-dateutil==2.8.2
|
|
||||||
python-engineio==4.8.2
|
|
||||||
pytz==2023.3.post1
|
|
||||||
six==1.16.0
|
|
||||||
SQLAlchemy==2.0.25
|
|
||||||
typing_extensions==4.9.0
|
|
||||||
tzdata==2023.4
|
|
||||||
tzlocal==5.2
|
|
||||||
vine==5.1.0
|
|
||||||
wcwidth==0.2.12
|
|
||||||
Werkzeug==3.0.1
|
|
||||||
wsproto==1.2.0
|
|
|
@ -67,3 +67,21 @@ def delete_event(event_id):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'error': str(e)}), 500
|
return jsonify({'error': str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
|
@eventRoutes.route('/<int:event_id>/attend', methods=['POST'])
|
||||||
|
@authenticate_user
|
||||||
|
def attend_event(event_id):
|
||||||
|
response = EventService.attend_event(event_id)
|
||||||
|
if 'error' in response:
|
||||||
|
return jsonify({'error': response['error']}), 400
|
||||||
|
|
||||||
|
return jsonify({'message': response['message']}), 200
|
||||||
|
|
||||||
|
@eventRoutes.route('/<int:event_id>/unattend', methods=['POST'])
|
||||||
|
@authenticate_user
|
||||||
|
def unattend_event(event_id):
|
||||||
|
response = EventService.unattend_event(event_id)
|
||||||
|
if 'error' in response:
|
||||||
|
return jsonify({'error': response['error']}), 400
|
||||||
|
|
||||||
|
return jsonify({'message': response['message']}), 200
|
|
@ -72,6 +72,71 @@ class EventService:
|
||||||
return event
|
return event
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def attend_event(event_id):
|
||||||
|
user_id = g.user_id
|
||||||
|
event = Event.query.filter(
|
||||||
|
Event.id == event_id,
|
||||||
|
Event.duedate > datetime.now(),
|
||||||
|
Event.deleted == False
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if not event:
|
||||||
|
return {'error': 'Event not found or already passed'}
|
||||||
|
|
||||||
|
# Check if the user is already associated with the event
|
||||||
|
is_already_attending = UserEventAssociation.query.filter_by(
|
||||||
|
user_id=user_id,
|
||||||
|
event_id=event_id
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if is_already_attending:
|
||||||
|
return {'error': 'User already attending this event'}
|
||||||
|
|
||||||
|
# Add the user to the event
|
||||||
|
user_event_association = UserEventAssociation(
|
||||||
|
user_id=user_id,
|
||||||
|
event_id=event_id
|
||||||
|
)
|
||||||
|
db.session.add(user_event_association)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return {'message': 'User successfully added to the event'}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def unattend_event(event_id):
|
||||||
|
user_id = g.user_id # Assuming user_id is stored in Flask's global g object
|
||||||
|
# Check if the event is valid and in the future
|
||||||
|
event = Event.query.filter(
|
||||||
|
Event.id == event_id,
|
||||||
|
Event.duedate > datetime.now(),
|
||||||
|
Event.deleted == False
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if not event:
|
||||||
|
return {'error': 'Event not found or already passed'}
|
||||||
|
|
||||||
|
user_event_association = UserEventAssociation.query.filter_by(
|
||||||
|
user_id=user_id,
|
||||||
|
event_id=event_id
|
||||||
|
).first()
|
||||||
|
|
||||||
|
|
||||||
|
if not user_event_association:
|
||||||
|
return {'error': 'User not attending this event'}
|
||||||
|
|
||||||
|
user = UserService.get_user_by_id(user_id)
|
||||||
|
if not user:
|
||||||
|
return {'error': 'User not found'}
|
||||||
|
|
||||||
|
|
||||||
|
db.session.delete(user_event_association)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return {'message': 'User successfully removed from the event'}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_upcomming_events():
|
def get_all_upcomming_events():
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
|
Loading…
Reference in a new issue