From d1ac52577da80c36dac1a67766c7588578670c4e Mon Sep 17 00:00:00 2001 From: Sujan Adhikari <109404840+Sujanadh@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:31:16 +0545 Subject: [PATCH] Instructions in create and edit project (#1224) * fix: update schema to edit only required fields * feat: added instructions in project create and edit --------- Co-authored-by: sujanadh --- src/backend/app/projects/project_crud.py | 8 ++++++++ src/backend/app/projects/project_routes.py | 2 +- src/backend/app/projects/project_schemas.py | 14 +++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/backend/app/projects/project_crud.py b/src/backend/app/projects/project_crud.py index aff88144e2..043adbcbf7 100644 --- a/src/backend/app/projects/project_crud.py +++ b/src/backend/app/projects/project_crud.py @@ -203,6 +203,12 @@ async def partial_update_project_info( db_project_info.description = project_metadata.description if project_metadata.short_description: db_project_info.short_description = project_metadata.short_description + if project_metadata.per_task_instructions: + db_project_info.per_task_instructions = ( + project_metadata.per_task_instructions + ) + if project_metadata.hashtags: + db_project.hashtags = project_metadata.hashtags db.commit() db.refresh(db_project) @@ -280,6 +286,7 @@ async def create_project_with_project_info( project_name = project_metadata.project_info.name project_description = project_metadata.project_info.description project_short_description = project_metadata.project_info.short_description + project_instructions = project_metadata.project_info.per_task_instructions # create new project db_project = db_models.DbProject( @@ -296,6 +303,7 @@ async def create_project_with_project_info( name=project_name, short_description=project_short_description, description=project_description, + per_task_instructions=project_instructions, ) db.add(db_project_info) diff --git a/src/backend/app/projects/project_routes.py b/src/backend/app/projects/project_routes.py index 25bc64ab83..033807423b 100644 --- a/src/backend/app/projects/project_routes.py +++ b/src/backend/app/projects/project_routes.py @@ -337,7 +337,7 @@ async def update_project( @router.patch("/{project_id}", response_model=project_schemas.ProjectOut) async def project_partial_update( project_id: int, - project_info: project_schemas.ProjectUpdate, + project_info: project_schemas.ProjectPartialUpdate, db: Session = Depends(database.get_db), current_user: AuthUser = Depends(project_admin), ): diff --git a/src/backend/app/projects/project_schemas.py b/src/backend/app/projects/project_schemas.py index 65c39e0da6..50e02a9872 100644 --- a/src/backend/app/projects/project_schemas.py +++ b/src/backend/app/projects/project_schemas.py @@ -128,6 +128,7 @@ class ProjectInfo(BaseModel): name: str short_description: str description: str + per_task_instructions: Optional[str] = None class ProjectIn(BaseModel): @@ -196,13 +197,20 @@ class ProjectUpload(ProjectIn, ODKCentralIn): pass -class ProjectUpdate(BaseModel): - """Update project.""" +class ProjectPartialUpdate(BaseModel): + """Update projects metadata.""" name: Optional[str] = None short_description: Optional[str] = None description: Optional[str] = None - changeset_comment: Optional[str] = None + hashtags: Optional[List[str]] = None + per_task_instructions: Optional[str] = None + + +class ProjectUpdate(ProjectIn): + """Update project.""" + + pass class GeojsonFeature(BaseModel):