async def get_timezone(request: Request): area, city = request['validated_args']['area'], request['validated_args'][ 'city'] result = await TimezoneApiClient(timeout=30).get_time(area=area, city=city) if not result: return http_bad_request( f'timezone with area={area} and city={city} not found') return http_ok(GetTimezoneResultSchema().dump(result))
async def ping(request: Request): try: async with request.app.db_engine.acquire() as conn: await conn.execute('SELECT 1;') return http_ok() except Exception: logger.exception('ping db fail') return http_bad_request(msg='База недоступна')
async def update_student_by_id(request: Request, student_id): data = request['validated_json'] async with request.app.db_engine.acquire() as conn: result = await Student.update_by_id(conn=conn, student_id=student_id, values=data) if not result: return http_bad_request('student not found') return http_ok(StudentResultSchema().dump(result))
async def get_all_students(request: Request): async with request.app.db_engine.acquire() as conn: result = await Student.get_all(conn=conn) return http_ok(StudentResultSchema().dump(result, many=True))
async def get_student_by_id(request: Request, student_id): async with request.app.db_engine.acquire() as conn: result = await Student.get_by_id(conn=conn, student_id=student_id) if not result: return http_bad_request('student not found') return http_ok(StudentResultSchema().dump(result))