Skip to content
Merged
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
17 changes: 17 additions & 0 deletions modal_backend/routes/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,20 @@ async def delete_group(id: int, user=Depends(UnionAuth(scopes=["modal.group.dele
Исключение **ObjectNotFound**, если `id` не найден
"""
return await GroupService.delete_group(db, id)


@group.patch("/{id}", response_model=GroupGet)
async def update_group(
id: int, group_info: GroupPost, user=Depends(UnionAuth(scopes=["modal.group.update"]))
) -> GroupGet:
"""
Обновляет данные о группе

Scopes: `["modal.group.update"]`

Исключение **ObjectNotFound**, если `id` не найден

Исключение **AlreadyExists**, если изменений нет
"""
updated_group = await GroupService.update_group(db, id, group_info)
return GroupGet.model_validate(updated_group)
8 changes: 7 additions & 1 deletion modal_backend/utils/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from modal_backend.exceptions import AlreadyExists, ObjectNotFound
from modal_backend.models.db import Group, ModalStatus, Note, NoteType, Service
from modal_backend.schemas.base import StatusResponseModel
from modal_backend.schemas.models import NoteTypePost, NotificationPost
from modal_backend.schemas.models import GroupPost, NoteTypePost, NotificationPost


class NoteService:
Expand Down Expand Up @@ -99,3 +99,9 @@ async def delete_group(cls, db: Session, id: int):
return StatusResponseModel(
status="Success", message="Group has been successfully deleted", ru="Группа успешно удалена"
)

@classmethod
async def update_group(cls, db: Session, id: int, group_info: GroupPost):
Group.get(session=db.session, id=id)
updated_group = Group.update(id, session=db.session, **group_info.model_dump())
return updated_group
Loading