From 1f68db20fc720da310e507fe51c650991eea372c Mon Sep 17 00:00:00 2001 From: LoRiot Date: Mon, 17 Oct 2022 14:17:49 +0300 Subject: [PATCH] Insert data into all project columns --- handlers/projects.py | 18 ++++++++++-------- services/repositories.py | 11 +++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/handlers/projects.py b/handlers/projects.py index 73577fe..61fa7a9 100644 --- a/handlers/projects.py +++ b/handlers/projects.py @@ -31,14 +31,13 @@ async def create_project(message: types.Message, state: FSMContext): ) -async def get_project_fields(message: types.Message, repo: Repos, state: FSMContext): - # TODO: для тегов и категорий вытаскивать из таблиц индексы, - # значением для creator должен быть user_id. +async def get_project_fields( + message: types.Message, repo: Repos, state: FSMContext +): field_patterns = { - "Название проекта": str, - "Описание": str, - "Кол-во участников": int, - "Статус": BitString, + "Название проекта": str, "Описание": str, "Контакты": str, + "Кол-во участников": int, "Статус": BitString, "Теги": str, + "Категория": str } field_values = [] @@ -51,8 +50,11 @@ async def get_project_fields(message: types.Message, repo: Repos, state: FSMCont pass logger.debug(field_values) + + await repo.get_repo(ProjectRepo).add( + *field_values, user_id=message.from_user.id + ) await state.reset_state() - await repo.get_repo(ProjectRepo).add(*field_values) def register_projects_handlers(dp: Dispatcher): diff --git a/services/repositories.py b/services/repositories.py index edf4628..6a09d3c 100644 --- a/services/repositories.py +++ b/services/repositories.py @@ -32,14 +32,13 @@ class UserRepo(BaseRepo): class ProjectRepo(BaseRepo): - async def add(self, name: str, description: str, *args): + async def add(self, *args, user_id: int): await self.conn.execute( "INSERT INTO projects " - "(name, description, contributors, status) " - "VALUES ($1, $2, $3, $4)", - name, - description, - *args + "(creator, name, description, contacts, " + "contributors, status, tag, category) " + "VALUES ($1, $2, $3, $4, $5, $6, $7, $8)", + user_id, *args ) async def get(self, user_id: int):