feat(backend): Add routed for get_job and get_invitations

This commit is contained in:
Ferdinand Thiessen 2021-12-22 01:06:23 +01:00
parent 5a52c364e4
commit a09ce26474
2 changed files with 20 additions and 1 deletions

View File

@ -2,6 +2,7 @@ from datetime import datetime, timedelta, timezone
from enum import IntEnum from enum import IntEnum
from typing import Optional, Tuple from typing import Optional, Tuple
from flaschengeist.models import UtcDateTime from flaschengeist.models import UtcDateTime
from flaschengeist.models.user import User
from werkzeug.exceptions import BadRequest, Conflict, NotFound from werkzeug.exceptions import BadRequest, Conflict, NotFound
from sqlalchemy.exc import IntegrityError from sqlalchemy.exc import IntegrityError
@ -339,6 +340,12 @@ def get_invitation(id: int):
return inv return inv
def get_invitations(user: User):
return Invitation.query.filter(
(Invitation.invitee_ == user) | (Invitation.inviter_ == user) | (Invitation.transferee_ == user)
).all()
def cancel_invitation(inv: Invitation): def cancel_invitation(inv: Invitation):
db.session.delete(inv) db.session.delete(inv)
db.session.commit() db.session.commit()

View File

@ -397,6 +397,12 @@ def get_jobs(current_session: Session):
return jsonify({"count": count, "result": result}) return jsonify({"count": count, "result": result})
@EventPlugin.blueprint.route("/events/jobs/<int:job_id>", methods=["GET"])
@login_required()
def get_job(job_id, current_session: Session):
return jsonify(event_controller.get_job(job_id))
@EventPlugin.blueprint.route("/events/jobs/<int:job_id>/assign", methods=["POST"]) @EventPlugin.blueprint.route("/events/jobs/<int:job_id>/assign", methods=["POST"])
@login_required() @login_required()
def assign_job(job_id, current_session: Session): def assign_job(job_id, current_session: Session):
@ -498,12 +504,18 @@ def invite(current_session: Session):
raise BadRequest raise BadRequest
@EventPlugin.blueprint.route("/events/invitations", methods=["GET"])
@login_required()
def get_invitations(current_session: Session):
return jsonify(event_controller.get_invitations(current_session.user_))
@EventPlugin.blueprint.route("/events/invitations/<int:invitation_id>", methods=["GET"]) @EventPlugin.blueprint.route("/events/invitations/<int:invitation_id>", methods=["GET"])
@login_required() @login_required()
def get_invitation(invitation_id: int, current_session: Session): def get_invitation(invitation_id: int, current_session: Session):
inv = event_controller.get_invitation(invitation_id) inv = event_controller.get_invitation(invitation_id)
if current_session.userid not in [inv.invitee_id, inv.inviter_id, inv.transferee_id]: if current_session.userid not in [inv.invitee_id, inv.inviter_id, inv.transferee_id]:
raise Forbidden raise NotFound
return jsonify(inv) return jsonify(inv)