Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fishchimp/feature/delete unavailability #205

Merged
merged 3 commits into from
Apr 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading