diff --git a/src/backend/app/projects/project_crud.py b/src/backend/app/projects/project_crud.py index f73a664867..51788cb0cc 100644 --- a/src/backend/app/projects/project_crud.py +++ b/src/backend/app/projects/project_crud.py @@ -81,6 +81,7 @@ def get_projects( limit: int = 100, db_objects: bool = False, hashtags: List[str] = None, + search: str = None, ): filters = [] if user_id: @@ -89,6 +90,9 @@ def get_projects( if hashtags: filters.append(db_models.DbProject.hashtags.op("&&")(hashtags)) + if search: + filters.append(db_models.DbProject.project_name_prefix.ilike(f"%{search}%")) + if len(filters) > 0: db_projects = ( db.query(db_models.DbProject) @@ -113,7 +117,12 @@ def get_projects( def get_project_summaries( - db: Session, user_id: int, skip: int = 0, limit: int = 100, hashtags: str = None + db: Session, + user_id: int, + skip: int = 0, + limit: int = 100, + hashtags: str = None, + search: str = None, ): # TODO: Just get summaries, something like: # db_projects = db.query(db_models.DbProject).with_entities( @@ -130,7 +139,7 @@ def get_project_summaries( # .filter( # db_models.DbProject.author_id == user_id).offset(skip).limit(limit).all() - db_projects = get_projects(db, user_id, skip, limit, True, hashtags) + db_projects = get_projects(db, user_id, skip, limit, True, hashtags, search) return convert_to_project_summaries(db_projects) diff --git a/src/backend/app/projects/project_routes.py b/src/backend/app/projects/project_routes.py index a8a3401965..4d5063f5c4 100644 --- a/src/backend/app/projects/project_routes.py +++ b/src/backend/app/projects/project_routes.py @@ -120,6 +120,7 @@ async def read_project_summaries( page: int = Query(1, ge=1), # Default to page 1, must be greater than or equal to 1 results_per_page: int = Query(13, le=100), db: Session = Depends(database.get_db), + search: str = None, ): if hashtags: hashtags = hashtags.split(",") # create list of hashtags @@ -135,7 +136,9 @@ async def read_project_summaries( hasPrev = page > 1 total_pages = (total_projects + results_per_page - 1) // results_per_page - projects = project_crud.get_project_summaries(db, user_id, skip, limit, hashtags) + projects = project_crud.get_project_summaries( + db, user_id, skip, limit, hashtags, search + ) project_summaries = [ project_schemas.ProjectSummary.from_db_project(project) for project in projects ]