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, )
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 post_role() -> ApiResponse: role_json = request.get_json() if RoleModel.find_by_name(role_json.get("role_name")): abort( 409, description=ERROR_409.format( "Role", "role_name", role_json.get("role_name"), ), ) role = role_schema.load(role_json) role.save_to_db() return ( jsonify( { "message": CREATED.format("Role"), "role": role_schema.dump(role), } ), 201, )
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, )
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, )
def post_member() -> ApiResponse: member_json = request.get_json() if MemberModel.find_by_email(member_json.get("email")): abort( 409, description=ERROR_409.format( "Member", "email", member_json.get("email"), ), ) member = member_schema.load(member_json) member.save_to_db() return ( jsonify({ "message": CREATED.format("Member"), "member": member_schema.dump(member), }), 201, )
def post_permission() -> ApiResponse: permission_json = request.get_json() if PermissionModel.find_by_name(permission_json.get("permission_name")): abort( 409, description=ERROR_409.format( "Permission", "permission_name", permission_json.get("permission_name"), ), ) permission = permission_schema.load(permission_json) permission.save_to_db() return ( jsonify({ "message": CREATED.format("Permission"), "permission": permission_schema.dump(permission), }), 201, )
def post_project() -> ApiResponse: project_json = request.get_json() if ProjectModel.find_by_title(project_json.get("title")): abort( 409, description=ERROR_409.format( "Project", "title", project_json.get("title"), ), ) project = project_schema.load(project_json) project.save_to_db() return ( jsonify({ "message": CREATED.format("Project"), "project": project_schema.dump(project), }), 201, )