예제 #1
0
def put_speaker(speaker_id: int) -> ApiResponse:
    speaker = SpeakerModel.find_by_id(speaker_id)

    if not speaker:
        abort(
            404,
            description=ERROR_404.format("Speaker", "id", speaker_id),
        )

    speaker_json = request.get_json()
    speaker.first_name = speaker_json.get("first_name")
    speaker.last_name = speaker_json.get("last_name")
    speaker.email = speaker_json.get("email")
    speaker.linkedin_profile = speaker_json.get("linkedin_profile")
    speaker.github_profile = speaker_json.get("github_profile")
    speaker.twitter_profile = speaker_json.get("twitter_profile")
    speaker.bio = speaker_json.get("bio")
    speaker.profile_picture = speaker_json.get("profile_picture")
    speaker.save_to_db()

    return (
        jsonify({
            "message": MODIFIED.format("Speaker"),
            "speaker": speaker_schema.dump(speaker),
        }),
        200,
    )
예제 #2
0
def put_role(role_id: int) -> ApiResponse:
    role = RoleModel.find_by_id(role_id)

    if not role:
        abort(
            404,
            description=ERROR_404.format("Role", "id", role_id),
        )

    role_json = request.get_json()

    role_by_name = RoleModel.find_by_name(role_json.get("role_name"))

    if role_by_name and role_by_name.id != role_id:
        abort(
            409,
            description=ERROR_409.format(
                "Role",
                "role_name",
                role_json.get("role_name"),
            ),
        )

    role.role_name = role_json.get("role_name")
    role.save_to_db()

    return (
        jsonify(
            {
                "message": MODIFIED.format("Role"),
                "role": role_schema.dump(role),
            }
        ),
        200,
    )
def put_permission(permission_id: int) -> ApiResponse:
    permission = PermissionModel.find_by_id(permission_id)

    if not permission:
        abort(
            404,
            description=ERROR_404.format("Permission", "id", permission_id),
        )

    permission_json = request.get_json()

    permission_by_name = PermissionModel.find_by_name(
        permission_json.get("permission_name"))

    if permission_by_name and permission_by_name.id != permission_id:
        abort(
            409,
            description=ERROR_409.format(
                "Permission",
                "permission_name",
                permission_json.get("permission_name"),
            ),
        )

    permission.permission_name = permission_json.get("permission_name")
    permission.save_to_db()

    return (
        jsonify({
            "message": MODIFIED.format("Permission"),
            "permission": permission_schema.dump(permission),
        }),
        200,
    )
예제 #4
0
def get_keynote(keynote_id: int) -> ApiResponse:
    keynote = KeynoteModel.find_by_id(keynote_id)

    if not keynote:
        abort(404, description=ERROR_404.format("Keynote", "id", keynote_id))

    return (
        jsonify({
            "keynote": keynote_schema.dump(keynote),
        }),
        200,
    )
예제 #5
0
def get_meeting(meeting_id: int) -> ApiResponse:
    meeting = MeetingModel.find_by_id(meeting_id)

    if not meeting:
        abort(404, description=ERROR_404.format("Meeting", "id", meeting_id))

    return (
        jsonify({
            "meeting": meeting_schema.dump(meeting),
        }),
        200,
    )
예제 #6
0
def get_member(member_id: int) -> ApiResponse:
    member = MemberModel.find_by_id(member_id)

    if not member:
        abort(404, description=ERROR_404.format("Member", "id", member_id))

    return (
        jsonify({
            "member": member_schema.dump(member),
        }),
        200,
    )
예제 #7
0
def get_keynotes_for_speaker(speaker_id: int) -> ApiResponse:
    keynote_list = KeynoteModel.find_by_speaker_id(speaker_id)

    if not keynote_list:
        abort(
            404,
            description=ERROR_404.format("Keynotes", "speaker_id", speaker_id),
        )

    return (
        jsonify({"keynotes": keynote_list_schema.dump(keynote_list)}),
        200,
    )
예제 #8
0
def delete_keynote(keynote_id: int) -> ApiResponse:
    keynote = KeynoteModel.find_by_id(keynote_id)

    if not keynote:
        abort(404, description=ERROR_404.format("Keynote", "id", keynote_id))

    keynote.delete_from_db()

    return (
        jsonify({
            "message": DELETED.format("Keynote"),
            "keynote": keynote_schema.dump(keynote),
        }),
        200,
    )
예제 #9
0
def get_speaker(speaker_id: int) -> ApiResponse:
    speaker = SpeakerModel.find_by_id(speaker_id)

    if not speaker:
        abort(
            404,
            description=ERROR_404.format("Speaker", "id", speaker_id),
        )

    return (
        jsonify({
            "speaker": speaker_schema.dump(speaker),
        }),
        200,
    )
def get_permission(permission_id: int) -> ApiResponse:
    permission = PermissionModel.find_by_id(permission_id)

    if not permission:
        abort(
            404,
            description=ERROR_404.format("Permission", "id", permission_id),
        )

    return (
        jsonify({
            "permission": permission_schema.dump(permission),
        }),
        200,
    )
예제 #11
0
def get_project(project_id: int) -> ApiResponse:
    project = ProjectModel.find_by_id(project_id)

    if not project:
        abort(
            404,
            description=ERROR_404.format("Project", "id", project_id),
        )

    return (
        jsonify({
            "project": project_schema.dump(project),
        }),
        200,
    )
예제 #12
0
def delete_meeting(meeting_id: int) -> ApiResponse:
    meeting = MeetingModel.find_by_id(meeting_id)

    if not meeting:
        abort(404, description=ERROR_404.format("Meeting", "id", meeting_id))

    meeting.delete_from_db()

    return (
        jsonify({
            "message": DELETED.format("Meeting"),
            "meeting": meeting_schema.dump(meeting),
        }),
        200,
    )
예제 #13
0
def deactivate_member(member_id: int) -> ApiResponse:
    member = MemberModel.find_by_id(member_id)

    if not member:
        abort(404, description=ERROR_404.format("Member", "id", member_id))

    member.is_active = False
    member.save_to_db()

    return (
        jsonify({
            "message": DEACTIVATED.format("Member"),
            "member": member_schema.dump(member),
        }),
        200,
    )
예제 #14
0
def put_member(member_id: int) -> ApiResponse:
    member = MemberModel.find_by_id(member_id)
    identity = get_jwt_identity()

    if member and identity["id"] != member.id:
        abort(
            401,
            description=ERROR_401,
        )

    if not member:
        abort(
            404,
            description=ERROR_404.format("Member", "id", member_id),
        )

    member_json = request.get_json()

    member_by_email = MemberModel.find_by_email(member_json.get("email"))

    if member_by_email and member_by_email.id != member_id:
        abort(
            409,
            description=ERROR_409.format(
                "Member",
                "email",
                member_json.get("email"),
            ),
        )

    member.email = member_json.get("email")
    member.mobile_phone = member_json.get("mobile_phone")
    member.first_name = member_json.get("first_name")
    member.last_name = member_json.get("last_name")
    member.linkedin_profile = member_json.get("linkedin_profile")
    member.github_profile = member_json.get("github_profile")
    member.twitter_profile = member_json.get("twitter_profile")
    member.profile_picture = member_json.get("profile_picture")
    member.save_to_db()

    return (
        jsonify({
            "message": MODIFIED.format("Member"),
            "member": member_schema.dump(member),
        }),
        200,
    )
예제 #15
0
def get_role(role_id: int) -> ApiResponse:
    role = RoleModel.find_by_id(role_id)

    if not role:
        abort(
            404,
            description=ERROR_404.format("Role", "id", role_id),
        )

    return (
        jsonify(
            {
                "role": role_schema.dump(role),
            }
        ),
        200,
    )
def delete_permission(permission_id: int) -> ApiResponse:
    permission = PermissionModel.find_by_id(permission_id)

    if not permission:
        abort(
            404,
            description=ERROR_404.format("Permission", "id", permission_id),
        )

    permission.delete_from_db()

    return (
        jsonify({
            "message": DELETED.format("Permission"),
            "permission": permission_schema.dump(permission),
        }),
        200,
    )
예제 #17
0
def delete_project(project_id: int) -> ApiResponse:
    project = ProjectModel.find_by_id(project_id)

    if not project:
        abort(
            404,
            description=ERROR_404.format("Project", "id", project_id),
        )

    project.delete_from_db()

    return (
        jsonify({
            "message": DELETED.format("project"),
            "project": project_schema.dump(project),
        }),
        200,
    )
예제 #18
0
def delete_speaker(speaker_id: int) -> ApiResponse:
    speaker = SpeakerModel.find_by_id(speaker_id)

    if not speaker:
        abort(
            404,
            description=ERROR_404.format("Speaker", "id", speaker_id),
        )

    speaker.delete_from_db()

    return (
        jsonify({
            "message": DELETED.format("Speaker"),
            "speaker": speaker_schema.dump(speaker),
        }),
        200,
    )
예제 #19
0
def delete_role(role_id: int) -> ApiResponse:
    role = RoleModel.find_by_id(role_id)

    if not role:
        abort(
            404,
            description=ERROR_404.format("Role", "id", role_id),
        )

    role.delete_from_db()

    return (
        jsonify(
            {
                "message": DELETED.format("Role"),
                "role": role_schema.dump(role),
            }
        ),
        200,
    )
예제 #20
0
def put_keynote(keynote_id: int) -> ApiResponse:
    keynote = KeynoteModel.find_by_id(keynote_id)

    if not keynote:
        abort(404, description=ERROR_404.format("Keynote", "id", keynote_id))

    keynote_json = request.get_json()

    keynote.title = keynote_json.get("title")
    keynote.description = keynote_json.get("description")
    keynote.speaker_id = keynote_json.get("speaker_id")
    keynote.meeting_id = keynote_json.get("meeting_id")
    keynote.save_to_db()

    return (
        jsonify({
            "message": MODIFIED.format("Keynote"),
            "keynote": keynote_schema.dump(keynote),
        }),
        200,
    )
예제 #21
0
def put_meeting(meeting_id: int) -> ApiResponse:
    meeting = MeetingModel.find_by_id(meeting_id)

    if not meeting:
        abort(404, description=ERROR_404.format("Meeting", "id", meeting_id))

    meeting_json = request.get_json()

    meeting.datetime = meeting_json.get("datetime")
    meeting.type = meeting_json.get("type")
    meeting.location = meeting_json.get("location")
    meeting.description = meeting_json.get("description")
    meeting.creator_id = meeting_json.get("creator_id")
    meeting.save_to_db()

    return (
        jsonify({
            "message": MODIFIED.format("Meeting"),
            "meeting": meeting_schema.dump(meeting),
        }),
        200,
    )
예제 #22
0
def put_project(project_id: int) -> ApiResponse:
    project = ProjectModel.find_by_id(project_id)

    if not project:
        abort(
            404,
            description=ERROR_404.format("Project", "id", project_id),
        )

    project_json = request.get_json()

    project_by_title = ProjectModel.find_by_title(project_json.get("title"))

    if project_by_title and project_by_title.id != project_id:
        abort(
            409,
            description=ERROR_409.format(
                "Project",
                "title",
                project_json.get("title"),
            ),
        )

    project.start_date = project_json.get("start_date")
    project.end_date = project_json.get("end_date")
    project.title = project_json.get("title")
    project.description = project_json.get("description")
    project.goals = project_json.get("goals")
    project.status = project_json.get("status")
    project.admin_id = project_json.get("admin_id")
    project.save_to_db()

    return (
        jsonify({
            "message": MODIFIED.format("Project"),
            "project": project_schema.dump(project),
        }),
        200,
    )
예제 #23
0
def change_member_password(member_id: int) -> ApiResponse:
    member = MemberModel.find_by_id(member_id)
    identity = get_jwt_identity()

    if member and identity["id"] != member.id:
        abort(
            401,
            description=ERROR_401,
        )

    if not member:
        abort(404, description=ERROR_404.format("Member", "id", member_id))

    member_json = request.get_json()
    member.password_hash = generate_password_hash(member_json.get("password"))
    member.save_to_db()

    return (
        jsonify({
            "message": PASSWORD_MODIFIED,
            "member": member_schema.dump(member),
        }),
        200,
    )