async def make_follower(params: MakeFollower): dbc = DBCommands() await db.set_bind(f'postgresql://{db_user}:{db_pass}@{host}/{db_name}') await dbc.make_follower(params.user_id, params.subject_id)
async def is_teacher(user_id: int): dbc = DBCommands() await db.set_bind(f'postgresql://{db_user}:{db_pass}@{host}/{db_name}') result = await dbc.is_teacher(user_id) return result
async def authorisation(email: str, password: str): dbc = DBCommands() await db.set_bind(f'postgresql://{db_user}:{db_pass}@{host}/{db_name}') result = await dbc.authorisation(email, password) return result
async def get_evaluations_by_teacher(user_id: int): dbc = DBCommands() await db.set_bind(f'postgresql://{db_user}:{db_pass}@{host}/{db_name}') evaluations = await dbc.get_evaluations_by_teacher(user_id) return evaluations
async def get_subject_by_teacher(user_id: int): dbc = DBCommands() await db.set_bind(f'postgresql://{db_user}:{db_pass}@{host}/{db_name}') subject = await dbc.get_subject_by_teacher(user_id) return subject
async def get_user(user_id: int): dbc = DBCommands() await db.set_bind(f'postgresql://{db_user}:{db_pass}@{host}/{db_name}') user = await dbc.get_user(user_id) return user
async def get_lesson_by_id(lesson_id: int): dbc = DBCommands() await db.set_bind(f'postgresql://{db_user}:{db_pass}@{host}/{db_name}') lesson = await dbc.get_lesson_by_id(lesson_id) return lesson
async def update_mark(params: Mark): dbc = DBCommands() await db.set_bind(f'postgresql://{db_user}:{db_pass}@{host}/{db_name}') await dbc.update_mark(params.user_id, params.lesson_id, params.file)
async def update_photo(params: Photo): dbc = DBCommands() await db.set_bind(f'postgresql://{db_user}:{db_pass}@{host}/{db_name}') await dbc.update_photo(params.user_id, params.photo)
async def create_subject(params: Subject): dbc = DBCommands() await db.set_bind(f'postgresql://{db_user}:{db_pass}@{host}/{db_name}') await dbc.create_subject(params.user_id, params.title, params.type_checking)
async def create_lesson(params: Lesson): dbc = DBCommands() await db.set_bind(f'postgresql://{db_user}:{db_pass}@{host}/{db_name}') await dbc.create_lesson(params.user_id, params.title, params.description, params.date, params.check_file)
async def create_user(params: Registration): dbc = DBCommands() await db.set_bind(f'postgresql://{db_user}:{db_pass}@{host}/{db_name}') await dbc.create_user(params.name, params.surname, params.email, params.password, params.birthday, params.is_teacher)
from aiogram import types from aiogram.dispatcher import FSMContext from aiogram.dispatcher.filters import Command from aiogram.types import Message from database.state import NewHW from preload.load_all import dp from database.database import HW, Done, DBCommands from others.keyboards import confirm_menu, func_menu, type_hw_menu db = DBCommands() @dp.message_handler(Command("count_user")) async def count_user(message: Message): if db.is_teacher(): count_users = await db.count_users() text = f'В базе {count_users} пользователей' await message.answer(text) @dp.message_handler(Command("cancel"), state=NewHW) async def cancel(message: Message, state: FSMContext): if db.is_teacher(): await message.answer("Вы отменили добавление ДЗ") await state.reset_state() @dp.message_handler(Command("add_hw")) async def add_item(message: Message): if db.is_teacher(): await message.answer("Введите название ДЗ или нажмите /cancel")
from aiogram.types import (Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery) from database.database import DBCommands from loader import dp d_con = DBCommands() @dp.message_handler(commands=['start']) async def start(message: Message): user = message.from_user user_data = { "uniq_user_id": user.id, "first_name": user.first_name, "last_name": user.last_name, "username": user.username, } profile = await d_con.create_profile(user_data) text = "Добрый день, {name}!\n\n" \ "Я могу помочь вам поработать с нашей системой\n" \ "Чтобы начать работу, напишите: /menu".format(name=profile) await message.answer(text) @dp.message_handler(commands=['menu']) async def start(message: Message): menu = await get_menu() await message.answer(text=menu.get('text'), reply_markup=menu.get('reply_markup'))