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

Separate response for comment and task status history #1391

Merged
merged 1 commit into from
Mar 26, 2024
Merged
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
39 changes: 31 additions & 8 deletions src/backend/app/tasks/tasks_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,28 +341,51 @@ def process_history_entry(history_entry):

async def get_project_task_history(
project_id: int,
end_date: Optional[datetime],
comment: bool,
end_date: datetime,
task_id: Optional[int],
db: Session,
) -> list[db_models.DbTaskHistory]:
):
"""Retrieves the task history records for a specific project.

Args:
project_id (int): The ID of the project.
comment (bool): True or False, True to get comments
from the project tasks and False by default for
entire task status history.
end_date (datetime, optional): The end date of the task history
records to retrieve.
task_id (int): The task_id of the project.
db (Session): The database session.

Returns:
A list of task history records for the specified project.
"""
query = db.query(db_models.DbTaskHistory).filter(
db_models.DbTaskHistory.project_id == project_id
)
query = f"""SELECT *
FROM task_history
WHERE project_id = {project_id}
AND action_date >= '{end_date}'
"""

if end_date:
query = query.filter(db_models.DbTaskHistory.action_date >= end_date)
query += " AND action = 'COMMENT'" if comment else " AND action != 'COMMENT'"

return query.all()
if task_id:
query += f" AND task_id = {task_id}"

result = db.execute(text(query)).fetchall()
task_history = [
{
"id": row[0],
"project_id": row[1],
"task_id": row[2],
"action": row[3],
"action_text": row[4],
"action_date": row[5],
"status": None if comment else row[4].split()[5],
}
for row in result
]
return task_history


async def count_validated_and_mapped_tasks(
Expand Down
18 changes: 14 additions & 4 deletions src/backend/app/tasks/tasks_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""Routes for FMTM tasks."""

from datetime import datetime, timedelta
from typing import List
from typing import List, Optional

from fastapi import APIRouter, Depends, HTTPException
from loguru import logger as log
Expand Down Expand Up @@ -256,20 +256,30 @@ async def task_activity(
)


@router.get("/task_history/", response_model=List[tasks_schemas.TaskHistory])
@router.get("/task_history/")
async def task_history(
project_id: int, days: int = 10, db: Session = Depends(database.get_db)
project_id: int,
days: int = 10,
comment: bool = False,
task_id: Optional[int] = None,
db: Session = Depends(database.get_db),
):
"""Get the detailed task history for a project.

Args:
project_id (int): The ID of the project.
days (int): The number of days to consider for the
task activity (default: 10).
comment (bool): True or False, True to get comments
from the project tasks and False by default for
entire task status history.
task_id (int): The task_id of the project.
db (Session): The database session.

Returns:
List[TaskHistory]: A list of task history.
"""
end_date = datetime.now() - timedelta(days=days)
return await tasks_crud.get_project_task_history(project_id, end_date, db)
return await tasks_crud.get_project_task_history(
project_id, comment, end_date, task_id, db
)
Loading