Skip to content
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
refactor(type-hints): ♻️ add Callable as type hint of functions
  • Loading branch information
Angeluz-07 committed May 14, 2020
commit f14734cc1f82d880fd9ba509641949e30f05c5b8
17 changes: 11 additions & 6 deletions commons/data_access_layer/cosmos_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def find(
self,
id: str,
event_context: EventContext,
peeker: 'function' = None,
peeker: Callable = None,
visible_only=True,
mapper: Callable = None,
):
Expand Down Expand Up @@ -275,7 +275,7 @@ def partial_update(
id: str,
changes: dict,
event_context: EventContext,
peeker: 'function' = None,
peeker: Callable = None,
visible_only=True,
mapper: Callable = None,
):
Expand Down Expand Up @@ -305,7 +305,7 @@ def delete(
self,
id: str,
event_context: EventContext,
peeker: 'function' = None,
peeker: Callable = None,
mapper: Callable = None,
):
return self.partial_update(
Expand Down Expand Up @@ -348,7 +348,9 @@ def __init__(self, repository: CosmosDBRepository):
def get_all(self, conditions: dict = None, **kwargs) -> list:
conditions = conditions if conditions else {}
event_ctx = self.create_event_context("read-many")
return self.repository.find_all(event_ctx, conditions=conditions, **kwargs)
return self.repository.find_all(
event_ctx, conditions=conditions, **kwargs
)

def get(self, id):
event_ctx = self.create_event_context("read")
Expand Down Expand Up @@ -406,6 +408,7 @@ def generate_uuid4() -> str:

def get_last_day_of_month(year: int, month: int) -> int:
from calendar import monthrange

return monthrange(year=year, month=month)[1]


Expand All @@ -419,7 +422,9 @@ def get_current_month() -> int:

def get_date_range_of_month(year: int, month: int) -> Dict[str, str]:
first_day_of_month = 1
start_date = datetime(year=year, month=month, day=first_day_of_month,tzinfo=timezone.utc)
start_date = datetime(
year=year, month=month, day=first_day_of_month, tzinfo=timezone.utc
)

last_day_of_month = get_last_day_of_month(year=year, month=month)
end_date = datetime(
Expand All @@ -430,7 +435,7 @@ def get_date_range_of_month(year: int, month: int) -> Dict[str, str]:
minute=59,
second=59,
microsecond=999999,
tzinfo=timezone.utc
tzinfo=timezone.utc,
)

return {
Expand Down
4 changes: 2 additions & 2 deletions time_tracker_api/time_entries/time_entries_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import abc
from dataclasses import dataclass, field
from typing import List, Callable
from flask import jsonify

from azure.cosmos import PartitionKey
from flask_restplus._http import HTTPStatus
Expand Down Expand Up @@ -115,7 +114,7 @@ def find(
self,
id: str,
event_context: EventContext,
peeker: 'function' = None,
peeker: Callable = None,
visible_only=True,
mapper: Callable = None,
):
Expand Down Expand Up @@ -150,6 +149,7 @@ def find_all(
custom_params=custom_params,
)

project_dao = projects_model.create_dao()
projects = project_dao.get_all()
add_project_name_to_time_entries(time_entries, projects)
return time_entries
Expand Down