Skip to content

Commit

Permalink
Final touches to this interface
Browse files Browse the repository at this point in the history
  • Loading branch information
horia141 committed Feb 25, 2024
1 parent 616715a commit 0460a07
Show file tree
Hide file tree
Showing 156 changed files with 702 additions and 834 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ async def do_it(
if big_plan.archived:
return BigPlanArchiveServiceResult(archived_inbox_tasks=[])

big_plan_collection = await uow.repository_for(BigPlanCollection).load_by_id(
big_plan_collection = await uow.get_for(BigPlanCollection).load_by_id(
big_plan.big_plan_collection.ref_id,
)

inbox_task_collection = await uow.repository_for(
inbox_task_collection = await uow.get_for(
InboxTaskCollection
).load_by_parent(
big_plan_collection.workspace.ref_id,
)
inbox_tasks_to_archive = await uow.repository_for(InboxTask).find_all_generic(
inbox_tasks_to_archive = await uow.get_for(InboxTask).find_all_generic(
parent_ref_id=inbox_task_collection.ref_id,
allow_archived=False,
big_plan_ref_ids=[big_plan.ref_id],
Expand All @@ -61,7 +61,7 @@ async def do_it(
archived_inbox_tasks.append(inbox_task)

big_plan = big_plan.mark_archived(ctx)
await uow.repository_for(BigPlan).save(big_plan)
await uow.get_for(BigPlan).save(big_plan)
await progress_reporter.mark_updated(big_plan)

return BigPlanArchiveServiceResult(archived_inbox_tasks=archived_inbox_tasks)
10 changes: 5 additions & 5 deletions src/core/jupiter/core/domain/big_plans/service/remove_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ async def remove(
ref_id: EntityId,
) -> None:
"""Hard remove a big plan."""
big_plan = await uow.repository_for(BigPlan).load_by_id(
big_plan = await uow.get_for(BigPlan).load_by_id(
ref_id,
allow_archived=True,
)
inbox_task_collection = await uow.repository_for(
inbox_task_collection = await uow.get_for(
InboxTaskCollection
).load_by_parent(
workspace.ref_id,
)
inbox_tasks_to_remove = await uow.repository_for(InboxTask).find_all_generic(
inbox_tasks_to_remove = await uow.get_for(InboxTask).find_all_generic(
parent_ref_id=inbox_task_collection.ref_id,
allow_archived=True,
big_plan_ref_ids=[ref_id],
)

for inbox_task in inbox_tasks_to_remove:
await uow.repository_for(InboxTask).remove(inbox_task.ref_id)
await uow.get_for(InboxTask).remove(inbox_task.ref_id)
await reporter.mark_removed(inbox_task)

big_plan = await uow.repository_for(BigPlan).remove(ref_id)
big_plan = await uow.get_for(BigPlan).remove(ref_id)
await reporter.mark_removed(big_plan)
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ async def do_it(
if chore.archived:
return

chore_collection = await uow.repository_for(ChoreCollection).load_by_id(
chore_collection = await uow.get_for(ChoreCollection).load_by_id(
chore.chore_collection.ref_id,
)
inbox_task_collection = await uow.repository_for(
inbox_task_collection = await uow.get_for(
InboxTaskCollection
).load_by_parent(
chore_collection.workspace.ref_id,
)
inbox_tasks_to_archive = await uow.repository_for(InboxTask).find_all_generic(
inbox_tasks_to_archive = await uow.get_for(InboxTask).find_all_generic(
parent_ref_id=inbox_task_collection.ref_id,
allow_archived=False,
chore_ref_id=[chore.ref_id],
Expand All @@ -48,5 +48,5 @@ async def do_it(
)

chore = chore.mark_archived(ctx)
await uow.repository_for(Chore).save(chore)
await uow.get_for(Chore).save(chore)
await progress_reporter.mark_updated(chore)
12 changes: 6 additions & 6 deletions src/core/jupiter/core/domain/chores/service/remove_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ async def remove(
ref_id: EntityId,
) -> None:
"""Hard remove a chore."""
chore = await uow.repository_for(Chore).load_by_id(ref_id, allow_archived=True)
chore_collection = await uow.repository_for(ChoreCollection).load_by_id(
chore = await uow.get_for(Chore).load_by_id(ref_id, allow_archived=True)
chore_collection = await uow.get_for(ChoreCollection).load_by_id(
chore.chore_collection.ref_id,
)
inbox_task_collection = await uow.repository_for(
inbox_task_collection = await uow.get_for(
InboxTaskCollection
).load_by_parent(
chore_collection.workspace.ref_id,
)
inbox_tasks_to_archive = await uow.repository_for(InboxTask).find_all_generic(
inbox_tasks_to_archive = await uow.get_for(InboxTask).find_all_generic(
parent_ref_id=inbox_task_collection.ref_id,
allow_archived=True,
chore_ref_id=[chore.ref_id],
)

for inbox_task in inbox_tasks_to_archive:
await uow.repository_for(InboxTask).remove(inbox_task.ref_id)
await uow.get_for(InboxTask).remove(inbox_task.ref_id)
await progress_reporter.mark_removed(inbox_task)

chore = await uow.repository_for(Chore).remove(ref_id)
chore = await uow.get_for(Chore).remove(ref_id)
await progress_reporter.mark_removed(chore)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def archive(
raise Exception(f"Note {note.ref_id} cannot be removed independently")

note = note.mark_archived(ctx)
await uow.repository_for(Note).save(note)
await uow.get_for(Note).save(note)

async def archive_for_source(
self,
Expand All @@ -35,7 +35,7 @@ async def archive_for_source(
source_entity_ref_id: EntityId,
) -> None:
"""Execute the command's action."""
note = await uow.get_x(NoteRepository).load_optional_for_source(
note = await uow.get(NoteRepository).load_optional_for_source(
domain, source_entity_ref_id, allow_archived=True
)

Expand All @@ -49,4 +49,4 @@ async def archive_for_source(
raise Exception(f"Note {note.ref_id} cannot be removed dependently")

note = note.mark_archived(ctx)
await uow.repository_for(Note).save(note)
await uow.get_for(Note).save(note)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def remove(
if note.can_be_removed_independently:
raise Exception(f"Note {note.ref_id} cannot be removed independently")

await uow.repository_for(Note).remove(note.ref_id)
await uow.get_for(Note).remove(note.ref_id)

async def remove_for_source(
self,
Expand All @@ -30,11 +30,11 @@ async def remove_for_source(
source_entity_ref_id: EntityId,
) -> None:
"""Execute the command's action."""
note = await uow.get_x(NoteRepository).load_optional_for_source(
note = await uow.get(NoteRepository).load_optional_for_source(
domain, source_entity_ref_id
)
if note is None:
return
if not note.can_be_removed_independently:
raise Exception(f"Note {note.ref_id} cannot be removed dependently")
await uow.repository_for(Note).remove(note.ref_id)
await uow.get_for(Note).remove(note.ref_id)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def do_it(
if doc.archived:
return

subdocs = await uow.repository_for(Doc).find_all_generic(
subdocs = await uow.get_for(Doc).find_all_generic(
parent_ref_id=doc.doc_collection.ref_id,
allow_archived=True,
parent_doc_ref_id=[doc.ref_id],
Expand All @@ -39,5 +39,5 @@ async def do_it(
)

doc = doc.mark_archived(ctx)
await uow.repository_for(Doc).save(doc)
await uow.get_for(Doc).save(doc)
await progress_reporter.mark_updated(doc)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def do_it(
doc: Doc,
) -> None:
"""Execute the command's action."""
subdocs = await uow.repository_for(Doc).find_all_generic(
subdocs = await uow.get_for(Doc).find_all_generic(
parent_ref_id=doc.doc_collection.ref_id,
allow_archived=True,
parent_doc_ref_id=[doc.ref_id],
Expand All @@ -32,5 +32,5 @@ async def do_it(
ctx, uow, NoteDomain.DOC, doc.ref_id
)

await uow.repository_for(Doc).remove(doc.ref_id)
await uow.get_for(Doc).remove(doc.ref_id)
await progress_reporter.mark_removed(doc)
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def record_task(

# Record the accomplishment of the task in the score log.

score_log = await uow.repository_for(ScoreLog).load_by_parent(user.ref_id)
score_log = await uow.get_for(ScoreLog).load_by_parent(user.ref_id)

if isinstance(task, InboxTask):
new_score_log_entry = ScoreLogEntry.new_from_inbox_task(
Expand All @@ -64,7 +64,7 @@ async def record_task(
)

try:
await uow.repository_for(ScoreLogEntry).create(new_score_log_entry)
await uow.get_for(ScoreLogEntry).create(new_score_log_entry)
except EntityAlreadyExistsError:
# The score log entry already exists. This entity has already been marked as done
# or not done, and we won't do it again!
Expand Down Expand Up @@ -254,7 +254,7 @@ async def _update_current_stats(
score_log_entry: ScoreLogEntry,
) -> ScoreStats:
timeline = infer_timeline(period, ctx.action_timestamp)
score_stats = await uow.get_r(ScoreStatsRepository).load_by_key_optional(
score_stats = await uow.get(ScoreStatsRepository).load_by_key_optional(
(score_log.ref_id, period, timeline)
)

Expand All @@ -268,13 +268,13 @@ async def _update_current_stats(
ctx,
score_log_entry,
)
score_stats = await uow.get_r(ScoreStatsRepository).create(score_stats)
score_stats = await uow.get(ScoreStatsRepository).create(score_stats)
else:
score_stats = score_stats.merge_score(
ctx,
score_log_entry,
)
score_stats = await uow.get_r(ScoreStatsRepository).save(score_stats)
score_stats = await uow.get(ScoreStatsRepository).save(score_stats)

return score_stats

Expand All @@ -288,7 +288,7 @@ async def _update_best(
score_log: ScoreLog,
) -> ScorePeriodBest:
timeline = infer_timeline(period, ctx.action_timestamp)
score_period_best = await uow.get_r(
score_period_best = await uow.get(
ScorePeriodBestRepository
).load_by_key_optional((score_log.ref_id, period, timeline, sub_period))

Expand All @@ -300,15 +300,15 @@ async def _update_best(
timeline,
sub_period,
).update_to_max(ctx, score_stats)
score_period_best = await uow.get_r(ScorePeriodBestRepository).create(
score_period_best = await uow.get(ScorePeriodBestRepository).create(
score_period_best
)
else:
score_period_best = score_period_best.update_to_max(
ctx,
score_stats,
)
score_period_best = await uow.get_r(ScorePeriodBestRepository).save(
score_period_best = await uow.get(ScorePeriodBestRepository).save(
score_period_best
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ async def do_it(
self, uow: DomainUnitOfWork, user: User, right_now: Timestamp
) -> UserScoreHistory:
"""Retrieve the history of scores for a user."""
score_log = await uow.repository_for(ScoreLog).load_by_parent(user.ref_id)
score_log = await uow.get_for(ScoreLog).load_by_parent(user.ref_id)

today = ADate.from_date(right_now.as_date())
daily_lower_limit = today.subtract_days(90)
weekly_lower_limit = today.subtract_days(365)
monthly_lower_limit = today.subtract_days(365 * 2)
quarterly_lower_limit = today.subtract_days(365 * 5)

daily_score_stats = await uow.get_r(ScoreStatsRepository).find_all_in_timerange(
daily_score_stats = await uow.get(ScoreStatsRepository).find_all_in_timerange(
score_log.ref_id, RecurringTaskPeriod.DAILY, daily_lower_limit, today
)
weekly_score_stats = await uow.get_r(
weekly_score_stats = await uow.get(
ScoreStatsRepository
).find_all_in_timerange(
score_log.ref_id, RecurringTaskPeriod.WEEKLY, weekly_lower_limit, today
)
monthly_score_stats = await uow.get_r(
monthly_score_stats = await uow.get(
ScoreStatsRepository
).find_all_in_timerange(
score_log.ref_id, RecurringTaskPeriod.MONTHLY, monthly_lower_limit, today
)
quarterly_score_stats = await uow.get_r(
quarterly_score_stats = await uow.get(
ScoreStatsRepository
).find_all_in_timerange(
score_log.ref_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def do_it(
self, uow: DomainUnitOfWork, user: User, right_now: Timestamp
) -> UserScoreOverview:
"""Get the scores overview for a user."""
score_log = await uow.repository_for(ScoreLog).load_by_parent(user.ref_id)
score_log = await uow.get_for(ScoreLog).load_by_parent(user.ref_id)

(
daily_score,
Expand Down Expand Up @@ -161,7 +161,7 @@ async def _load_stats(
right_now: Timestamp,
) -> UserScore:
timeline = infer_timeline(period, right_now)
score_stats = await uow.get_r(ScoreStatsRepository).load_by_key_optional(
score_stats = await uow.get(ScoreStatsRepository).load_by_key_optional(
(score_log.ref_id, period, timeline)
)
return score_stats.to_user_score() if score_stats else UserScore.new()
Expand All @@ -175,7 +175,7 @@ async def _load_period_best(
sub_period: RecurringTaskPeriod,
) -> UserScore:
timeline = infer_timeline(period, right_now)
score_period_best = await uow.get_r(
score_period_best = await uow.get(
ScorePeriodBestRepository
).load_by_key_optional((score_log.ref_id, period, timeline, sub_period))
return (
Expand Down
Loading

0 comments on commit 0460a07

Please sign in to comment.