Skip to content

Commit

Permalink
Instructions in create and edit project (#1224)
Browse files Browse the repository at this point in the history
* fix: update schema to edit only required fields

* feat: added instructions in project create and edit

---------

Co-authored-by: sujanadh <[email protected]>
  • Loading branch information
Sujanadh and sujanadh authored Feb 16, 2024
1 parent 331bbd6 commit d1ac525
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
):
Expand Down
14 changes: 11 additions & 3 deletions src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class ProjectInfo(BaseModel):
name: str
short_description: str
description: str
per_task_instructions: Optional[str] = None


class ProjectIn(BaseModel):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit d1ac525

Please sign in to comment.