Skip to content

Commit

Permalink
Deprication (#83)
Browse files Browse the repository at this point in the history
* Old routers depricate

* Test fixes

* Style
  • Loading branch information
dyakovri authored Mar 13, 2023
1 parent 7244dc4 commit 1993f62
Show file tree
Hide file tree
Showing 53 changed files with 382 additions and 281 deletions.
1 change: 1 addition & 0 deletions calendar_backend/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from calendar_backend.routes import app


logging.basicConfig(
filename=f'logger_{__name__}.log',
level=logging.DEBUG,
Expand Down
3 changes: 2 additions & 1 deletion calendar_backend/google_engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .service import get_calendar_service_from_token
from .api_utils import create_calendar_with_timetable
from .service import get_calendar_service_from_token


__all__ = [
"get_calendar_service_from_token",
Expand Down
2 changes: 2 additions & 0 deletions calendar_backend/google_engine/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from sqlalchemy.orm import Session

from calendar_backend.settings import get_settings

from .event import Event
from .event_from_db import create_google_events_from_db


settings = get_settings()
logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion calendar_backend/google_engine/event.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from calendar_backend.methods import utils
from pydantic import BaseModel

from calendar_backend.methods import utils


class Event(BaseModel):
summary: str
Expand Down
4 changes: 3 additions & 1 deletion calendar_backend/google_engine/event_from_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

from sqlalchemy.orm import Session

from calendar_backend.settings import get_settings
from calendar_backend.methods.utils import get_lessons_by_group_from_date
from calendar_backend.models import Event, Group
from calendar_backend.settings import get_settings

from .event import create_google_calendar_event


settings = get_settings()
logger = logging.getLogger(__name__)

Expand Down
7 changes: 4 additions & 3 deletions calendar_backend/google_engine/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import google.oauth2.credentials
import googleapiclient.discovery
from sqlalchemy.exc import NoResultFound
from fastapi_sqlalchemy import db
from googleapiclient.discovery import build
from pydantic import Json
from sqlalchemy.exc import NoResultFound

from calendar_backend.models import Credentials
from calendar_backend.settings import get_settings
from fastapi_sqlalchemy import db
from pydantic import Json


settings = get_settings()
Expand Down
4 changes: 2 additions & 2 deletions calendar_backend/methods/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import utils
from . import auth
from . import auth, utils


__all__ = [
"utils",
Expand Down
3 changes: 3 additions & 0 deletions calendar_backend/methods/auth.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import logging

from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
from pydantic import BaseModel

from calendar_backend.settings import get_settings


logger = logging.getLogger(__name__)
settings = get_settings()
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
Expand Down
9 changes: 6 additions & 3 deletions calendar_backend/methods/list_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import time
from datetime import date as date_
from datetime import datetime
from fastapi import HTTPException
from fastapi.responses import FileResponse

import pytz
from fastapi import HTTPException
from fastapi.responses import FileResponse
from icalendar import Calendar, Event, vText
from sqlalchemy.orm import Session

from calendar_backend.models import Group
from calendar_backend.settings import get_settings

from . import utils
from calendar_backend.models import Group


settings = get_settings()
logger = logging.getLogger(__name__)
Expand Down
17 changes: 6 additions & 11 deletions calendar_backend/methods/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,16 @@
import string
from concurrent.futures import ThreadPoolExecutor
from functools import partial
from io import BytesIO
from typing import Final

import aiofiles
from fastapi import File, UploadFile, HTTPException
from fastapi import File, HTTPException, UploadFile
from PIL import Image
from sqlalchemy.orm import Session

from calendar_backend.models.db import (
Event,
Group,
Lecturer,
Photo,
Room,
ApproveStatuses,
)
from calendar_backend.models.db import ApproveStatuses, Event, Group, Lecturer, Photo, Room
from calendar_backend.settings import get_settings
from PIL import Image
from io import BytesIO


settings = get_settings()
Expand Down Expand Up @@ -75,8 +68,10 @@ async def get_lecturer_lessons_in_daterange(
events_list.append(lesson)
return events_list


SUPPORTED_FILE_EXTENSIONS: Final[list[str]] = ['png', 'svg', 'jpg', 'jpeg']


async def upload_lecturer_photo(lecturer_id: int, session: Session, file: UploadFile = File(...)) -> Photo:
lecturer = Lecturer.get(lecturer_id, session=session)
random_string = ''.join(random.choice(string.ascii_letters) for _ in range(32))
Expand Down
15 changes: 8 additions & 7 deletions calendar_backend/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from .db import (
Credentials,
Group,
Lecturer,
Event,
Room,
Direction,
ApproveStatuses,
CommentEvent,
CommentLecturer,
Credentials,
Direction,
Event,
EventsLecturers,
EventsRooms,
ApproveStatuses,
Group,
Lecturer,
Room,
)


__all__ = [
"Credentials",
"Group",
Expand Down
4 changes: 2 additions & 2 deletions calendar_backend/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import re
from enum import Enum

from sqlalchemy import Column, Integer, not_
from sqlalchemy import Integer, not_
from sqlalchemy.exc import NoResultFound
from sqlalchemy.ext.declarative import as_declarative, declared_attr
from sqlalchemy.orm import Query, Session, Mapped, mapped_column
from sqlalchemy.orm import Mapped, Query, Session, mapped_column

from calendar_backend.exceptions import ObjectNotFound

Expand Down
7 changes: 4 additions & 3 deletions calendar_backend/models/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from datetime import datetime
from enum import Enum

from sqlalchemy import and_, or_, Integer, String, Boolean, JSON, DateTime, Text, ForeignKey, true
from sqlalchemy import JSON, Boolean, DateTime
from sqlalchemy import Enum as DbEnum
from sqlalchemy import ForeignKey, Integer, String, Text, and_, or_, true
from sqlalchemy.ext.hybrid import hybrid_method, hybrid_property
from sqlalchemy.orm import relationship, Mapped, mapped_column
from sqlalchemy.orm import Mapped, mapped_column, relationship

from .base import BaseDbModel, ApproveStatuses
from .base import ApproveStatuses, BaseDbModel


class Credentials(BaseDbModel):
Expand Down
1 change: 1 addition & 0 deletions calendar_backend/routes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .base import app


__all__ = ["app"]
10 changes: 7 additions & 3 deletions calendar_backend/routes/auth.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"""DEPRICATED TODO: Drop 2023-04-01
"""
import logging

from fastapi import APIRouter, HTTPException, Depends
from fastapi import APIRouter, Depends, HTTPException
from fastapi.security import OAuth2PasswordRequestForm

from calendar_backend.settings import get_settings
from calendar_backend.methods import auth
from calendar_backend.settings import get_settings


auth_router = APIRouter(prefix="", tags=["Utils: Auth"])
settings = get_settings()
logger = logging.getLogger(__name__)
# DEPRICATED TODO: Drop 2023-04-01
auth_router = APIRouter(prefix="", tags=["Utils: Auth"], deprecated=True)


@auth_router.post("/token")
Expand Down
65 changes: 47 additions & 18 deletions calendar_backend/routes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,57 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from fastapi_sqlalchemy import DBSessionMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi_sqlalchemy import DBSessionMiddleware
from starlette import status
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
from starlette.requests import Request
from starlette.responses import Response
from starlette.types import ASGIApp

from calendar_backend import __version__
from calendar_backend.exceptions import ObjectNotFound, ForbiddenAction, NotEnoughCriteria
from calendar_backend.exceptions import ForbiddenAction, NotEnoughCriteria, ObjectNotFound
from calendar_backend.settings import get_settings

from .auth import auth_router
from .auth import auth_router # TODO: Replace with PKFF Auth
from .event import event_comment_review_router as old_event_comment_review_router # DEPRICATED TODO: Drop 2023-04-01
from .event import event_comment_router as old_event_comment_router # DEPRICATED TODO: Drop 2023-04-01
from .event import event_router as old_event_router # DEPRICATED TODO: Drop 2023-04-01
from .event.comment import router as event_comment_router
from .event.comment_review import router as event_comment_review_router
from .event.event import router as event_router
from .gcal import gcal
from .group import group_router as old_group_router # DEPRICATED TODO: Drop 2023-04-01
from .group.group import router as group_router
from .lecturer import (
lecturer_router,
lecturer_comment_router,
lecturer_comment_review_router,
lecturer_photo_review_router,
lecturer_photo_router,
)
from .group import group_router
from .room import room_router
from .event import event_router, event_comment_router, event_comment_review_router
lecturer_comment_review_router as old_lecturer_comment_review_router,
) # DEPRICATED TODO: Drop 2023-04-01
from .lecturer import lecturer_comment_router as old_lecturer_comment_router # DEPRICATED TODO: Drop 2023-04-01
from .lecturer import (
lecturer_photo_review_router as old_lecturer_photo_review_router,
) # DEPRICATED TODO: Drop 2023-04-01
from .lecturer import lecturer_photo_router as old_lecturer_photo_router # DEPRICATED TODO: Drop 2023-04-01
from .lecturer import lecturer_router as old_lecturer_router # DEPRICATED TODO: Drop 2023-04-01
from .lecturer.comment import router as lecturer_comment_router
from .lecturer.comment_review import router as lecturer_comment_review_router
from .lecturer.lecturer import router as lecturer_router
from .lecturer.photo import router as lecturer_photo_router
from .lecturer.photo_review import router as lecturer_photo_review_router
from .room import room_router as old_room_router # DEPRICATED TODO: Drop 2023-04-01
from .room.room import router as room_router


settings = get_settings()
logger = logging.getLogger(__name__)
app = FastAPI(
title='Сервис мониторинга активности',
description=dedent("""
title='Сервис расписания',
description=dedent(
"""
API для работы с календарем физфака.
Пример работы на питоне(Создание Room):
```python
import reqests, json
url=f"https://timetable.api.test.profcomff.com"
url=f"https://api.test.profcomff.com/timetable"
# Авторизация
beaver = requests.post(f"{url}/token", {"username": "...", "password": "..."})
Expand All @@ -50,14 +65,14 @@
# Создание
create_room = requests.post(
f"{url}/timetable/room",
f"{url}/room",
json={"name": "test", "direction": "South"},
headers={"Authorization": f"Bearer {auth_data.get('access_token')}"}
)
```
"""),
"""
),
version=__version__,

# Настраиваем интернет документацию
root_path=settings.ROOT_PATH if __version__ != 'dev' else '/',
docs_url=None if __version__ != 'dev' else '/docs',
Expand Down Expand Up @@ -123,8 +138,22 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -

app.mount('/static', StaticFiles(directory=settings.STATIC_PATH), 'static')

# region DEPRICATED
# TODO: Drop 2023-04-01
app.include_router(gcal)
app.include_router(auth_router)
app.include_router(old_lecturer_router)
app.include_router(old_lecturer_comment_router)
app.include_router(old_lecturer_comment_review_router)
app.include_router(old_lecturer_photo_router)
app.include_router(old_lecturer_photo_review_router)
app.include_router(old_group_router)
app.include_router(old_room_router)
app.include_router(old_event_router)
app.include_router(old_event_comment_router)
app.include_router(old_event_comment_review_router)
# endregion

app.include_router(lecturer_router)
app.include_router(lecturer_comment_router)
app.include_router(lecturer_comment_review_router)
Expand Down
5 changes: 3 additions & 2 deletions calendar_backend/routes/event/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .event import event_router
from .comment_review import event_comment_review_router
from .comment import event_comment_router
from .comment_review import event_comment_review_router
from .event import event_router


__all__ = ["event_router", "event_comment_review_router", "event_comment_router"]
Loading

0 comments on commit 1993f62

Please sign in to comment.