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

Change task comment api #1126

Open
wants to merge 7 commits into
base: develop
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
11 changes: 10 additions & 1 deletion app/api/dao/task_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from app import messages
from app.database.models.mentorship_relation import MentorshipRelationModel
from app.database.models.task_comment import TaskCommentModel
from app.database.models.user import UserModel
from app.utils.decorator_utils import email_verification_required
from app.utils.enum_utils import MentorshipRelationState

Expand Down Expand Up @@ -103,7 +104,15 @@ def get_all_task_comments_by_task_id(user_id, task_id, relation_id):
return is_valid

comments_list = TaskCommentModel.find_all_by_task_id(task_id, relation_id)
return [comment.json() for comment in comments_list]
response = []
for comment in comments_list:
user_details = UserModel.find_by_id(comment.user_id)
comment = comment.json()
del comment["user_id"]
comment["user"] = user_details
response.append(comment)

return response

@staticmethod
@email_verification_required
Expand Down
5 changes: 2 additions & 3 deletions app/api/models/mentorship_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
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

# from .task_comment import task_comment_model, task_comments_model


def add_models_to_namespace(api_namespace):
Expand All @@ -20,8 +21,6 @@ def add_models_to_namespace(api_namespace):
mentorship_request_response_body_for_user_dashboard_body.name
] = mentorship_request_response_body_for_user_dashboard_body
api_namespace.models[user_dashboard_user_details.name] = user_dashboard_user_details
api_namespace.models[task_comment_model.name] = task_comment_model
api_namespace.models[task_comments_model.name] = task_comments_model


send_mentorship_request_body = Model(
Expand Down
5 changes: 3 additions & 2 deletions app/api/models/task_comment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask_restx import Model, fields
from flask_restx import fields, Model
from app.api.models.user import public_user_api_model


def add_models_to_namespace(api_namespace):
Expand All @@ -15,7 +16,7 @@ def add_models_to_namespace(api_namespace):
"Task comments model",
{
"id": fields.Integer(required=True, description="Task comment's id."),
"user_id": fields.Integer(required=True, description="User's id."),
"user": fields.Nested(public_user_api_model),
"task_id": fields.Integer(required=True, description="Task's id."),
"relation_id": fields.Integer(required=True, description="Relation's id."),
"creation_date": fields.Float(
Expand Down
7 changes: 6 additions & 1 deletion tests/task_comments/test_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from app import messages
from app.api.dao.task_comment import TaskCommentDAO
from app.database.models.user import UserModel
from tests.tasks.tasks_base_setup import TasksBaseTestCase


Expand Down Expand Up @@ -30,7 +31,11 @@ def test_dao_find_by_task_id(self):
task_comments = TaskCommentDAO.get_all_task_comments_by_task_id(
user_id=1, task_id=1, relation_id=2
)[0]
task_comment = TaskCommentDAO.get_task_comment(1, 1)[0].json()
task_comment = TaskCommentDAO.get_task_comment(1, 1)[0]
user_details = UserModel.find_by_id(1).json()
task_comment = task_comment.json()
del task_comment["user_id"]
task_comment["user"] = user_details
self.assertEqual(task_comment, task_comments)

def test_dao_find_by_user_id(self):
Expand Down