Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create DAO and New Endpoints for Program Mentorship Relationship #22

Open
wants to merge 4 commits into
base: ms-backend-server
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/api/api_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from app.api.resources.mentorship_relation import (
mentorship_relation_ns as mentorship_namespace,
)
from app.api.resources.program_mentorship_relation import program_mentorship_relation_ns as program_mentorship_namespace
from app.api.resources.task import task_ns as task_namespace
from app.api.resources.task_comment import task_comment_ns as task_comment_namespace

Expand Down Expand Up @@ -52,6 +53,8 @@ def ioslink():

api.add_namespace(mentorship_namespace, path="/")

api.add_namespace(program_mentorship_namespace, path="/")

api.add_namespace(task_namespace, path="/")

api.add_namespace(task_comment_namespace, path="/")
411 changes: 411 additions & 0 deletions app/api/dao/program_mentorship_relation.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions app/api/dao/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ def update_user_profile(user_id: int, data: Dict[str, str]):
else:
user.occupation = None

if "organization" in data:
if data["organization"]:
user.organization = data["organization"]
if "current_organization" in data:
if data["current_organization"]:
user.current_organization = data["current_organization"]
else:
user.organization = None
user.current_organization = None

if "slack_username" in data:
if data["slack_username"]:
Expand Down
57 changes: 57 additions & 0 deletions app/api/email_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,63 @@ def send_email_mentorship_relation_accepted(request_id):
)
send_email(request_sender.email, subject, html)

def send_email_program_mentorship_relation_accepted(request_id,org_rep_id):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we place this in a separate file "bit_email_utils.py" to make it easier for contributors to locate BIT specific email logic from.

"""
Sends a notification email to the sender of the mentorship relation request,
stating that his request has been accepted.

Args:
request_id: Request id of the mentorship request.
"""

from app.database.models.user import UserModel
from app.database.models.mentorship_relation import MentorshipRelationModel

# Getting the request from id.
request = MentorshipRelationModel.find_by_id(request_id)

# Getting the sender and receiver of the mentorship request from their ids.
if not request.mentee:
if request.action_user_id == request.mentor_id:
request_sender = UserModel.find_by_id(org_rep_id)
request_receiver = UserModel.find_by_id(request.mentor_id)
role = "mentor"
else:
request_sender = UserModel.find_by_id(request.mentor_id)
request_receiver = UserModel.find_by_id(org_rep_id)
role = "mentor"
elif not request.mentor:
if request.action_user_id == request.mentee_id:
request_sender = UserModel.find_by_id(org_rep_id)
request_receiver = UserModel.find_by_id(request.mentee_id)
role = "mentee"
else:
request_sender = UserModel.find_by_id(request.mentee_id)
request_receiver = UserModel.find_by_id(org_rep_id)
role = "mentee"
else:
if request.action_user_id == request.mentor_id:
request_sender = UserModel.find_by_id(request.mentor_id)
request_receiver = UserModel.find_by_id(request.mentee_id)
role = "mentee"
else:
request_sender = UserModel.find_by_id(request.mentee_id)
request_receiver = UserModel.find_by_id(request.mentor_id)
role = "mentor"

end_date = request.end_date
date = datetime.datetime.fromtimestamp(end_date).strftime("%d-%m-%Y")

subject = "Mentorship relation accepted!"
html = render_template(
"mentorship_relation_accepted.html",
request_sender=request_sender.name,
request_receiver=request_receiver.name,
role=role,
end_date=date,
)
send_email(request_sender.email, subject, html)


def send_email_new_request(user_sender, user_recipient, notes, sender_role):
"""Sends a notification html email message to the user_recipient user.
Expand Down
2 changes: 1 addition & 1 deletion app/api/models/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def add_models_to_namespace(api_namespace):
"bio": fields.String(required=True, description="User bio"),
"location": fields.String(required=True, description="User location"),
"occupation": fields.String(required=True, description="User occupation"),
"organization": fields.String(required=True, description="User organization"),
"current_organization": fields.String(required=True, description="User current organization"),
"skills": fields.String(required=True, description="User skills"),
},
)
40 changes: 40 additions & 0 deletions app/api/models/program_mentorship_relation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from flask_restx import fields, Model

from app.utils.enum_utils import MentorshipRelationState
from .task import create_task_request_body, list_tasks_response_body
from .task_comment import task_comment_model, task_comments_model


def add_models_to_namespace(api_namespace):
api_namespace.models[
send_program_mentorship_request_body.name
] = send_program_mentorship_request_body



send_program_mentorship_request_body = Model(
"Send mentorship relation request model",
{
"mentor_id": fields.Integer(
description="Mentorship relation mentor ID"
),
"mentee_id": fields.Integer(
description="Mentorship relation mentee ID"
),
"org_rep_id": fields.Integer(
required=True, description="Organization Representative's ID"
),
"relation_id": fields.Integer(
description="Mentorship Relation ID"
),
"start_date": fields.Float(
description="Program start date in UNIX timestamp format",
),
"end_date": fields.Float(
description="Program end date in UNIX timestamp format",
),
"notes": fields.String(required=True, description="Mentorship relation notes"),
},
)


6 changes: 3 additions & 3 deletions app/api/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def add_models_to_namespace(api_namespace):
"bio": fields.String(required=True, description="User bio"),
"location": fields.String(required=True, description="User location"),
"occupation": fields.String(required=True, description="User occupation"),
"organization": fields.String(required=True, description="User organization"),
"current_organization": fields.String(required=True, description="User current_organization"),
"interests": fields.String(required=True, description="User interests"),
"skills": fields.String(required=True, description="User skills"),
"need_mentoring": fields.Boolean(
Expand Down Expand Up @@ -91,7 +91,7 @@ def add_models_to_namespace(api_namespace):
"bio": fields.String(required=False, description="User bio"),
"location": fields.String(required=False, description="User location"),
"occupation": fields.String(required=False, description="User occupation"),
"organization": fields.String(required=False, description="User organization"),
"current_organization": fields.String(required=False, description="User current_organization"),
"slack_username": fields.String(
required=False, description="User slack username"
),
Expand Down Expand Up @@ -179,7 +179,7 @@ def add_models_to_namespace(api_namespace):
"bio": fields.String(required=False, description="User bio"),
"location": fields.String(required=False, description="User location"),
"occupation": fields.String(required=False, description="User occupation"),
"organization": fields.String(required=False, description="User organization"),
"current_organization": fields.String(required=False, description="User current_organization"),
"slack_username": fields.String(
required=False, description="User slack username"
),
Expand Down
2 changes: 1 addition & 1 deletion app/api/resources/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get(cls):
A admin user with valid access token can view the list of all admins. The endpoint
doesn't take any other input. A JSON array having an object for each admin user is
returned. The array contains id, username, name, slack_username, bio,
location, occupation, organization, skills.
location, occupation, current_organization, skills.
The current admin user's details are not returned.
"""
user_id = get_jwt_identity()
Expand Down
Loading