Skip to content

Commit

Permalink
feat: update completed_duration_minutes to seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
upa-r-upa committed Oct 2, 2024
1 parent ac368a1 commit 7b07629
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""empty message
Revision ID: 53548f6233a4
Revision ID: 204d6103061c
Revises:
Create Date: 2024-09-20 13:21:08.260499
Create Date: 2024-10-02 22:29:15.706919
"""
from typing import Sequence, Union
Expand All @@ -12,7 +12,7 @@


# revision identifiers, used by Alembic.
revision: str = '53548f6233a4'
revision: str = '204d6103061c'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
Expand Down Expand Up @@ -93,7 +93,7 @@ def upgrade() -> None:
)
op.create_table('routine_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('duration_minutes', sa.Integer(), nullable=False),
sa.Column('duration_seconds', sa.Integer(), nullable=False),
sa.Column('completed_at', sa.TIMESTAMP(), nullable=False),
sa.Column('is_skipped', sa.Boolean(), nullable=False),
sa.Column('routine_id', sa.Integer(), nullable=False),
Expand Down
2 changes: 1 addition & 1 deletion app/api/dao/routine_log_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def put_logs(self, routine_id: int, logs: List[RoutineLogBase]):
routine_log = RoutineLog(
routine_id=routine_id,
routine_element_id=log.routine_item_id,
duration_minutes=log.duration_minutes,
duration_seconds=log.duration_seconds,
is_skipped=bool(log.is_skipped),
)

Expand Down
5 changes: 3 additions & 2 deletions app/api/repositories/routine_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ def get_routine_by_date(self, target: date) -> list[RoutinePublic]:
):
log = routine_log_map[routine.id][element.id]
routine_item.completed_at = log.completed_at
routine_item.completed_duration_minutes = (
log.duration_minutes
routine_item.completed_duration_seconds = (
log.duration_seconds
)
routine_item.is_skipped = log.is_skipped

routine_with_logs.routine_elements.append(routine_item)

Expand Down
2 changes: 1 addition & 1 deletion app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class RoutineLog(Base):

id = Column(Integer, primary_key=True)

duration_minutes = Column(Integer, nullable=False)
duration_seconds = Column(Integer, nullable=False)
completed_at = Column(TIMESTAMP, default=func.now(), nullable=False)
is_skipped = Column(Boolean, default=False, nullable=False)

Expand Down
7 changes: 5 additions & 2 deletions app/schemas/routine.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class RoutineItem(RoutineItemBase):
updated_at: datetime

completed_at: datetime | None
completed_duration_minutes: int | None
completed_duration_seconds: int | None
is_skipped: bool

class Config:
orm_mode = True
Expand All @@ -82,6 +83,7 @@ def from_routine_element(
created_at=element.created_at,
updated_at=element.updated_at,
completed_at=completed_at,
is_skipped=False,
)


Expand Down Expand Up @@ -125,6 +127,7 @@ def from_routine(routine: Routine, routine_elements: List[RoutineElement]):
duration_minutes=item.duration_minutes,
created_at=item.created_at,
updated_at=item.updated_at,
is_skipped=False,
)
for item in routine_elements
],
Expand All @@ -145,7 +148,7 @@ class RoutineUpdateInput(BaseModel):

class RoutineLogBase(BaseModel):
routine_item_id: int
duration_minutes: int
duration_seconds: int
is_skipped: bool = False


Expand Down
9 changes: 5 additions & 4 deletions tests/api/endpoints/protected/routines/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def add_routine(
duration_minutes=item.duration_minutes,
created_at=item.created_at,
updated_at=item.updated_at,
is_skipped=False,
)
for item in routine_elements
],
Expand All @@ -134,19 +135,19 @@ def routine_log_data(
return [
RoutineLogBase(
routine_item_id=1,
duration_minutes=5,
duration_seconds=5*60,
),
RoutineLogBase(
routine_item_id=2,
duration_minutes=30,
duration_seconds=30*60,
),
RoutineLogBase(
routine_item_id=3,
duration_minutes=30,
duration_seconds=30*60,
),
RoutineLogBase(
routine_item_id=4,
duration_minutes=30,
duration_seconds=30*60,
is_skipped=True,
),
]
32 changes: 16 additions & 16 deletions tests/api/endpoints/protected/task/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,99 +276,99 @@ def add_routine_list_with_log(
routine_id=1,
routine_element_id=1,
completed_at=target_date,
duration_minutes=5,
duration_seconds=5 * 60,
),
RoutineLog(
routine_id=1,
routine_element_id=2,
completed_at=target_date,
duration_minutes=5,
duration_seconds=5 * 60,
),
RoutineLog(
routine_id=1,
routine_element_id=3,
completed_at=target_date,
duration_minutes=5,
duration_seconds=5 * 60,
),
RoutineLog(
routine_id=1,
routine_element_id=4,
completed_at=target_date,
duration_minutes=5,
duration_seconds=5 * 60,
),
RoutineLog(
routine_id=2,
routine_element_id=1,
completed_at=target_date,
duration_minutes=5,
duration_seconds=5 * 60,
),
RoutineLog(
routine_id=2,
routine_element_id=2,
completed_at=target_date,
duration_minutes=5,
duration_seconds=5 * 60,
),
RoutineLog(
routine_id=2,
routine_element_id=3,
completed_at=target_date,
duration_minutes=5,
duration_seconds=5 * 60,
),
RoutineLog(
routine_id=2,
routine_element_id=4,
completed_at=target_date,
duration_minutes=5,
duration_seconds=5 * 60,
),
RoutineLog(
routine_id=2,
routine_element_id=1,
completed_at=target_date,
duration_minutes=15,
duration_seconds=15 * 60,
),
RoutineLog(
routine_id=2,
routine_element_id=2,
completed_at=target_date,
duration_minutes=15,
duration_seconds=15 * 60,
),
RoutineLog(
routine_id=2,
routine_element_id=3,
completed_at=target_date,
duration_minutes=15,
duration_seconds=15 * 60,
is_skipped=True,
),
RoutineLog(
routine_id=2,
routine_element_id=4,
completed_at=target_date,
duration_minutes=15,
duration_seconds=15 * 60,
),
RoutineLog(
routine_id=2,
routine_element_id=1,
completed_at=non_target_date,
duration_minutes=15,
duration_seconds=15 * 60,
),
RoutineLog(
routine_id=2,
routine_element_id=2,
completed_at=non_target_date,
duration_minutes=15,
duration_seconds=15 * 60,
),
RoutineLog(
routine_id=2,
routine_element_id=3,
completed_at=non_target_date,
duration_minutes=15,
duration_seconds=15 * 60,
is_skipped=True,
),
RoutineLog(
routine_id=2,
routine_element_id=4,
completed_at=non_target_date,
duration_minutes=15,
duration_seconds=15 * 60,
),
]

Expand Down

0 comments on commit 7b07629

Please sign in to comment.