-
Notifications
You must be signed in to change notification settings - Fork 0
feat: TT-402 put v2 time entries #347
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
10 commits
Select commit
Hold shift + click to select a range
adab8f4
feat: TT-402 add put time entries
Jobzi c04ec5a
refactor: TT-402 rebase post time entry
Jobzi 4c1ff5e
test: TT-402 add integration test of UPDATE
Jobzi 7ea2377
refactor: TT-402 delete time_entires_sql_dao_test
Jobzi 09271e5
refactor: TT-404 revert changes _db.py
Jobzi a60b3eb
fix: TT-402 solve conflict merge
Jobzi 406e7f4
fix: TT-402 Resolve comments
Jobzi 972cdaa
refactor: TT-402 Andres's resolve comments
Jobzi a9ebe95
fix: TT-402 refactor azure update endpoint
Jobzi c0ec2c1
fix: TT-402 change name test
Jobzi 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
Next
Next commit
feat: TT-402 add put time entries
- Loading branch information
commit adab8f40ab6744e693ce45a61755540df21b472f
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
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,41 @@ | ||
| import pytest | ||
|
|
||
| from time_tracker.time_entries._infrastructure import TimeEntriesSQLDao | ||
|
|
||
| from time_tracker._infrastructure import DB | ||
|
|
||
|
|
||
| @pytest.fixture(name='create_time_entry_fake_dao') | ||
| def _create_fake_dao() -> TimeEntriesSQLDao: | ||
| db_fake = DB('sqlite:///:memory:') | ||
| dao = TimeEntriesSQLDao(db_fake) | ||
| return dao | ||
|
|
||
|
|
||
| def test_update__returns_an_time_entry_dto__when_found_one_time_entry_to_update( | ||
| create_time_entry_fake_dao, time_entry_factory, insert_activity, activity_factory | ||
| ): | ||
| dao = create_time_entry_fake_dao | ||
| inserted_activity = insert_activity(activity_factory(), dao.db) | ||
| existent_time_entries = time_entry_factory(activity_id=inserted_activity.id, technologies="[jira,sql]") | ||
| inserted_time_entries = dao.create(existent_time_entries).__dict__ | ||
| time_entry_id = inserted_time_entries["id"] | ||
| inserted_time_entries.update({"description": "description updated"}) | ||
|
|
||
| time_entry = dao.update(time_entry_id=time_entry_id, time_entry_data=inserted_time_entries) | ||
|
|
||
| assert time_entry.id == time_entry_id | ||
| assert time_entry.description == "description updated" | ||
|
|
||
|
|
||
| def test_update__returns_none__when_doesnt_found_one_time_entry_to_update( | ||
| create_time_entry_fake_dao, time_entry_factory, insert_activity, activity_factory | ||
| ): | ||
| dao = create_time_entry_fake_dao | ||
| inserted_activity = insert_activity(activity_factory(), dao.db) | ||
| existent_time_entries = time_entry_factory(activity_id=inserted_activity.id, technologies="[jira,sql]") | ||
| inserted_time_entries = dao.create(existent_time_entries).__dict__ | ||
|
|
||
| time_entry = dao.update(0, inserted_time_entries) | ||
|
|
||
| assert time_entry is None |
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
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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| # flake8: noqa | ||
| from ._time_entries import create_time_entry, delete_time_entry | ||
| from ._time_entries import create_time_entry, delete_time_entry | ||
| from ._time_entries import update_time_entry |
3 changes: 2 additions & 1 deletion
3
V2/time_tracker/time_entries/_application/_time_entries/__init__.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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| # flake8: noqa | ||
| from ._create_time_entry import create_time_entry | ||
| from ._delete_time_entry import delete_time_entry | ||
| from ._delete_time_entry import delete_time_entry | ||
| from ._update_time_entry import update_time_entry |
48 changes: 48 additions & 0 deletions
48
V2/time_tracker/time_entries/_application/_time_entries/_update_time_entry.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,48 @@ | ||
| import dataclasses | ||
| import json | ||
| import logging | ||
|
|
||
| import azure.functions as func | ||
|
|
||
| from time_tracker.time_entries._infrastructure import TimeEntriesSQLDao | ||
| from time_tracker.time_entries._domain import TimeEntryService, TimeEntry, _use_cases | ||
| from time_tracker._infrastructure import DB | ||
|
|
||
|
|
||
|
|
||
| def update_time_entry(req: func.HttpRequest) -> func.HttpResponse: | ||
| logging.info( | ||
| 'Python HTTP trigger function processed a request to update an time entry.' | ||
| ) | ||
| time_entry_id = req.route_params.get('id') | ||
| time_entry_data = req.get_json() if req.get_body() else {} | ||
| time_entry_keys = [field.name for field in dataclasses.fields(TimeEntry)] | ||
|
|
||
| if all(key in time_entry_keys for key in time_entry_data.keys()): | ||
| try: | ||
| response = _update(int(time_entry_id), time_entry_data) | ||
| status_code = 200 | ||
| except ValueError: | ||
| response = b'Invalid ID' | ||
| status_code = 400 | ||
| else: | ||
| response = b'Incorrect time entry body' | ||
Jobzi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| status_code = 400 | ||
|
|
||
| return func.HttpResponse( | ||
| body=response, status_code=status_code, mimetype="application/json" | ||
| ) | ||
|
|
||
|
|
||
| def _update(time_entry_id: int, time_entry_data: dict) -> str: | ||
| database = DB() | ||
| time_entry_use_case = _use_cases.UpdateTimeEntryUseCase( | ||
| _create_time_entry_service(database) | ||
| ) | ||
| time_entry = time_entry_use_case.update_time_entry(time_entry_id, time_entry_data) | ||
| return json.dumps(time_entry.__dict__) if time_entry else b'Not Found' | ||
|
|
||
|
|
||
| def _create_time_entry_service(db: DB): | ||
| time_entry_sql = TimeEntriesSQLDao(db) | ||
Jobzi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return TimeEntryService(time_entry_sql) | ||
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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| # flake8: noqa | ||
| from ._time_entry import TimeEntry | ||
| from ._time_entry import TimeEntry |
2 changes: 1 addition & 1 deletion
2
V2/time_tracker/time_entries/_domain/_persistence_contracts/__init__.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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| # flake8: noqa | ||
| from ._time_entries_dao import TimeEntriesDao | ||
| from ._time_entries_dao import TimeEntriesDao |
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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| # flake8: noqa | ||
| from ._time_entry import TimeEntryService | ||
| from ._time_entry import TimeEntryService |
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| # flake8: noqa | ||
| from ._create_time_entry_use_case import CreateTimeEntryUseCase | ||
| from ._delete_time_entry_use_case import DeleteTimeEntryUseCase | ||
| from ._update_time_entry_use_case import UpdateTimeEntryUseCase |
11 changes: 11 additions & 0 deletions
11
V2/time_tracker/time_entries/_domain/_use_cases/_update_time_entry_use_case.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,11 @@ | ||
| from time_tracker.time_entries._domain import TimeEntryService, TimeEntry | ||
|
|
||
|
|
||
| class UpdateTimeEntryUseCase: | ||
| def __init__(self, time_entry_service: TimeEntryService): | ||
| self.time_entry_service = time_entry_service | ||
|
|
||
| def update_time_entry( | ||
| self, time_entry_id: int, new_time_entry: dict | ||
| ) -> TimeEntry: | ||
| return self.time_entry_service.update(time_entry_id, new_time_entry) |
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| # flake8: noqa | ||
| from ._application import create_time_entry | ||
| from ._application import delete_time_entry | ||
| from ._application import delete_time_entry | ||
| from ._application import update_time_entry |
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.