feat(chalice): notes pagination
feat(chalice): notes sort
This commit is contained in:
parent
c3913e6dca
commit
224541a0c2
5 changed files with 23 additions and 10 deletions
|
|
@ -28,7 +28,7 @@ def get_session_notes(tenant_id, project_id, session_id, user_id):
|
|||
return rows
|
||||
|
||||
|
||||
def get_all_notes(tenant_id, project_id, user_id):
|
||||
def get_all_notes_by_project_id(tenant_id, project_id, user_id, data: schemas.SearchNoteSchema):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
query = cur.mogrify(f"""SELECT sessions_notes.*
|
||||
FROM sessions_notes
|
||||
|
|
@ -37,7 +37,8 @@ def get_all_notes(tenant_id, project_id, user_id):
|
|||
AND sessions_notes.deleted_at IS NULL
|
||||
AND (sessions_notes.user_id = %(user_id)s
|
||||
OR sessions_notes.is_public)
|
||||
ORDER BY created_at DESC;""",
|
||||
ORDER BY created_at {data.order}
|
||||
LIMIT {data.limit} OFFSET {data.limit * (data.page - 1)};""",
|
||||
{"project_id": project_id, "user_id": user_id, "tenant_id": tenant_id})
|
||||
|
||||
cur.execute(query=query)
|
||||
|
|
|
|||
|
|
@ -419,9 +419,10 @@ def delete_note(projectId: int, noteId: int, context: schemas.CurrentContext = D
|
|||
return data
|
||||
|
||||
|
||||
@app.get('/{projectId}/notes', tags=["sessions", "notes"])
|
||||
def get_all_notes(projectId: int, context: schemas.CurrentContext = Depends(OR_context)):
|
||||
data = sessions_notes.get_all_notes(tenant_id=context.tenant_id, project_id=projectId, user_id=context.user_id)
|
||||
@app.post('/{projectId}/notes', tags=["sessions", "notes"])
|
||||
def get_all_notes(projectId: int, data: schemas.SearchNoteSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
data = sessions_notes.get_all_notes_by_project_id(tenant_id=context.tenant_id, project_id=projectId, user_id=context.user_id,data=data)
|
||||
if "errors" in data:
|
||||
return data
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1086,6 +1086,14 @@ class IntegrationType(str, Enum):
|
|||
newrelic = "NEWRELIC"
|
||||
|
||||
|
||||
class SearchNoteSchema(_PaginatedSchema):
|
||||
sort: str = Field(default="createdAt")
|
||||
order: SortOrderType = Field(default=SortOrderType.desc)
|
||||
|
||||
class Config:
|
||||
alias_generator = attribute_to_camel_case
|
||||
|
||||
|
||||
class SessionNoteSchema(BaseModel):
|
||||
message: str = Field(..., min_length=2)
|
||||
tags: List[str] = Field(default=[])
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ def get_session_notes(tenant_id, project_id, session_id, user_id):
|
|||
return rows
|
||||
|
||||
|
||||
def get_all_notes(tenant_id, project_id, user_id):
|
||||
def get_all_notes_by_project_id(tenant_id, project_id, user_id, data: schemas.SearchNoteSchema):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
query = cur.mogrify(f"""SELECT sessions_notes.*
|
||||
FROM sessions_notes
|
||||
|
|
@ -37,7 +37,8 @@ def get_all_notes(tenant_id, project_id, user_id):
|
|||
AND sessions_notes.deleted_at IS NULL
|
||||
AND (sessions_notes.user_id = %(user_id)s
|
||||
OR sessions_notes.is_public AND users.tenant_id = %(tenant_id)s)
|
||||
ORDER BY created_at DESC;""",
|
||||
ORDER BY created_at {data.order}
|
||||
LIMIT {data.limit} OFFSET {data.limit * (data.page - 1)};""",
|
||||
{"project_id": project_id, "user_id": user_id, "tenant_id": tenant_id})
|
||||
|
||||
cur.execute(query=query)
|
||||
|
|
|
|||
|
|
@ -446,9 +446,11 @@ def delete_note(projectId: int, noteId: int, context: schemas.CurrentContext = D
|
|||
return data
|
||||
|
||||
|
||||
@app.get('/{projectId}/notes', tags=["sessions", "notes"], dependencies=[OR_scope(Permissions.session_replay)])
|
||||
def get_all_notes(projectId: int, context: schemas.CurrentContext = Depends(OR_context)):
|
||||
data = sessions_notes.get_all_notes(tenant_id=context.tenant_id, project_id=projectId, user_id=context.user_id)
|
||||
@app.post('/{projectId}/notes', tags=["sessions", "notes"], dependencies=[OR_scope(Permissions.session_replay)])
|
||||
def get_all_notes(projectId: int, data: schemas.SearchNoteSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
data = sessions_notes.get_all_notes_by_project_id(tenant_id=context.tenant_id, project_id=projectId,
|
||||
user_id=context.user_id)
|
||||
if "errors" in data:
|
||||
return data
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue