feat(users): add get user by id endpoint

This commit is contained in:
qzl
2026-03-11 20:57:49 +08:00
parent c76f2d1301
commit d3545b5c28
2 changed files with 27 additions and 0 deletions
+17
View File
@@ -20,6 +20,7 @@ if TYPE_CHECKING:
from sqlalchemy.ext.asyncio import AsyncSession
from v1.auth.schemas import UserByEmailResponse
from v1.friendships.schemas import UserBasicInfo
logger = get_logger("v1.users.service")
@@ -99,6 +100,22 @@ class UserService(BaseService):
bio=user.bio,
)
async def get_user_by_id(self, user_id: UUID) -> "UserBasicInfo":
from v1.friendships.schemas import UserBasicInfo
try:
profile = await self._repository.get_by_user_id(user_id)
except SQLAlchemyError:
raise HTTPException(status_code=503, detail="User store unavailable")
if profile is None:
raise HTTPException(status_code=404, detail="User not found")
return UserBasicInfo(
id=str(profile.id),
username=profile.username,
avatar_url=profile.avatar_url,
)
async def update_me(self, update: UserUpdateRequest) -> UserResponse:
user_id = self.require_user_id()
update_data: dict[str, str | None] = {