Skip to content

Commit

Permalink
modified the message
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiran Li committed Mar 11, 2024
1 parent 40cc8b9 commit 5e39923
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
20 changes: 10 additions & 10 deletions controllers/v2/unavailability/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

class SpecificVolunteerUnavailabilityV2(Resource):

#@requires_auth
#@is_user_or_has_role(None, UserType.ROOT_ADMIN)
@requires_auth
@is_user_or_has_role(None, UserType.ROOT_ADMIN)
def put(self, user_id, event_id):
args = edit_parser.parse_args()
with session_scope() as session:
Expand All @@ -29,8 +29,8 @@ def put(self, user_id, event_id):
else:
return {"message": "Unexpected Error Occurred"}, 400

#@requires_auth
#@is_user_or_has_role(None, UserType.ROOT_ADMIN)
@requires_auth
@is_user_or_has_role(None, UserType.ROOT_ADMIN)
def delete(self, user_id, event_id):
with session_scope() as session:
try:
Expand All @@ -48,19 +48,19 @@ def delete(self, user_id, event_id):

class VolunteerUnavailabilityV2(Resource):

#@requires_auth
#@marshal_with(volunteer_unavailability_time)
#@is_user_or_has_role(None, UserType.ROOT_ADMIN)
@requires_auth
@marshal_with(volunteer_unavailability_time)
@is_user_or_has_role(None, UserType.ROOT_ADMIN)
def get(self, user_id):
with session_scope() as session:
volunteer_unavailability_record = get_event(session, user_id)
if volunteer_unavailability_record is not None:
return volunteer_unavailability_record
else:
return jsonify({'userID': user_id, 'success': False}), 400
return {"message": "No unavailability record found."}, 400

#@requires_auth
#@is_user_or_has_role(None, UserType.ROOT_ADMIN)
@requires_auth
@is_user_or_has_role(None, UserType.ROOT_ADMIN)
def post(self, user_id):
try:
args = edit_parser.parse_args()
Expand Down
33 changes: 17 additions & 16 deletions repository/volunteer_unavailability_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,23 @@ def get_event(session, userId):
# only show the unavailability time that is end in the future
events = session.query(UnavailabilityTime).filter(
UnavailabilityTime.userId == userId, UnavailabilityTime.status == 1, UnavailabilityTime.end > now).all()
session.expunge_all()
event_records = []
for event in events:
# if the start time is earlier than now, then show from now to the end time
start_time = max(event.start, now)
event_record = {
"eventId": event.eventId,
"userId": event.userId,
"title": event.title,
"startTime": start_time.isoformat(),
"endTime": event.end.isoformat(),
"periodicity": event.periodicity
}
event_records.append(event_record)

return jsonify(event_records)
if events:
event_records = []
for event in events:
# if the start time is earlier than now, then show from now to the end time
start_time = max(event.start, now)
event_record = {
"eventId": event.eventId,
"userId": event.userId,
"title": event.title,
"startTime": start_time.isoformat(),
"endTime": event.end.isoformat(),
"periodicity": event.periodicity
}
event_records.append(event_record)
return jsonify(event_records)
else:
return None
except Exception as e:
logging.error(e)
return None

0 comments on commit 5e39923

Please sign in to comment.