diff --git a/app/services/user.py b/app/services/user.py index b0ea12c6..a5ade6a7 100644 --- a/app/services/user.py +++ b/app/services/user.py @@ -1,8 +1,8 @@ from sqlalchemy.orm import Session from app.api.v1.schemas.user import ApiKeyPayload, CreditInfo, DetailData, UserPayload -from app.utils import generate_id from netspresso.netspresso import NetsPresso +from netspresso.utils.db.generate_uuid import generate_uuid from netspresso.utils.db.models.user import User from netspresso.utils.db.repositories.user import user_repository @@ -19,7 +19,7 @@ def create_user(self, db: Session, email: str, password: str, api_key: str): return user def generate_api_key(self, db: Session, email: str, password: str) -> ApiKeyPayload: - generated_id = generate_id(entity="user") + generated_id = generate_uuid(entity="user") user = user_repository.get_by_email(db=db, email=email) @@ -27,9 +27,7 @@ def generate_api_key(self, db: Session, email: str, password: str) -> ApiKeyPayl if user.password != password: user.password = password user.api_key = generated_id - elif user.api_key != generated_id: - user.api_key = generated_id - user = user_repository.save(db=db, model=user) + user = user_repository.save(db=db, model=user) else: user = self.create_user( db=db, diff --git a/app/utils.py b/netspresso/utils/db/generate_uuid.py similarity index 63% rename from app/utils.py rename to netspresso/utils/db/generate_uuid.py index eb04b7de..351da900 100644 --- a/app/utils.py +++ b/netspresso/utils/db/generate_uuid.py @@ -1,6 +1,6 @@ from nanoid import generate -def generate_id(entity: str, size: int = 10) -> str: +def generate_uuid(entity: str, size: int = 10) -> str: nano_id = generate(size=size) return f"{entity}_{nano_id}"