quivr/backend/modules/user/repository/create_user_identity.py
Zineb El Bachiri 375f50356c
refactor: add modules folder (#1633)
# Description

New Modules folder with "user" module:
- controller: contains the current route
- entity: contains the current Models (TO be renamed DTO)
- repository: contains the current repo
- service: methods used by other modules 

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):
2023-11-15 13:17:51 +01:00

25 lines
685 B
Python

from typing import Optional
from uuid import UUID
from models import get_supabase_client
from modules.user.entity.user_identity import UserIdentity
def create_user_identity(id: UUID, openai_api_key: Optional[str]) -> UserIdentity:
supabase_client = get_supabase_client()
response = (
supabase_client.from_("user_identity")
.insert(
{
"user_id": str(id),
"openai_api_key": openai_api_key,
}
)
.execute()
)
user_identity = response.data[0]
return UserIdentity(
id=user_identity.get("user_id"), openai_api_key=user_identity.get("openai_api_key") # type: ignore
)