Skip to content

Commit

Permalink
re-organize search
Browse files Browse the repository at this point in the history
  • Loading branch information
MorvanZhou committed Oct 17, 2023
1 parent ed40842 commit 5d9d77b
Show file tree
Hide file tree
Showing 18 changed files with 1,000 additions and 791 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = rethink-note
version = 0.1.5
version = 0.1.6
author = MorvanZhou
author_email = [email protected]
description = note taking app
Expand Down
9 changes: 7 additions & 2 deletions src/rethink/controllers/schemas/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ class AddToRecentSearchHistRequest(BaseModel):
toNid: str


class RecentSearchQueriesResponse(BaseModel):
class PutRecentSearchRequest(BaseModel):
requestId: str
nid: str


class GetRecentSearchResponse(BaseModel):
code: NonNegativeInt
message: str
requestId: str
queries: List[str]
nodes: List[NodesInfoResponse.Data.NodeInfo]
41 changes: 33 additions & 8 deletions src/rethink/controllers/search/node_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def search_user_nodes(
)


def add_to_recent_search_history(
def add_to_recent_cursor_search(
td: TokenDecode,
req: schemas.search.AddToRecentSearchHistRequest
) -> schemas.base.AcknowledgeResponse:
Expand All @@ -78,30 +78,55 @@ def add_to_recent_search_history(
message=const.get_msg_by_code(td.code, td.language),
requestId=req.requestId,
)
code = models.search.add_recent_search_nid(uid=td.uid, nid=req.nid, to_nid=req.toNid)
code = models.search.add_recent_cursor_search(uid=td.uid, nid=req.nid, to_nid=req.toNid)
return schemas.base.AcknowledgeResponse(
code=code.value,
message=const.get_msg_by_code(code, td.language),
requestId=req.requestId,
)


def get_recent_search_queries(
def get_recent(
td: TokenDecode,
rid: str,
) -> schemas.search.RecentSearchQueriesResponse:
) -> schemas.search.GetRecentSearchResponse:
if td.code != const.Code.OK:
return schemas.search.RecentSearchQueriesResponse(
return schemas.search.GetRecentSearchResponse(
code=td.code.value,
message=const.get_msg_by_code(td.code, td.language),
requestId=rid,
queries=[],
)
queries = models.search.get_recent_search_queries(uid=td.uid)
nodes = models.search.get_recent_search(uid=td.uid)
code = const.Code.OK
return schemas.search.RecentSearchQueriesResponse(
return schemas.search.GetRecentSearchResponse(
code=code.value,
message=const.get_msg_by_code(code, td.language),
requestId=rid,
queries=queries,
nodes=[schemas.node.NodesInfoResponse.Data.NodeInfo(
id=n["id"],
title=n["title"],
snippet=n["snippet"],
type=n["type"],
createdAt=datetime2str(n["_id"].generation_time),
modifiedAt=datetime2str(n["modifiedAt"]),
) for n in nodes]
)


def put_recent(
td: TokenDecode,
req: schemas.search.PutRecentSearchRequest,
) -> schemas.base.AcknowledgeResponse:
if td.code != const.Code.OK:
return schemas.base.AcknowledgeResponse(
code=td.code.value,
message=const.get_msg_by_code(td.code, td.language),
requestId=req.requestId,
)
code = models.search.put_recent_search(uid=td.uid, nid=req.nid)
return schemas.base.AcknowledgeResponse(
code=code.value,
message=const.get_msg_by_code(code, td.language),
requestId=req.requestId,
)
Loading

0 comments on commit 5d9d77b

Please sign in to comment.