Skip to content
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

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

eckter
Copy link
Contributor

@eckter eckter commented Nov 19, 2024

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:

  1. POST /work_schedules/group: create a new group (name can be empty and autofilled (the unique name thing is just painful))
  2. GET /work_schedules/group: lists all the group ids
  3. PUT /work_schedules/group/42: insets a work schedule into an existing group
  4. GET /work_schedules/group/42: lists all the work schedules in the group
  5. DELETE /workçschedules/group/42: deletes the group and its work schedules

What I have not added but could have been nice:

  1. More details in GET /work_schedules/group (name, creation date, ...)
  2. GET /work_schedules to list them all
  3. Any kind of endpoint dealing with individual work schedules

@codecov-commenter
Copy link

codecov-commenter commented Nov 19, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 83.40426% with 39 lines in your changes missing coverage. Please review.

Project coverage is 37.89%. Comparing base (535d81d) to head (b27ef13).
Report is 33 commits behind head on dev.

Files with missing lines Patch % Lines
editoast/src/views/work_schedules.rs 84.26% 31 Missing ⚠️
front/src/common/api/generatedEditoastApi.ts 80.64% 6 Missing ⚠️
editoast/src/views/operational_studies.rs 66.66% 2 Missing ⚠️

❗ 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            
Flag Coverage Δ
editoast 73.03% <83.82%> (-0.33%) ⬇️
front 20.13% <80.64%> (+0.01%) ⬆️
gateway 2.18% <ø> (ø)
osrdyne 3.28% <ø> (ø)
railjson_generator 87.49% <ø> (ø)
tests 86.74% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@eckter eckter force-pushed the ech/work-schedule-endpoints branch 5 times, most recently from 7525cf6 to 7cb0332 Compare November 19, 2024 15:44
@github-actions github-actions bot added the area:editoast Work on Editoast Service label Nov 19, 2024
@eckter eckter force-pushed the ech/work-schedule-endpoints branch 6 times, most recently from 8f1bb19 to 5f2eca1 Compare November 20, 2024 14:28
@eckter eckter marked this pull request as ready for review November 20, 2024 14:47
@eckter eckter requested review from a team as code owners November 20, 2024 14:47
Signed-off-by: Eloi Charpentier <eloi.charpentier.42@gmail.com>
Copy link
Contributor

@woshilapin woshilapin left a 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.

@@ -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};
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f937a33

Comment on lines 381 to 392
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?;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@eckter eckter Nov 21, 2024

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

Copy link
Contributor

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 ?

Comment on lines 463 to 473
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?;
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@leovalais leovalais left a 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 :)

editoast/src/views/work_schedules.rs Outdated Show resolved Hide resolved
editoast/src/views/work_schedules.rs Outdated Show resolved Hide resolved
editoast/src/views/work_schedules.rs Outdated Show resolved Hide resolved
editoast/src/views/work_schedules.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Sh099078 Sh099078 left a 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

editoast/src/views/work_schedules.rs Outdated Show resolved Hide resolved
editoast/src/views/work_schedules.rs Outdated Show resolved Hide resolved
editoast/src/views/work_schedules.rs Outdated Show resolved Hide resolved
editoast/src/views/work_schedules.rs Show resolved Hide resolved
Copy link
Contributor

@SharglutDev SharglutDev left a 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)

front/public/locales/en/errors.json Outdated Show resolved Hide resolved
@github-actions github-actions bot added the area:front Work on Standard OSRD Interface modules label Nov 22, 2024
Copy link
Contributor

@leovalais leovalais left a 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!

editoast/src/views/work_schedules.rs Outdated Show resolved Hide resolved
editoast/src/views/work_schedules.rs Outdated Show resolved Hide resolved
…ion and viewing

Update editoast/src/views/work_schedules.rs

Co-authored-by: Léo Valais <leo.valais97@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:editoast Work on Editoast Service area:front Work on Standard OSRD Interface modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants