Ejemplo n.º 1
0
    async def update_profile(self, *, profile_update: ProfileUpdate, requesting_user: UserInDB) -> ProfileInDB:
        profile = await self.get_profile_by_user_id(user_id=requesting_user.id)
        update_params = profile.copy(update=profile_update.dict(exclude_unset=True))

        updated_profile = await self.db.fetch_one(query=UPDATE_PROFILE_QUERY,
                                                  values=update_params.dict(exclude={"id", "created_at", "updated_at", "username", "email"}),)
        return ProfileInDB(**updated_profile)
Ejemplo n.º 2
0
    async def get_profile_by_user_id(self, *, user_id: int) -> ProfileInDB:
        profile_record = await self.db.fetch_one(query=GET_PROFILE_BY_USER_ID_QUERY, values={"user_id": user_id})

        if not profile_record:
            return None

        return ProfileInDB(**profile_record)
Ejemplo n.º 3
0
    async def get_profile_by_username(self, *, username: str) -> ProfileInDB:
        profile_record = await self.db.fetch_one(
            query=GET_PROFILE_BY_USERNAME_QUERY, values={'username': username})

        if not profile_record:
            return None

        return ProfileInDB(**profile_record)
Ejemplo n.º 4
0
 async def get_profile_by_username(self, *, username: str) -> ProfileInDB:
     """
     Select the username and email from the users table,
     while selecting all fields from the profiles table.
     """
     profile_record = await self.db.fetch_one(
         query=GET_PROFILE_BY_USERNAME_QUERY, values={"username": username})
     if profile_record:
         return ProfileInDB(**profile_record)