-
Notifications
You must be signed in to change notification settings - Fork 907
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #445 from julep-ai/f/new-routes
feat: new routes for docs, users, search
- Loading branch information
Showing
85 changed files
with
1,000 additions
and
1,631 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
""" | ||
This module contains the implementation of the delete_user_query function, which is responsible for deleting an user and its related default settings from the CozoDB database. | ||
""" | ||
|
||
from uuid import UUID | ||
|
||
from beartype import beartype | ||
from fastapi import HTTPException | ||
from pycozo.client import QueryException | ||
from pydantic import ValidationError | ||
|
||
from ...autogen.openapi_model import ResourceDeletedResponse | ||
from ...common.utils.datetime import utcnow | ||
from ..utils import ( | ||
cozo_query, | ||
partialclass, | ||
rewrap_exceptions, | ||
verify_developer_id_query, | ||
verify_developer_owns_resource_query, | ||
wrap_in_class, | ||
) | ||
|
||
|
||
@rewrap_exceptions( | ||
{ | ||
QueryException: partialclass(HTTPException, status_code=400), | ||
ValidationError: partialclass(HTTPException, status_code=400), | ||
TypeError: partialclass(HTTPException, status_code=400), | ||
} | ||
) | ||
@wrap_in_class( | ||
ResourceDeletedResponse, | ||
one=True, | ||
transform=lambda d: { | ||
"id": UUID(d.pop("user_id")), | ||
"deleted_at": utcnow(), | ||
"jobs": [], | ||
}, | ||
) | ||
@cozo_query | ||
@beartype | ||
def delete_user(*, developer_id: UUID, user_id: UUID) -> tuple[list[str], dict]: | ||
""" | ||
Constructs and returns a datalog query for deleting an user and its default settings from the database. | ||
Parameters: | ||
- developer_id (UUID): The UUID of the developer owning the user. | ||
- user_id (UUID): The UUID of the user to be deleted. | ||
- client (CozoClient, optional): An instance of the CozoClient to execute the query. | ||
Returns: | ||
- ResourceDeletedResponse: The response indicating the deletion of the user. | ||
""" | ||
|
||
queries = [ | ||
verify_developer_id_query(developer_id), | ||
verify_developer_owns_resource_query(developer_id, "users", user_id=user_id), | ||
""" | ||
# Delete docs | ||
?[user_id, doc_id] := | ||
*user_docs{ | ||
user_id, | ||
doc_id, | ||
}, user_id = to_uuid($user_id) | ||
:delete user_docs { | ||
user_id, | ||
doc_id | ||
} | ||
:returning | ||
""", | ||
""" | ||
# Delete tools | ||
?[user_id, tool_id] := | ||
*tools{ | ||
user_id, | ||
tool_id, | ||
}, user_id = to_uuid($user_id) | ||
:delete tools { | ||
user_id, | ||
tool_id | ||
} | ||
:returning | ||
""", | ||
""" | ||
# Delete default user settings | ||
?[user_id] <- [[$user_id]] | ||
:delete user_default_settings { | ||
user_id | ||
} | ||
:returning | ||
""", | ||
""" | ||
# Delete the user | ||
?[user_id, developer_id] <- [[$user_id, $developer_id]] | ||
:delete users { | ||
developer_id, | ||
user_id | ||
} | ||
:returning | ||
""", | ||
] | ||
|
||
return (queries, {"user_id": str(user_id), "developer_id": str(developer_id)}) |
Oops, something went wrong.