Skip to content

Commit 069ef53

Browse files
committed
editoast: make budget nullable in project and study
1 parent a24e487 commit 069ef53

File tree

10 files changed

+23
-19
lines changed

10 files changed

+23
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE study ALTER COLUMN budget SET NOT NULL;
2+
ALTER TABLE project ALTER COLUMN budget SET NOT NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE study ALTER COLUMN budget DROP NOT NULL;
2+
ALTER TABLE project ALTER COLUMN budget DROP NOT NULL;

editoast/openapi.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -4475,6 +4475,7 @@ components:
44754475
properties:
44764476
budget:
44774477
format: int32
4478+
nullable: true
44784479
type: integer
44794480
creation_date:
44804481
format: date-time
@@ -4505,7 +4506,6 @@ components:
45054506
- objectives
45064507
- description
45074508
- funders
4508-
- budget
45094509
- creation_date
45104510
- last_modification
45114511
- tags
@@ -4515,6 +4515,7 @@ components:
45154515
properties:
45164516
budget:
45174517
format: int32
4518+
nullable: true
45184519
type: integer
45194520
description:
45204521
maxLength: 1024
@@ -5967,6 +5968,7 @@ components:
59675968
type: string
59685969
budget:
59695970
format: int32
5971+
nullable: true
59705972
type: integer
59715973
business_code:
59725974
type: string
@@ -6010,7 +6012,6 @@ components:
60106012
- service_code
60116013
- creation_date
60126014
- last_modification
6013-
- budget
60146015
- tags
60156016
- state
60166017
- study_type
@@ -6025,6 +6026,7 @@ components:
60256026
type: string
60266027
budget:
60276028
format: int32
6029+
nullable: true
60286030
type: integer
60296031
business_code:
60306032
type: string

editoast/src/fixtures.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub mod tests {
295295
.service_code("BBB".into())
296296
.creation_date(Utc::now().naive_utc())
297297
.last_modification(Utc::now().naive_utc())
298-
.budget(0)
298+
.budget(Some(0))
299299
.tags(Tags::default())
300300
.state("some_state".into())
301301
.study_type("some_type".into())
@@ -313,7 +313,7 @@ pub mod tests {
313313
.objectives("".to_owned())
314314
.description("".to_owned())
315315
.funders("".to_owned())
316-
.budget(0)
316+
.budget(Some(0))
317317
.creation_date(Utc::now().naive_utc())
318318
.last_modification(Utc::now().naive_utc())
319319
.tags(Tags::default());

editoast/src/modelsv2/projects.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct Project {
2828
pub objectives: String,
2929
pub description: String,
3030
pub funders: String,
31-
pub budget: i32,
31+
pub budget: Option<i32>,
3232
pub creation_date: NaiveDateTime,
3333
pub last_modification: NaiveDateTime,
3434
#[model(remote = "Vec<Option<String>>")]
@@ -239,7 +239,7 @@ pub mod test {
239239
// Patch a project
240240
let mut project = project_fixture.model.clone();
241241
project.name = "update_name".into();
242-
project.budget = 1000;
242+
project.budget = Some(1000);
243243
project.save(conn).await.unwrap();
244244
let project = Project::retrieve(conn, project.id).await.unwrap().unwrap();
245245
assert_eq!(project.name, String::from("update_name"));

editoast/src/modelsv2/study.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct Study {
3131
pub start_date: Option<NaiveDate>,
3232
pub expected_end_date: Option<NaiveDate>,
3333
pub actual_end_date: Option<NaiveDate>,
34-
pub budget: i32,
34+
pub budget: Option<i32>,
3535
#[model(remote = "Vec<Option<String>>")]
3636
pub tags: Tags,
3737
pub state: String,

editoast/src/tables.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ diesel::table! {
402402
description -> Varchar,
403403
#[max_length = 255]
404404
funders -> Varchar,
405-
budget -> Int4,
405+
budget -> Nullable<Int4>,
406406
creation_date -> Timestamptz,
407407
last_modification -> Timestamptz,
408408
tags -> Array<Nullable<Text>>,
@@ -612,7 +612,7 @@ diesel::table! {
612612
start_date -> Nullable<Date>,
613613
expected_end_date -> Nullable<Date>,
614614
actual_end_date -> Nullable<Date>,
615-
budget -> Int4,
615+
budget -> Nullable<Int4>,
616616
tags -> Array<Nullable<Text>>,
617617
#[max_length = 16]
618618
state -> Varchar,

editoast/src/views/projects.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ struct ProjectCreateForm {
7676
#[serde(default)]
7777
#[schema(max_length = 1024)]
7878
pub funders: String,
79-
#[serde(default)]
80-
pub budget: i32,
79+
pub budget: Option<i32>,
8180
/// The id of the image document
8281
pub image: Option<i64>,
8382
#[serde(default)]
@@ -269,7 +268,7 @@ impl From<ProjectPatchForm> for Changeset<Project> {
269268
.flat_description(project.description)
270269
.flat_objectives(project.objectives)
271270
.flat_funders(project.funders)
272-
.flat_budget(project.budget)
271+
.flat_budget(Some(project.budget))
273272
.flat_image(Some(project.image))
274273
.flat_tags(project.tags)
275274
}

editoast/src/views/study.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ struct StudyCreateForm {
7474
pub business_code: String,
7575
#[serde(default)]
7676
pub service_code: String,
77-
#[serde(default)]
78-
pub budget: i32,
77+
pub budget: Option<i32>,
7978
#[serde(default)]
8079
pub tags: Tags,
8180
pub state: String,
@@ -328,7 +327,7 @@ impl StudyPatchForm {
328327
.flat_start_date(Some(self.start_date))
329328
.flat_expected_end_date(Some(self.expected_end_date))
330329
.flat_actual_end_date(Some(self.actual_end_date))
331-
.flat_budget(self.budget)
330+
.flat_budget(Some(self.budget))
332331
.flat_tags(self.tags)
333332
.flat_state(self.state)
334333
.flat_study_type(self.study_type);

front/src/common/api/osrdEditoastApi.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,7 @@ export type ElectrificationsOnPathResponse = {
19261926
};
19271927
export type Tags = string[];
19281928
export type Project = {
1929-
budget: number;
1929+
budget?: number | null;
19301930
creation_date: string;
19311931
description: string;
19321932
funders: string;
@@ -1958,7 +1958,7 @@ export type Ordering =
19581958
| 'LastModifiedDesc'
19591959
| 'LastModifiedAsc';
19601960
export type ProjectCreateForm = {
1961-
budget?: number;
1961+
budget?: number | null;
19621962
description?: string;
19631963
funders?: string;
19641964
/** The id of the image document */
@@ -1979,7 +1979,7 @@ export type ProjectPatchForm = {
19791979
};
19801980
export type Study = {
19811981
actual_end_date?: string | null;
1982-
budget: number;
1982+
budget?: number | null;
19831983
business_code: string;
19841984
creation_date: string;
19851985
description: string;
@@ -2013,7 +2013,7 @@ export type StudyResponse = Study & {
20132013
};
20142014
export type StudyCreateForm = {
20152015
actual_end_date?: string | null;
2016-
budget?: number;
2016+
budget?: number | null;
20172017
business_code?: string;
20182018
description?: string;
20192019
expected_end_date?: string | null;

0 commit comments

Comments
 (0)