Skip to content

Commit

Permalink
editoast: remove serde default from project and study
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadjetz committed Apr 16, 2024
1 parent bde4844 commit b050e4b
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- This file should undo anything in `up.sql`

ALTER TABLE "project"
ALTER "objectives" DROP DEFAULT,
ALTER "objectives" SET NOT NULL;

ALTER TABLE "project"
ALTER "description" DROP DEFAULT,
ALTER "description" SET NOT NULL;

ALTER TABLE "project"
ALTER "funders" DROP DEFAULT,
ALTER "funders" SET NOT NULL;

ALTER TABLE "study"
ALTER "description" DROP DEFAULT,
ALTER "description" SET NOT NULL;

ALTER TABLE "study"
ALTER "business_code" DROP DEFAULT,
ALTER "business_code" SET NOT NULL;

ALTER TABLE "study"
ALTER "service_code" DROP DEFAULT,
ALTER "service_code" SET NOT NULL;

ALTER TABLE "study"
ALTER "study_type" DROP DEFAULT,
ALTER "study_type" SET NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- Your SQL goes here

ALTER TABLE "project"
ALTER "objectives" SET DEFAULT '',
ALTER "objectives" DROP NOT NULL;

ALTER TABLE "project"
ALTER "description" SET DEFAULT '',
ALTER "description" DROP NOT NULL;

ALTER TABLE "project"
ALTER "funders" SET DEFAULT '',
ALTER "funders" DROP NOT NULL;

ALTER TABLE "study"
ALTER "description" SET DEFAULT '',
ALTER "description" DROP NOT NULL;

ALTER TABLE "study"
ALTER "business_code" SET DEFAULT '',
ALTER "business_code" DROP NOT NULL;

ALTER TABLE "study"
ALTER "service_code" SET DEFAULT '',
ALTER "service_code" DROP NOT NULL;

ALTER TABLE "study"
ALTER "study_type" SET DEFAULT '',
ALTER "study_type" DROP NOT NULL;
21 changes: 14 additions & 7 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4819,8 +4819,10 @@ components:
format: date-time
type: string
description:
nullable: true
type: string
funders:
nullable: true
type: string
id:
format: int64
Expand All @@ -4835,15 +4837,13 @@ components:
name:
type: string
objectives:
nullable: true
type: string
tags:
$ref: '#/components/schemas/Tags'
required:
- id
- name
- objectives
- description
- funders
- creation_date
- last_modification
- tags
Expand All @@ -4857,9 +4857,11 @@ components:
type: integer
description:
maxLength: 1024
nullable: true
type: string
funders:
maxLength: 1024
nullable: true
type: string
image:
description: The id of the image document
Expand All @@ -4871,6 +4873,7 @@ components:
type: string
objectives:
maxLength: 4096
nullable: true
type: string
tags:
$ref: '#/components/schemas/Tags'
Expand Down Expand Up @@ -6615,11 +6618,13 @@ components:
nullable: true
type: integer
business_code:
nullable: true
type: string
creation_date:
format: date-time
type: string
description:
nullable: true
type: string
expected_end_date:
format: date
Expand All @@ -6637,6 +6642,7 @@ components:
format: int64
type: integer
service_code:
nullable: true
type: string
start_date:
format: date
Expand All @@ -6645,20 +6651,17 @@ components:
state:
type: string
study_type:
nullable: true
type: string
tags:
$ref: '#/components/schemas/Tags'
required:
- id
- name
- description
- business_code
- service_code
- creation_date
- last_modification
- tags
- state
- study_type
- project_id
type: object
StudyCreateForm:
Expand All @@ -6673,8 +6676,10 @@ components:
nullable: true
type: integer
business_code:
nullable: true
type: string
description:
nullable: true
type: string
expected_end_date:
format: date
Expand All @@ -6683,6 +6688,7 @@ components:
name:
type: string
service_code:
nullable: true
type: string
start_date:
format: date
Expand All @@ -6691,6 +6697,7 @@ components:
state:
type: string
study_type:
nullable: true
type: string
tags:
$ref: '#/components/schemas/Tags'
Expand Down
7 changes: 0 additions & 7 deletions editoast/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,12 @@ pub mod tests {
let project = project.await;
let study_model = Study::changeset()
.name("test_study".into())
.description("test".into())
.creation_date(Utc::now().naive_utc())
.business_code("AAA".into())
.service_code("BBB".into())
.creation_date(Utc::now().naive_utc())
.last_modification(Utc::now().naive_utc())
.budget(Some(0))
.tags(Tags::default())
.state("some_state".into())
.study_type("some_type".into())
.project_id(project.id());
StudyFixtureSet {
project,
Expand All @@ -344,9 +340,6 @@ pub mod tests {
pub async fn project(db_pool: Data<DbPool>) -> TestFixture<Project> {
let project_model = Project::changeset()
.name("test_project".to_owned())
.objectives("".to_owned())
.description("".to_owned())
.funders("".to_owned())
.budget(Some(0))
.creation_date(Utc::now().naive_utc())
.last_modification(Utc::now().naive_utc())
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/modelsv2/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ editoast_common::schemas! {
pub struct Project {
pub id: i64,
pub name: String,
pub objectives: String,
pub description: String,
pub funders: String,
pub objectives: Option<String>,
pub description: Option<String>,
pub funders: Option<String>,
pub budget: Option<i32>,
pub creation_date: NaiveDateTime,
pub last_modification: NaiveDateTime,
Expand Down
8 changes: 4 additions & 4 deletions editoast/src/modelsv2/study.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ use crate::DbPool;
pub struct Study {
pub id: i64,
pub name: String,
pub description: String,
pub business_code: String,
pub service_code: String,
pub description: Option<String>,
pub business_code: Option<String>,
pub service_code: Option<String>,
pub creation_date: NaiveDateTime,
pub last_modification: NaiveDateTime,
pub start_date: Option<NaiveDate>,
Expand All @@ -43,7 +43,7 @@ pub struct Study {
#[model(remote = "Vec<Option<String>>")]
pub tags: Tags,
pub state: String,
pub study_type: String,
pub study_type: Option<String>,
pub project_id: i64,
}

Expand Down
14 changes: 7 additions & 7 deletions editoast/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ diesel::table! {
#[max_length = 128]
name -> Varchar,
#[max_length = 4096]
objectives -> Varchar,
objectives -> Nullable<Varchar>,
#[max_length = 1024]
description -> Varchar,
description -> Nullable<Varchar>,
#[max_length = 255]
funders -> Varchar,
funders -> Nullable<Varchar>,
budget -> Nullable<Int4>,
creation_date -> Timestamptz,
last_modification -> Timestamptz,
Expand Down Expand Up @@ -620,11 +620,11 @@ diesel::table! {
#[max_length = 128]
name -> Varchar,
#[max_length = 1024]
description -> Varchar,
description -> Nullable<Varchar>,
#[max_length = 128]
business_code -> Varchar,
business_code -> Nullable<Varchar>,
#[max_length = 128]
service_code -> Varchar,
service_code -> Nullable<Varchar>,
creation_date -> Timestamptz,
last_modification -> Timestamptz,
start_date -> Nullable<Date>,
Expand All @@ -635,7 +635,7 @@ diesel::table! {
#[max_length = 16]
state -> Varchar,
#[max_length = 100]
study_type -> Varchar,
study_type -> Nullable<Varchar>,
project_id -> Int8,
}
}
Expand Down
22 changes: 12 additions & 10 deletions editoast/src/views/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,12 @@ pub struct QueryParams {
struct ProjectCreateForm {
#[schema(max_length = 128)]
pub name: String,
#[serde(default)]
#[schema(max_length = 1024)]
pub description: String,
#[serde(default)]
pub description: Option<String>,
#[schema(max_length = 4096)]
pub objectives: String,
#[serde(default)]
pub objectives: Option<String>,
#[schema(max_length = 1024)]
pub funders: String,
pub funders: Option<String>,
pub budget: Option<i32>,
/// The id of the image document
pub image: Option<i64>,
Expand Down Expand Up @@ -278,9 +275,9 @@ impl From<ProjectPatchForm> for Changeset<Project> {
fn from(project: ProjectPatchForm) -> Self {
Project::changeset()
.flat_name(project.name)
.flat_description(project.description)
.flat_objectives(project.objectives)
.flat_funders(project.funders)
.description(project.description)
.objectives(project.objectives)
.funders(project.funders)
.flat_budget(Some(project.budget))
.flat_image(Some(project.image))
.flat_tags(project.tags)
Expand Down Expand Up @@ -350,7 +347,12 @@ pub mod test {
let app = create_test_service().await;
let req = TestRequest::post()
.uri("/projects")
.set_json(json!({ "name": "test_project","description": "", "objectives":"" }))
.set_json(json!({
"name": "test_project",
"description": "",
"objectives": "",
"funders": "",
}))
.to_request();
let response = call_service(&app, req).await;
assert_eq!(response.status(), StatusCode::OK);
Expand Down
29 changes: 16 additions & 13 deletions editoast/src/views/study.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,17 @@ pub enum StudyError {
#[derivative(Default)]
struct StudyCreateForm {
pub name: String,
#[serde(default)]
pub description: String,
pub description: Option<String>,
pub start_date: Option<NaiveDate>,
pub expected_end_date: Option<NaiveDate>,
pub actual_end_date: Option<NaiveDate>,
#[serde(default)]
pub business_code: String,
#[serde(default)]
pub service_code: String,
pub business_code: Option<String>,
pub service_code: Option<String>,
pub budget: Option<i32>,
#[serde(default)]
pub tags: Tags,
pub state: String,
#[serde(default)]
pub study_type: String,
pub study_type: Option<String>,
}

impl StudyCreateForm {
Expand Down Expand Up @@ -336,16 +332,16 @@ impl StudyPatchForm {
pub fn into_study_changeset(self) -> Result<Changeset<Study>> {
let study_changeset = Study::changeset()
.flat_name(self.name)
.flat_description(self.description)
.flat_business_code(self.business_code)
.flat_service_code(self.service_code)
.description(self.description)
.business_code(self.business_code)
.service_code(self.service_code)
.flat_start_date(Some(self.start_date))
.flat_expected_end_date(Some(self.expected_end_date))
.flat_actual_end_date(Some(self.actual_end_date))
.flat_budget(Some(self.budget))
.flat_tags(self.tags)
.flat_state(self.state)
.flat_study_type(self.study_type);
.study_type(self.study_type);
Study::validate(&study_changeset)?;
Ok(study_changeset)
}
Expand Down Expand Up @@ -456,7 +452,14 @@ pub mod test {
let project = project.await;
let req = TestRequest::post()
.uri(format!("/projects/{}/studies/", project.id()).as_str())
.set_json(json!({ "name": "study_test", "state": "Starting" }))
.set_json(json!({
"name": "study_test",
"description": "Study description",
"state": "Starting",
"business_code": "",
"service_code": "",
"study_type": "",
}))
.to_request();
let response = call_service(&app, req).await;
assert_eq!(response.status(), StatusCode::OK);
Expand Down
Loading

0 comments on commit b050e4b

Please sign in to comment.