Show projects related to the user's chat
This commit is contained in:
parent
d2307dba48
commit
2a85be2f6f
|
@ -4,7 +4,7 @@ from aiogram import types
|
|||
from aiogram.dispatcher import FSMContext
|
||||
|
||||
from states.project import ProjectStates
|
||||
from services.repositories import Repos, ProjectRepo
|
||||
from services.repositories import Repos, ProjectRepo, UserRepo
|
||||
|
||||
|
||||
async def ask_for_project_name(message: types.Message, state: FSMContext):
|
||||
|
@ -16,7 +16,10 @@ async def search_for_projects(
|
|||
message: types.Message, state: FSMContext, repo: Repos
|
||||
):
|
||||
await state.reset_state()
|
||||
projects = await repo.get_repo(ProjectRepo).get(message.text)
|
||||
user = await repo.get_repo(UserRepo).get(message.from_user.id)
|
||||
projects = await repo.get_repo(ProjectRepo).get(
|
||||
message.text, user["chat_id"]
|
||||
)
|
||||
|
||||
for project in projects:
|
||||
await message.answer(
|
||||
|
|
|
@ -27,8 +27,8 @@ class UserRepo(BaseRepo):
|
|||
)
|
||||
|
||||
async def get(self, user_id: int) -> Record:
|
||||
return await self.conn.fetchval(
|
||||
"SELECT user_id FROM users WHERE user_id = $1", user_id
|
||||
return await self.conn.fetchrow(
|
||||
"SELECT user_id, chat_id FROM users WHERE user_id = $1", user_id
|
||||
)
|
||||
|
||||
|
||||
|
@ -42,8 +42,10 @@ class ProjectRepo(BaseRepo):
|
|||
user_id, *args
|
||||
)
|
||||
|
||||
async def get(self, name: str) -> Record:
|
||||
async def get(self, name: str, chat_id: int) -> Record:
|
||||
return await self.conn.fetch(
|
||||
"SELECT id, name, description FROM projects WHERE name LIKE $1",
|
||||
f"%{name}%"
|
||||
"SELECT id, name, description FROM projects "
|
||||
"INNER JOIN users ON projects.creator = users.user_id "
|
||||
"WHERE users.chat_id = $1 AND name LIKE $2",
|
||||
chat_id, f"%{name}%"
|
||||
)
|
||||
|
|
Reference in a new issue