-
Notifications
You must be signed in to change notification settings - Fork 43
Refactor endpoints post Runtime integration #1733
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
base: main
Are you sure you want to change the base?
Conversation
e1c927f to
a1cac25
Compare
…Add use cases for associating and retrieving runtime jobs. Adapt tests to new messages.
c6363cf to
acf8201
Compare
korgan00
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code wise it looks good to me.
Should we control something about permissions in the Post?
|
@ElePT I think you said this was ready for review, right? Can I click on "Ready of review"? |
Co-authored-by: Goyo <korgan00@gmail.com>
| RuntimeJob.objects.create( | ||
| job=job, | ||
| runtime_job=runtime_job, | ||
| runtime_session=runtime_session, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know accessing to the Django orm in use cases is tempting, but if we are following the Repository approach, all the database accesses (that means, any call to Model.objects.whatever()) should be done through a repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this specific case, this use case is very simple. I guess you can get rid of the use case and call to the repository directly from the endpoint. Having one single call to one repository in the controller is acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point, this case is so simple that I struggled to find the balance between following the approach of other endpoints and adding too much boilerplate. I am fine updating it.
| class GetRuntimeJobsUseCase: | ||
| """Retrieve all RuntimeJob objects associated to a given Job.""" | ||
|
|
||
| jobs_repository = JobsRepository() | ||
|
|
||
| def execute(self, job_id: UUID) -> list[RuntimeJob]: | ||
| """ | ||
| Return all RuntimeJob objects associated to a given Job. | ||
| Args: | ||
| job_id: Target Job ID. | ||
| Returns: | ||
| The list of RuntimeJobs. | ||
| Raises: | ||
| NotFoundError: If the job does not exist or access is denied. | ||
| """ | ||
| job = self.jobs_repository.get_job_by_id(job_id) | ||
|
|
||
| if job is None: | ||
| raise NotFoundError(f"Job [{job_id}] not found") | ||
|
|
||
| return job.runtime_jobs.all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, just create (or reuse) a repository RuntimeRepository with this logic and call it from the endpoint. In the repository, you can safely call to any Model.objects.whatever() method you want :)
Tansito
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this refactor Elena we should be able also to remove this file and also rename the folder jobs_new to just jobs.
I'm fine if we do this last thing later to facilitate the review of the PR also.
| @@ -1,8 +1,9 @@ | |||
| """ | |||
| Django Rest framework Job views for api application: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially now that we removed the end-points from this file we should be able to remove it entirely 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will give it a try
Summary
Details and comments
Follow-up of #1707