Skip to content

Commit

Permalink
Move common string conversion method to domain
Browse files Browse the repository at this point in the history
* Add open_tasks, backlog_tasks, completed_tasks to `Project`
* Add `project_name` and `assignee_name` to `Task`
  • Loading branch information
AndreyMarkinPPC committed Jan 30, 2024
1 parent 27de84d commit 39ab698
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 216 deletions.
1 change: 1 addition & 0 deletions terka/domain/entities/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def backlog_tasks(self) -> list[Task]:
if task.status.name == "BACKLOG":
tasks.append(task)
return tasks

@property
def open_tasks(self) -> list[Task]:
tasks = []
Expand Down
25 changes: 25 additions & 0 deletions terka/domain/entities/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from statistics import median

from .entity import Entity
from .task import Task

class ProjectStatus(Enum):
DELETED = 0
Expand Down Expand Up @@ -110,6 +111,30 @@ def done(self):
def deleted(self):
return self._count_task_status("DELETED")

@property
def backlog_tasks(self) -> list[Task]:
tasks = []
for task in self.tasks:
if task.status.name == "BACKLOG":
tasks.append(task)
return tasks

@property
def open_tasks(self) -> list[Task]:
tasks = []
for task in self.tasks:
if task.status.name not in ("DONE", "DELETED"):
tasks.append(task)
return tasks

@property
def completed_tasks(self) -> list[Task]:
tasks = []
for task in self.tasks:
if task.status.name in ("DONE", "DELETED"):
tasks.append(task)
return tasks

def daily_time_entries_hours(
self,
start_date: str | date | None = None,
Expand Down
24 changes: 19 additions & 5 deletions terka/domain/entities/sprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,25 @@ def total_time_spent(self):
return total_time_spent_sprint

@property
def open_tasks(self):
return [
task for task in self.tasks
if task.tasks.status.name not in ("DONE", "DELETED")
]
def open_tasks(self) -> list[Task]:
tasks = []
for entity_task in self.tasks:
task = entity_task.tasks
if task.status.name not in ("DONE", "DELETED"):
task.story_points = entity_task.story_points
tasks.append(task)
return tasks

@property
def completed_tasks(self) -> list[Task]:
tasks = []
for entity_task in self.tasks:
task = entity_task.tasks
if task.status.name in ("DONE", "DELETED"):
task.story_points = entity_task.story_points
tasks.append(task)
return tasks


@property
def pct_completed(self) -> float:
Expand Down
42 changes: 38 additions & 4 deletions terka/domain/entities/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .entity import Entity


class TaskStatus(Enum):
DELETED = 0
BACKLOG = 1
Expand Down Expand Up @@ -105,11 +106,24 @@ def daily_time_entries_hours(
entries[day] += entry.time_spent_minutes / 60
return entries

@property
def project_name(self) -> str:
if project := self.project_:
return project.name
return ""

@property
def assignee_name(self) -> str:
if assigned_to := self.assigned_to:
return assigned_to.name
return ""

@property
def completion_date(self) -> datetime | None:
for event in self.history:
if event.new_value in ("DONE", "DELETED"):
return event.date
return datetime.utcfromtimestamp(0)

@property
def is_stale(self):
Expand All @@ -132,6 +146,27 @@ def is_completed(self):
return True
return False

@property
def collaborators_string(self) -> str:
if collaborators := self.collaborators:
collaborators_texts = sorted([
collaborator.users.name for collaborator in list(collaborators)
if collaborator.users
])
collaborator_string = ",".join(collaborators_texts)
else:
collaborator_string = ""
return collaborator_string

@property
def tags_string(self) -> str:
if tags := self.tags:
tags_text = ",".join(
[tag.base_tag.text for tag in list(tags)])
else:
tags_text = ""
return tags_text

def __repr__(self):
return f"<Task {self.id}>: {self.name}, {self.status.name}, {self.creation_date}"

Expand All @@ -147,9 +182,8 @@ def __eq__(self, other) -> bool:
if not isinstance(other, Task):
return False
if (self.name, self.description, self.project, self.status,
self.priority, self.due_date,
self.assignee) != (other.name, other.description,
other.project, other.status, other.priority,
other.due_date, other.assignee):
self.priority, self.due_date, self.assignee) != (
other.name, other.description, other.project, other.status,
other.priority, other.due_date, other.assignee):
return False
return True
4 changes: 3 additions & 1 deletion terka/entrypoints/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,12 @@ def delete_user(user_id):
return _build_response(result)


# tags
# tags
@app.route("/api/v1/tags", methods=["GET"])
def list_tags():
return _build_response(views.tags(bus.uow))


@app.route("/api/v1/tags/<tag_id>", methods=["GET"])
def get_tag(tag_id):
return _build_response(views.tag(bus.uow, tag_id))
Expand All @@ -433,6 +434,7 @@ def delete_tag():
result = bus.handle(cmd)
return _build_response(result)


def _build_response(msg="", status=200, mimetype="application/json"):
"""Helper method to build the response."""
msg = json.dumps(msg, indent=4, cls=EntityEncoder)
Expand Down
Loading

0 comments on commit 39ab698

Please sign in to comment.