remove attend routes and handlers
This commit is contained in:
parent
212b18a47a
commit
80b9b20241
3 changed files with 49 additions and 83 deletions
49
requirements.txt
Normal file
49
requirements.txt
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
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
|
||||||
|
celery==5.3.6
|
||||||
|
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-SocketIO==5.3.6
|
||||||
|
Flask-SQLAlchemy==3.1.1
|
||||||
|
Flask-Testing==0.8.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
|
||||||
|
python-socketio==5.11.0
|
||||||
|
pytz==2023.3.post1
|
||||||
|
simple-websocket==1.0.0
|
||||||
|
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,21 +67,3 @@ 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,71 +72,6 @@ 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