feat: 增加菜地搜索功能
This commit is contained in:
12
.idea/workspace.xml
generated
12
.idea/workspace.xml
generated
@@ -6,7 +6,7 @@
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="92592c29-2276-4c2c-bd45-9ab94e25491d" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/schemas/patch.py" beforeDir="false" afterPath="$PROJECT_DIR$/schemas/patch.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/routers/patch.py" beforeDir="false" afterPath="$PROJECT_DIR$/routers/patch.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/service/patch_service.py" beforeDir="false" afterPath="$PROJECT_DIR$/service/patch_service.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@@ -26,9 +26,9 @@
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectColorInfo"><![CDATA[{
|
||||
"associatedIndex": 7
|
||||
}]]></component>
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 7
|
||||
}</component>
|
||||
<component name="ProjectId" id="3J4P6AjqhDBRxWCujlbOFJb7BqN" />
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
|
||||
<ConfirmationsSetting value="2" id="Add" />
|
||||
@@ -41,6 +41,7 @@
|
||||
"keyToString": {
|
||||
"FastAPI.patch-service.executor": "Run",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
"last_opened_file_path": "D:/Cxx/PythonProjects/patch-service/routers",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
@@ -91,6 +92,7 @@
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1788917189828</updated>
|
||||
<workItem from="1788917190899" duration="18264000" />
|
||||
<workItem from="1789023303581" duration="1297000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
@@ -98,6 +100,6 @@
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||
<SUITE FILE_PATH="coverage/patch_service$patch_service.coverage" NAME="patch-service Coverage Results" MODIFIED="1788951341519" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
|
||||
<SUITE FILE_PATH="coverage/patch_service$patch_service.coverage" NAME="patch-service Coverage Results" MODIFIED="1789023884564" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -15,8 +15,8 @@ def create(data: PatchCreate, db: Session = Depends(get_db)):
|
||||
|
||||
|
||||
@router.get("", response_model=list[PatchResponse])
|
||||
def list_all(db: Session = Depends(get_db)):
|
||||
return patch_service.get_patches(db)
|
||||
def list_all(keyword: str | None, db: Session = Depends(get_db)):
|
||||
return patch_service.get_patches(db, keyword)
|
||||
|
||||
|
||||
@router.get("/{patch_id}", response_model=PatchResponse)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import select, delete
|
||||
from sqlalchemy import select, delete, or_
|
||||
from sqlalchemy.orm import Session, selectinload
|
||||
|
||||
from models.patch import Patches, Crops, Records
|
||||
@@ -14,9 +14,21 @@ def create_patch(db: Session, data: PatchCreate) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def get_patches(db: Session) -> list[PatchResponse]:
|
||||
patches = db.execute(select(Patches)).scalars().all()
|
||||
def get_patches(db: Session, keyword: str | None = None) -> list[PatchResponse]:
|
||||
stmt = select(Patches)
|
||||
|
||||
if keyword:
|
||||
like_pattern = f"%{keyword}%"
|
||||
stmt = stmt.where(
|
||||
or_(
|
||||
Patches.name.ilike(like_pattern),
|
||||
Patches.location.ilike(like_pattern),
|
||||
)
|
||||
)
|
||||
|
||||
patches = db.execute(stmt).scalars().all()
|
||||
result = []
|
||||
|
||||
for p in patches:
|
||||
crop = db.execute(
|
||||
select(Crops).where(Crops.patch_id == p.id)
|
||||
@@ -42,6 +54,7 @@ def get_patches(db: Session) -> list[PatchResponse]:
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def get_patch(db: Session, patch_id: int) -> PatchResponse | None:
|
||||
patch = db.execute(
|
||||
select(Patches).where(Patches.id == patch_id)
|
||||
|
||||
Reference in New Issue
Block a user