Skip to content

Commit

Permalink
Fishchimp/feature/delete unavailability (#205)
Browse files Browse the repository at this point in the history
## Describe your changes
Slight improvement to the delete unavailability method

considerations:
1. The remove_event method is already a soft delete, which aligns with
industry practices
2. The delete method is already quite straightforward
3. Futureproofing ideas include changing the return type of remove_event
into an enum to differentiate between a failed "mark event as deleted"
and a "cannot find such event to delete".
4. ultimately decided to just add logging for better debugging if any
issues were to arise

## Issue ticket number and link
Issue [FE-187](https://fireapp-emergiq-2024.atlassian.net/browse/FE-187)

---------

Co-authored-by: Muhammad Hafizh Hasyim <[email protected]>
Co-authored-by: Tai Ha <[email protected]>
  • Loading branch information
3 people authored Apr 13, 2024
1 parent 7428461 commit 19e3373
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions controllers/v2/unavailability/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from controllers.v2.v2_blueprint import v2_api
import logging
from exception import EventNotFoundError, InvalidArgumentError

edit_parser = reqparse.RequestParser()
edit_parser.add_argument("title", type=str)
edit_parser.add_argument("start", type=inputs.datetime_from_iso8601)
Expand Down Expand Up @@ -42,16 +43,18 @@ def put(self, user_id, event_id):
@requires_auth
@is_user_or_has_role(None, UserType.ROOT_ADMIN)
def delete(self, user_id, event_id):
# logging is used for easier debugging
try:
success = self.event_repository.remove_event(user_id, event_id)
if success:
# If the event is successfully removed, return HTTP 200 OK.
logging.info(f"Soft deleted unavailability event {event_id} for user {user_id}.")
return {"message": "Unavailability event removed successfully."}, 200
else:
# If the event does not exist or could not be removed, return HTTP 404 Not Found.
return {"message": "Unavailability event not found."}, 404
logging.warning(
f"Attempted to remove non-existing or already removed event {event_id} for user {user_id}.")
return {"message": "Unavailability event not found or already removed."}, 404
except Exception as e:
# HTTP 500 Internal Server Error
logging.error(f"Error during deletion of event {event_id} for user {user_id}: {str(e)}")
return {"message": "Internal server error", "error": str(e)}, 500


Expand Down

0 comments on commit 19e3373

Please sign in to comment.