Skip to content

Commit

Permalink
fix: user tasks api
Browse files Browse the repository at this point in the history
  • Loading branch information
kaditya97 committed Oct 1, 2024
1 parent eead542 commit cf7180e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
26 changes: 26 additions & 0 deletions backend/models/postgis/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,32 @@ async def as_dto(
)
return task_dto

async def task_as_dto(
self,
task_history: List[TaskHistoryDTO] = [],
last_updated: datetime.datetime = None,
comments: int = None,
db: Database = None,
):
from backend.services.users.user_service import UserService

"""Just converts to a TaskDTO"""
task_dto = TaskDTO()
task_dto.task_id = self.id
task_dto.project_id = self.project_id
task_dto.task_status = TaskStatus(self.task_status).name
user = (
await UserService.get_user_by_id(self.locked_by, db)
if self.locked_by
else None
)
task_dto.lock_holder = user.username if user else None
task_dto.task_history = task_history
task_dto.last_updated = last_updated if last_updated else None
task_dto.auto_unlock_seconds = await Task.auto_unlock_delta()
task_dto.comments_number = comments if isinstance(comments, int) else None
return task_dto

@staticmethod
async def get_task_history(
task_id: int, project_id: int, db: Database
Expand Down
10 changes: 6 additions & 4 deletions backend/services/users/user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,13 @@ async def get_tasks_dto(
if project_status:
tasks_query = tasks_query.where(
and_(
Task.c.project_id == Project.c.id,
Project.c.status == ProjectStatus[project_status.upper()].value,
Task.project_id == Project.id,
Project.status == ProjectStatus[project_status.upper()].value,
)
)

if project_id:
tasks_query = tasks_query.where(Task.c.project_id == project_id)
tasks_query = tasks_query.where(Task.project_id == project_id)

# Pagination
offset = (page - 1) * page_size
Expand All @@ -385,7 +385,9 @@ async def get_tasks_dto(

# Create list of task DTOs from the results
task_list = [
Task.as_dto(last_updated=row["max"], comments=row["comments"])
await Task.task_as_dto(
row, last_updated=row["max"], comments=row["comments"], db=db
)
for row in rows
]

Expand Down

0 comments on commit cf7180e

Please sign in to comment.