Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions modal_backend/routes/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
NoteStatus,
NoteTextGet,
NoteTextPost,
NotificationGet,
)
from modal_backend.settings import Settings, get_settings
from modal_backend.utils.services import NoteService
Expand Down Expand Up @@ -95,9 +94,7 @@ async def get_note(


@note.post("/info", response_model=NoteInfoGet)
async def create_note_info(
note: NoteInfoPost, user=Depends(UnionAuth(scopes=["modal.note.create"]))
) -> NotificationGet:
async def create_note_info(note: NoteInfoPost, user=Depends(UnionAuth(scopes=["modal.note.create"]))) -> NoteInfoGet:
"""
Создает новую модалку.

Expand All @@ -107,6 +104,7 @@ async def create_note_info(

Права: `["modal.note.create"]`
"""
await NoteService.validate_note(db, note=note)
new_note = Note.create(
session=db.session,
type_id=NoteTypeEnum.INFO,
Expand All @@ -120,7 +118,7 @@ async def create_note_info(
@note.post("/rating", response_model=NoteRatingGet)
async def create_note_rating(
note: NoteRatingPost, user=Depends(UnionAuth(scopes=["modal.note.create"]))
) -> NotificationGet:
) -> NoteRatingGet:
"""
Создает новую модалку.

Expand All @@ -130,6 +128,7 @@ async def create_note_rating(

Права: `["modal.note.create"]`
"""
await NoteService.validate_note(db, note=note)
new_note = Note.create(
session=db.session,
type_id=NoteTypeEnum.RATING,
Expand All @@ -141,9 +140,7 @@ async def create_note_rating(


@note.post("/text", response_model=NoteTextGet)
async def create_note_text(
note: NoteTextPost, user=Depends(UnionAuth(scopes=["modal.note.create"]))
) -> NotificationGet:
async def create_note_text(note: NoteTextPost, user=Depends(UnionAuth(scopes=["modal.note.create"]))) -> NoteTextGet:
"""
Создает новую модалку.

Expand All @@ -153,6 +150,7 @@ async def create_note_text(

Права: `["modal.note.create"]`
"""
await NoteService.validate_note(db, note=note)
new_note = Note.create(
session=db.session,
type_id=NoteTypeEnum.TEXT,
Expand All @@ -166,7 +164,7 @@ async def create_note_text(
@note.post("/choice", response_model=NoteChoiceGet)
async def create_note_choice(
note: NoteChoicePost, user=Depends(UnionAuth(scopes=["modal.note.create"]))
) -> NotificationGet:
) -> NoteChoiceGet:
"""
Создает новую модалку.

Expand All @@ -176,6 +174,7 @@ async def create_note_choice(

Права: `["modal.note.create"]`
"""
await NoteService.validate_note(db, note=note)
new_note = Note.create(
session=db.session,
type_id=NoteTypeEnum.CHOICE,
Expand All @@ -189,7 +188,7 @@ async def create_note_choice(
@note.post("/image", response_model=NoteImageGet)
async def create_note_images(
note: NoteImagePost, user=Depends(UnionAuth(scopes=["modal.note.create"]))
) -> NotificationGet:
) -> NoteImageGet:
"""
Создает новую модалку.

Expand All @@ -199,6 +198,7 @@ async def create_note_images(

Права: `["modal.note.create"]`
"""
await NoteService.validate_note(db, note=note)
new_note = Note.create(
session=db.session,
type_id=NoteTypeEnum.IMAGE,
Expand Down
27 changes: 26 additions & 1 deletion modal_backend/utils/services.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
from datetime import datetime, timezone
from typing import Union

from requests import Session

from modal_backend.exceptions import AlreadyExists, ForbiddenAction, ObjectNotFound
from modal_backend.models.db import Group, ModalStatus, Note, Service
from modal_backend.schemas.base import StatusResponseModel
from modal_backend.schemas.models import GroupPost, ServicePost
from modal_backend.schemas.models import (
GroupPost,
NoteChoicePost,
NoteImagePost,
NoteInfoPost,
NoteRatingPost,
NoteTextPost,
ServicePost,
)


class NoteService:
"""
Сервис для работы с логикой Notifications и базой данных
"""

@classmethod
async def validate_note(
cls, db: Session, note: Union[NoteInfoPost, NoteRatingPost, NoteTextPost, NoteChoicePost, NoteImagePost]
):
"""Валидация полей при создании note"""
if isinstance(note, NoteInfoPost):
pass
elif isinstance(note, NoteRatingPost):
pass
elif isinstance(note, NoteTextPost):
pass
elif isinstance(note, NoteChoicePost):
pass
else: # NoteImagePost there
pass

@classmethod
async def get_notes_by_filters(
cls,
Expand Down
Loading