feat: initialize aivideo project
This commit is contained in:
31
backend/app/modules/users/service.py
Normal file
31
backend/app/modules/users/service.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.common.errors.app_error import ConflictAppError
|
||||
from app.models.entities import User
|
||||
from app.modules.users.repository import UsersRepository
|
||||
|
||||
|
||||
class UsersService:
|
||||
def __init__(self, db: Session) -> None:
|
||||
self.db = db
|
||||
self.repository = UsersRepository(db)
|
||||
|
||||
def update_profile(self, user: User, payload) -> dict:
|
||||
if payload.username and payload.username != user.username:
|
||||
existing = self.repository.get_by_username(payload.username)
|
||||
if existing and existing.id != user.id:
|
||||
raise ConflictAppError("username already exists", code=10011)
|
||||
user.username = payload.username
|
||||
if payload.nickname is not None:
|
||||
user.nickname = payload.nickname
|
||||
if payload.avatar_url is not None:
|
||||
user.avatar_url = payload.avatar_url
|
||||
self.db.commit()
|
||||
return {
|
||||
"publicId": user.public_id,
|
||||
"username": user.username or "",
|
||||
"nickname": user.nickname,
|
||||
"avatarUrl": user.avatar_url,
|
||||
"email": user.email or "",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user