From 6cf33976b383f48b747df8e2fb720d3eac66c357 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 24 Mar 2021 20:47:04 +0100 Subject: [PATCH] [events] Changed routes --- flaschengeist/plugins/events/__init__.py | 44 +++++++++---------- .../plugins/events/event_controller.py | 8 +++- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/flaschengeist/plugins/events/__init__.py b/flaschengeist/plugins/events/__init__.py index 91deac0..3e955df 100644 --- a/flaschengeist/plugins/events/__init__.py +++ b/flaschengeist/plugins/events/__init__.py @@ -17,7 +17,7 @@ from . import event_controller, permissions from . import models from ...utils.HTTP import no_content -schedule_bp = Blueprint("events", __name__, url_prefix="/schedule") +schedule_bp = Blueprint("events", __name__, url_prefix="/events") class EventPlugin(Plugin): @@ -42,8 +42,8 @@ def get_templates(current_session): def get_event_types(current_session, identifier=None): """Get EventType(s) - Route: ``/schedule/event-types`` | Method: ``GET`` - Route: ``/schedule/event-types/`` | Method: ``GET`` + Route: ``/events/event-types`` | Method: ``GET`` + Route: ``/events/event-types/`` | Method: ``GET`` Args: current_session: Session sent with Authorization Header @@ -64,7 +64,7 @@ def get_event_types(current_session, identifier=None): def new_event_type(current_session): """Create a new EventType - Route: ``/schedule/event-types`` | Method: ``POST`` + Route: ``/events/event-types`` | Method: ``POST`` POST-data: ``{name: string}`` @@ -86,7 +86,7 @@ def new_event_type(current_session): def modify_event_type(identifier, current_session): """Rename or delete an event type - Route: ``/schedule/event-types/`` | Method: ``PUT`` or ``DELETE`` + Route: ``/events/event-types/`` | Method: ``PUT`` or ``DELETE`` POST-data: (if renaming) ``{name: string}`` @@ -112,7 +112,7 @@ def modify_event_type(identifier, current_session): def get_job_types(current_session): """Get all JobTypes - Route: ``/schedule/job-types`` | Method: ``GET`` + Route: ``/events/job-types`` | Method: ``GET`` Args: current_session: Session sent with Authorization Header @@ -129,7 +129,7 @@ def get_job_types(current_session): def new_job_type(current_session): """Create a new JobType - Route: ``/schedule/job-types`` | Method: ``POST`` + Route: ``/events/job-types`` | Method: ``POST`` POST-data: ``{name: string}`` @@ -151,7 +151,7 @@ def new_job_type(current_session): def modify_job_type(type_id, current_session): """Rename or delete a JobType - Route: ``/schedule/job-types/`` | Method: ``PUT`` or ``DELETE`` + Route: ``/events/job-types/`` | Method: ``PUT`` or ``DELETE`` POST-data: (if renaming) ``{name: string}`` @@ -172,12 +172,12 @@ def modify_job_type(type_id, current_session): return "", NO_CONTENT -@schedule_bp.route("/events/", methods=["GET"]) +@schedule_bp.route("/", methods=["GET"]) @login_required() def get_event(event_id, current_session): """Get event by id - Route: ``/schedule/events/`` | Method: ``GET`` + Route: ``/events/`` | Method: ``GET`` Args: event_id: ID identifying the event @@ -190,7 +190,7 @@ def get_event(event_id, current_session): return jsonify(event) -@schedule_bp.route("/events", methods=["GET"]) +@schedule_bp.route("/", methods=["GET"]) @login_required() def get_filtered_events(current_session): begin = request.args.get("from") @@ -204,14 +204,14 @@ def get_filtered_events(current_session): return jsonify(event_controller.get_events(begin, end)) -@schedule_bp.route("/events//", methods=["GET"]) +@schedule_bp.route("//", methods=["GET"]) @schedule_bp.route("/events///", methods=["GET"]) @login_required() def get_events(current_session, year=datetime.now().year, month=datetime.now().month, day=None): """Get Event objects for specified date (or month or year), if nothing set then events for current month are returned - Route: ``/schedule/events[//[/]]`` | Method: ``GET`` + Route: ``/events[//[/]]`` | Method: ``GET`` Args: year (int, optional): year to query, defaults to current year @@ -256,12 +256,12 @@ def _add_job(event, data): event_controller.add_job(event, job_type, required_services, start, end, comment=data.get("comment", None)) -@schedule_bp.route("/events", methods=["POST"]) +@schedule_bp.route("", methods=["POST"]) @login_required(permission=permissions.CREATE) def create_event(current_session): """Create an new event - Route: ``/schedule/events`` | Method: ``POST`` + Route: ``/events`` | Method: ``POST`` POST-data: See interfaces for Event, can already contain jobs @@ -306,7 +306,7 @@ def create_event(current_session): def modify_event(event_id, current_session): """Modify an event - Route: ``/schedule/events/`` | Method: ``PUT`` + Route: ``/events/`` | Method: ``PUT`` POST-data: See interfaces for Event, can already contain slots @@ -332,12 +332,12 @@ def modify_event(event_id, current_session): return jsonify(event) -@schedule_bp.route("/events/", methods=["DELETE"]) +@schedule_bp.route("/", methods=["DELETE"]) @login_required(permission=permissions.DELETE) def delete_event(event_id, current_session): """Delete an event - Route: ``/schedule/events/`` | Method: ``DELETE`` + Route: ``/events/`` | Method: ``DELETE`` Args: event_id: Identifier of the event @@ -350,12 +350,12 @@ def delete_event(event_id, current_session): return "", NO_CONTENT -@schedule_bp.route("/events//jobs", methods=["POST"]) +@schedule_bp.route("//jobs", methods=["POST"]) @login_required(permission=permissions.EDIT) def add_job(event_id, current_session): """Add an new Job to an Event / EventSlot - Route: ``/schedule/events//jobs`` | Method: ``POST`` + Route: ``/events//jobs`` | Method: ``POST`` POST-data: See Job @@ -371,7 +371,7 @@ def add_job(event_id, current_session): return jsonify(event) -@schedule_bp.route("/events//jobs/", methods=["DELETE"]) +@schedule_bp.route("//jobs/", methods=["DELETE"]) @login_required(permission=permissions.DELETE) def delete_job(event_id, job_id, current_session): """Delete a Job @@ -391,7 +391,7 @@ def delete_job(event_id, job_id, current_session): return no_content() -@schedule_bp.route("/events//jobs/", methods=["PUT"]) +@schedule_bp.route("//jobs/", methods=["PUT"]) @login_required() def update_job(event_id, job_id, current_session: Session): """Edit Job or assign user to the Job diff --git a/flaschengeist/plugins/events/event_controller.py b/flaschengeist/plugins/events/event_controller.py index 84e2887..ee1f663 100644 --- a/flaschengeist/plugins/events/event_controller.py +++ b/flaschengeist/plugins/events/event_controller.py @@ -146,7 +146,13 @@ def create_event(event_type, start, end=None, jobs=[], is_template=None, name=No try: logger.debug(event_type) event = Event( - start=start, end=end, name=name, description=description, type=event_type, is_template=is_template, jobs=jobs + start=start, + end=end, + name=name, + description=description, + type=event_type, + is_template=is_template, + jobs=jobs, ) db.session.add(event) db.session.commit()