-
Notifications
You must be signed in to change notification settings - Fork 44
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
editoast: work-schedules: add endpoints for easier edition and viewing #9785
base: dev
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## dev #9785 +/- ##
========================================
Coverage 37.88% 37.89%
========================================
Files 992 994 +2
Lines 90965 91403 +438
Branches 1176 1176
========================================
+ Hits 34463 34635 +172
- Misses 56048 56314 +266
Partials 454 454
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
7525cf6
to
7cb0332
Compare
8f1bb19
to
5f2eca1
Compare
5f2eca1
to
53adda9
Compare
Signed-off-by: Eloi Charpentier <eloi.charpentier.42@gmail.com>
53adda9
to
2c360cb
Compare
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.
Nice work, just some comments about if we should do more transactional operations or not.
editoast/src/views/work_schedules.rs
Outdated
@@ -26,19 +10,56 @@ use crate::views::path::projection::PathProjection; | |||
use crate::views::AuthenticationExt; | |||
use crate::views::AuthorizationError; | |||
use crate::AppState; | |||
use axum::extract::State; | |||
use axum::extract::{Json, Path}; |
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.
nitpick: Can you unmerge the use
, it's preferable for the diff (but hard to enforce in the formatter without being a pain for developers)
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.
Fixed in f937a33
editoast/src/views/work_schedules.rs
Outdated
let work_schedule_ids = WorkSchedule::list(conn, selection_setting) | ||
.await? | ||
.into_iter() | ||
.map(|work_schedule| work_schedule.id); | ||
|
||
// Delete them | ||
use crate::models::DeleteBatch; | ||
let conn = &mut db_pool.get().await?; | ||
WorkSchedule::delete_batch(conn, work_schedule_ids).await?; | ||
|
||
// Delete the group itself | ||
WorkScheduleGroup::delete(&work_schedule_group, conn).await?; |
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.
Should we run all of this into a transaction (or at least the delete_batch
and delete
)? I wonder how much of a problem it is if remove all of the work schedule and miss the removal of the work schedule group? @eckter Any opinion? Feel free to resolve if you think that is not a problem.
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 didn't even know transactions were a thing in this context 😄
I don't think it would be an issue, but it would still generally make sense to run a transaction. I'll do the change.
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.
Fixed in f937a33
Please let me know if I did the transaction wrong, I did the same thing as in other places
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.
If I am not mistaken in this comment the delete_batch and the transaction might not be needed. What do you think @woshilapin ?
editoast/src/views/work_schedules.rs
Outdated
WorkScheduleGroup::retrieve_or_fail(conn, group_id, || { | ||
WorkScheduleError::WorkScheduleGroupNotFound { id: group_id } | ||
}) | ||
.await?; | ||
|
||
// Create work schedules | ||
let work_schedules_changesets = work_schedules | ||
.into_iter() | ||
.map(|work_schedule| work_schedule.into_work_schedule_changeset(group_id)) | ||
.collect::<Vec<_>>(); | ||
let work_schedules = WorkSchedule::create_batch(conn, work_schedules_changesets).await?; |
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 here, maybe we need a transaction, because I'm not sure what happens if the work schedule group is deleted in between?
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.
Fixed in f937a33
It would have created "orphaned" work schedules that couldn't be used, queried, or deleted
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.
LGTM, a few non-blocking comments :)
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.
Great PR ! I added a few comments but mostly nitpicks
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.
Lgtm for front part (not tested)
62011da
to
61426f6
Compare
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.
LGTM, thanks for the changes!
2f59abc
to
fadd260
Compare
…ion and viewing Update editoast/src/views/work_schedules.rs Co-authored-by: Léo Valais <leo.valais97@gmail.com>
fadd260
to
b27ef13
Compare
Would fix 2/3 of https://github.com/osrd-project/osrd-confidential/issues/838, the rest is changing the etl for batched imports.
I've added a few more endpoints than just what was in the ticket, to have a complete workflow:
POST /work_schedules/group
: create a new group (name can be empty and autofilled (the unique name thing is just painful))GET /work_schedules/group
: lists all the group idsPUT /work_schedules/group/42
: insets a work schedule into an existing groupGET /work_schedules/group/42
: lists all the work schedules in the groupDELETE /workçschedules/group/42
: deletes the group and its work schedulesWhat I have not added but could have been nice:
GET /work_schedules/group
(name, creation date, ...)GET /work_schedules
to list them all