-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06cfde4
commit 7f59ae8
Showing
12 changed files
with
460 additions
and
326 deletions.
There are no files selected for viewing
This file contains 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 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,33 +1,50 @@ | ||
use std::collections::HashMap; | ||
|
||
use crate::diesel::QueryDsl; | ||
use crate::diesel::query_dsl::methods::DistinctDsl; | ||
use crate::error::Result; | ||
use crate::models::LightRollingStockModel; | ||
use crate::models::Retrieve; | ||
use crate::models::{ | ||
train_schedule::{ | ||
LightTrainSchedule, MechanicalEnergyConsumedBaseEco, TrainSchedule, TrainScheduleSummary, | ||
}, | ||
SimulationOutput, | ||
}; | ||
use crate::tables::timetable; | ||
use crate::DbPool; | ||
use actix_web::web::Data; | ||
use derivative::Derivative; | ||
use diesel::prelude::*; | ||
use diesel::result::Error as DieselError; | ||
use diesel::ExpressionMethods; | ||
use crate::models::List; | ||
use crate::models::NoParams; | ||
use crate::modelsv2::Model; | ||
use crate::modelsv2::Row; | ||
use crate::tables::timetablev2::dsl; | ||
use crate::views::pagination::Paginate; | ||
use crate::views::pagination::PaginatedResponse; | ||
use async_trait::async_trait; | ||
use diesel_async::AsyncPgConnection as PgConnection; | ||
use diesel_async::RunQueryDsl; | ||
use editoast_derive::Model; | ||
use editoast_derive::ModelV2; | ||
use futures::future::try_join_all; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Default, Clone, Serialize, Deserialize, ModelV2)] | ||
#[derive(Debug, Default, Clone, ModelV2, Serialize, Deserialize)] | ||
#[model(table = crate::tables::timetablev2)] | ||
#[model(changeset(public))] | ||
pub struct TimetableV2 { | ||
pub id: i64, | ||
pub electrical_profile_set_id: Option<i64>, | ||
} | ||
|
||
#[async_trait] | ||
impl List<NoParams> for TimetableV2 { | ||
async fn list_conn( | ||
conn: &mut PgConnection, | ||
page: i64, | ||
page_size: i64, | ||
_: NoParams, | ||
) -> Result<PaginatedResponse<Self>> { | ||
let timetable_rows = dsl::timetablev2 | ||
.distinct() | ||
.paginate(page, page_size) | ||
.load_and_count::<Row<TimetableV2>>(conn) | ||
.await?; | ||
|
||
let results: Vec<TimetableV2> = timetable_rows | ||
.results | ||
.into_iter() | ||
.map(Self::from_row) | ||
.collect(); | ||
|
||
Ok(PaginatedResponse { | ||
count: timetable_rows.count, | ||
previous: timetable_rows.previous, | ||
next: timetable_rows.next, | ||
results, | ||
}) | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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,11 @@ | ||
pub mod scenariov2; | ||
pub mod timetablev2; | ||
pub mod trainschedulev2; | ||
|
||
crate::routes! { | ||
|
||
trainschedulev2::routes(), | ||
timetablev2::routes(), | ||
scenariov2::routes() | ||
|
||
} |
Oops, something went wrong.