-
Notifications
You must be signed in to change notification settings - Fork 0
Tt 185 find all method in time entries #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
eb62162
refactor: TT-185 create SQLBuilder, TimeEntryQueryBuilder and find_al…
kellycastrof 031b883
test: TT-185 query_builder tests
kellycastrof 262ace0
test: TT-185 add test methods for TimeEntryQueryBuilder and new funct…
kellycastrof 7914fdf
build: TT-199 build(deps): bump jinja2 in /requirements/time_tracker…
dependabot[bot] 2b57549
refactor: TT-185 create SQLBuilder, TimeEntryQueryBuilder and find_al…
kellycastrof 7606663
test: TT-185 query_builder tests
kellycastrof f1fc8a6
test: TT-185 add test methods for TimeEntryQueryBuilder and new funct…
kellycastrof be72ff8
refactor: TT-185 rename get_string_without_empty_spaces to remove_whi…
kellycastrof 3401b39
refactor: TT-185 add time_entries_id in condition
kellycastrof 2342ce9
refactor: TT-185 delete empty lines
kellycastrof 5358c40
refactor: TT-185 delete isintance validation
kellycastrof a403edb
refactor: TT-185 improve function remove_white_spaces
Angeluz-07 d538899
refactor: TT-185 change column to columns
Angeluz-07 06cbca7
refactor: TT-185 add more scenarios to test_add_sql_in_condition_shou…
Angeluz-07 a1331fc
refactor: TT-185 add more scenarios to test__build_where_should_retur…
Angeluz-07 c44f20e
refactor: TT-185 improve test_TimeEntryQueryBuilder_is_subclass_Cosmo…
Angeluz-07 f17d841
refactor: TT-185 rename args in TimeEntriesRepository
Angeluz-07 be6e9b1
refactor: TT-185 change the scenarios in test_add_sql_date_range_cond…
kellycastrof File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor: TT-185 create SQLBuilder, TimeEntryQueryBuilder and find_al…
…l_v2 method in time entries repository
- Loading branch information
commit 2b57549eaac65c98de83f51ba9915524fc9e87fa
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
time_tracker_api/time_entries/time_entries_query_builder.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from utils.query_builder import CosmosDBQueryBuilder | ||
|
|
||
|
|
||
| class TimeEntryQueryBuilder(CosmosDBQueryBuilder): | ||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
| def add_sql_date_range_condition(self, dates: tuple = None): | ||
| if dates and len(dates) == 2: | ||
| start_date, end_date = dates | ||
| condition = """ | ||
| ((c.start_date BETWEEN @start_date AND @end_date) OR | ||
| (c.end_date BETWEEN @start_date AND @end_date)) | ||
| """ | ||
| self.where_conditions.append(condition) | ||
| self.parameters.extend( | ||
| [ | ||
| {'name': '@start_date', 'value': start_date}, | ||
| {'name': '@end_date', 'value': end_date}, | ||
| ] | ||
| ) | ||
| return self |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| from typing import List | ||
| from utils.repository import convert_list_to_tuple_string | ||
|
|
||
|
|
||
| class CosmosDBQueryBuilder: | ||
| query: str | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| self.query = "" | ||
| self.parameters = [] | ||
| self.select_conditions = [] | ||
| self.where_conditions = [] | ||
| self.limit = None | ||
| self.offset = None | ||
|
|
||
| def add_select_conditions(self, column: List[str] = None): | ||
| column = column if column else ["*"] | ||
| self.select_conditions.extend(column) | ||
| return self | ||
|
|
||
| def add_sql_in_condition( | ||
| self, attribute: str = None, ids_list: List[str] = None | ||
| ): | ||
| if ids_list and attribute and len(ids_list) > 0: | ||
| ids_values = convert_list_to_tuple_string(ids_list) | ||
| self.where_conditions.append(f"c.{attribute} IN {ids_values}") | ||
| return self | ||
|
|
||
| def add_sql_where_equal_condition(self, data: dict = None): | ||
| if data: | ||
| for k, v in data.items(): | ||
| condition = f"c.{k} = @{k}" | ||
| self.where_conditions.append(condition) | ||
| self.parameters.append({'name': f'@{k}', 'value': v}) | ||
| return self | ||
|
|
||
| def add_sql_visibility_condition(self, visible_only: bool): | ||
| if visible_only: | ||
| self.where_conditions.append('NOT IS_DEFINED(c.deleted)') | ||
| return self | ||
|
|
||
| def add_sql_limit_condition(self, limit): | ||
| if limit and isinstance(limit, int): | ||
kellycastrof marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self.limit = limit | ||
| return self | ||
|
|
||
| def add_sql_offset_condition(self, offset): | ||
| if offset and isinstance(offset, int): | ||
| self.offset = offset | ||
| return self | ||
|
|
||
| def build_select(self): | ||
| if len(self.select_conditions) < 1: | ||
| self.select_conditions.append("*") | ||
| return ",".join(self.select_conditions) | ||
|
|
||
| def build_where(self): | ||
| if len(self.where_conditions) > 0: | ||
| return "WHERE " + " AND ".join(self.where_conditions) | ||
| else: | ||
| return "" | ||
|
|
||
| def build_offset(self): | ||
| if self.offset: | ||
| self.parameters.append({'name': '@offset', 'value': self.offset}) | ||
| return "OFFSET @offset" | ||
| else: | ||
| return "" | ||
|
|
||
| def build_limit(self): | ||
| if self.limit: | ||
| self.parameters.append({'name': '@limit', 'value': self.limit}) | ||
| return "LIMIT @limit" | ||
| else: | ||
| return "" | ||
|
|
||
| def build(self): | ||
| self.query = """ | ||
| SELECT {select_conditions} FROM c | ||
| {where_conditions} | ||
| {offset_condition} | ||
| {limit_condition} | ||
| """.format( | ||
| select_conditions=self.build_select(), | ||
| where_conditions=self.build_where(), | ||
| offset_condition=self.build_offset(), | ||
| limit_condition=self.build_limit(), | ||
| ) | ||
| return self | ||
|
|
||
| def get_query(self): | ||
| return self.query | ||
|
|
||
| def get_parameters(self): | ||
| return self.parameters | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.