[events] Changed routes

This commit is contained in:
Ferdinand Thiessen 2021-03-24 20:47:04 +01:00
parent 7d692c5f68
commit 6cf33976b3
2 changed files with 29 additions and 23 deletions

View File

@ -17,7 +17,7 @@ from . import event_controller, permissions
from . import models from . import models
from ...utils.HTTP import no_content 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): class EventPlugin(Plugin):
@ -42,8 +42,8 @@ def get_templates(current_session):
def get_event_types(current_session, identifier=None): def get_event_types(current_session, identifier=None):
"""Get EventType(s) """Get EventType(s)
Route: ``/schedule/event-types`` | Method: ``GET`` Route: ``/events/event-types`` | Method: ``GET``
Route: ``/schedule/event-types/<identifier>`` | Method: ``GET`` Route: ``/events/event-types/<identifier>`` | Method: ``GET``
Args: Args:
current_session: Session sent with Authorization Header 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): def new_event_type(current_session):
"""Create a new EventType """Create a new EventType
Route: ``/schedule/event-types`` | Method: ``POST`` Route: ``/events/event-types`` | Method: ``POST``
POST-data: ``{name: string}`` POST-data: ``{name: string}``
@ -86,7 +86,7 @@ def new_event_type(current_session):
def modify_event_type(identifier, current_session): def modify_event_type(identifier, current_session):
"""Rename or delete an event type """Rename or delete an event type
Route: ``/schedule/event-types/<id>`` | Method: ``PUT`` or ``DELETE`` Route: ``/events/event-types/<id>`` | Method: ``PUT`` or ``DELETE``
POST-data: (if renaming) ``{name: string}`` POST-data: (if renaming) ``{name: string}``
@ -112,7 +112,7 @@ def modify_event_type(identifier, current_session):
def get_job_types(current_session): def get_job_types(current_session):
"""Get all JobTypes """Get all JobTypes
Route: ``/schedule/job-types`` | Method: ``GET`` Route: ``/events/job-types`` | Method: ``GET``
Args: Args:
current_session: Session sent with Authorization Header current_session: Session sent with Authorization Header
@ -129,7 +129,7 @@ def get_job_types(current_session):
def new_job_type(current_session): def new_job_type(current_session):
"""Create a new JobType """Create a new JobType
Route: ``/schedule/job-types`` | Method: ``POST`` Route: ``/events/job-types`` | Method: ``POST``
POST-data: ``{name: string}`` POST-data: ``{name: string}``
@ -151,7 +151,7 @@ def new_job_type(current_session):
def modify_job_type(type_id, current_session): def modify_job_type(type_id, current_session):
"""Rename or delete a JobType """Rename or delete a JobType
Route: ``/schedule/job-types/<name>`` | Method: ``PUT`` or ``DELETE`` Route: ``/events/job-types/<name>`` | Method: ``PUT`` or ``DELETE``
POST-data: (if renaming) ``{name: string}`` POST-data: (if renaming) ``{name: string}``
@ -172,12 +172,12 @@ def modify_job_type(type_id, current_session):
return "", NO_CONTENT return "", NO_CONTENT
@schedule_bp.route("/events/<int:event_id>", methods=["GET"]) @schedule_bp.route("/<int:event_id>", methods=["GET"])
@login_required() @login_required()
def get_event(event_id, current_session): def get_event(event_id, current_session):
"""Get event by id """Get event by id
Route: ``/schedule/events/<event_id>`` | Method: ``GET`` Route: ``/events/<event_id>`` | Method: ``GET``
Args: Args:
event_id: ID identifying the event event_id: ID identifying the event
@ -190,7 +190,7 @@ def get_event(event_id, current_session):
return jsonify(event) return jsonify(event)
@schedule_bp.route("/events", methods=["GET"]) @schedule_bp.route("/", methods=["GET"])
@login_required() @login_required()
def get_filtered_events(current_session): def get_filtered_events(current_session):
begin = request.args.get("from") begin = request.args.get("from")
@ -204,14 +204,14 @@ def get_filtered_events(current_session):
return jsonify(event_controller.get_events(begin, end)) return jsonify(event_controller.get_events(begin, end))
@schedule_bp.route("/events/<int:year>/<int:month>", methods=["GET"]) @schedule_bp.route("/<int:year>/<int:month>", methods=["GET"])
@schedule_bp.route("/events/<int:year>/<int:month>/<int:day>", methods=["GET"]) @schedule_bp.route("/events/<int:year>/<int:month>/<int:day>", methods=["GET"])
@login_required() @login_required()
def get_events(current_session, year=datetime.now().year, month=datetime.now().month, day=None): 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), """Get Event objects for specified date (or month or year),
if nothing set then events for current month are returned if nothing set then events for current month are returned
Route: ``/schedule/events[/<year>/<month>[/<int:day>]]`` | Method: ``GET`` Route: ``/events[/<year>/<month>[/<int:day>]]`` | Method: ``GET``
Args: Args:
year (int, optional): year to query, defaults to current year 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)) 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) @login_required(permission=permissions.CREATE)
def create_event(current_session): def create_event(current_session):
"""Create an new event """Create an new event
Route: ``/schedule/events`` | Method: ``POST`` Route: ``/events`` | Method: ``POST``
POST-data: See interfaces for Event, can already contain jobs 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): def modify_event(event_id, current_session):
"""Modify an event """Modify an event
Route: ``/schedule/events/<event_id>`` | Method: ``PUT`` Route: ``/events/<event_id>`` | Method: ``PUT``
POST-data: See interfaces for Event, can already contain slots POST-data: See interfaces for Event, can already contain slots
@ -332,12 +332,12 @@ def modify_event(event_id, current_session):
return jsonify(event) return jsonify(event)
@schedule_bp.route("/events/<int:event_id>", methods=["DELETE"]) @schedule_bp.route("/<int:event_id>", methods=["DELETE"])
@login_required(permission=permissions.DELETE) @login_required(permission=permissions.DELETE)
def delete_event(event_id, current_session): def delete_event(event_id, current_session):
"""Delete an event """Delete an event
Route: ``/schedule/events/<event_id>`` | Method: ``DELETE`` Route: ``/events/<event_id>`` | Method: ``DELETE``
Args: Args:
event_id: Identifier of the event event_id: Identifier of the event
@ -350,12 +350,12 @@ def delete_event(event_id, current_session):
return "", NO_CONTENT return "", NO_CONTENT
@schedule_bp.route("/events/<int:event_id>/jobs", methods=["POST"]) @schedule_bp.route("/<int:event_id>/jobs", methods=["POST"])
@login_required(permission=permissions.EDIT) @login_required(permission=permissions.EDIT)
def add_job(event_id, current_session): def add_job(event_id, current_session):
"""Add an new Job to an Event / EventSlot """Add an new Job to an Event / EventSlot
Route: ``/schedule/events/<event_id>/jobs`` | Method: ``POST`` Route: ``/events/<event_id>/jobs`` | Method: ``POST``
POST-data: See Job POST-data: See Job
@ -371,7 +371,7 @@ def add_job(event_id, current_session):
return jsonify(event) return jsonify(event)
@schedule_bp.route("/events/<int:event_id>/jobs/<int:job_id>", methods=["DELETE"]) @schedule_bp.route("/<int:event_id>/jobs/<int:job_id>", methods=["DELETE"])
@login_required(permission=permissions.DELETE) @login_required(permission=permissions.DELETE)
def delete_job(event_id, job_id, current_session): def delete_job(event_id, job_id, current_session):
"""Delete a Job """Delete a Job
@ -391,7 +391,7 @@ def delete_job(event_id, job_id, current_session):
return no_content() return no_content()
@schedule_bp.route("/events/<int:event_id>/jobs/<int:job_id>", methods=["PUT"]) @schedule_bp.route("/<int:event_id>/jobs/<int:job_id>", methods=["PUT"])
@login_required() @login_required()
def update_job(event_id, job_id, current_session: Session): def update_job(event_id, job_id, current_session: Session):
"""Edit Job or assign user to the Job """Edit Job or assign user to the Job

View File

@ -146,7 +146,13 @@ def create_event(event_type, start, end=None, jobs=[], is_template=None, name=No
try: try:
logger.debug(event_type) logger.debug(event_type)
event = Event( 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.add(event)
db.session.commit() db.session.commit()