-
Notifications
You must be signed in to change notification settings - Fork 0
patch archive handler #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| from datetime import datetime | ||
|
|
||
| from requests import Session | ||
|
|
||
| from modal_backend.exceptions import AlreadyExists, ObjectNotFound | ||
| from modal_backend.models.db import Group, Note, NoteType, Service | ||
| from modal_backend.exceptions import AlreadyExists, ForbiddenAction, 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 GroupPost, NoteTypePost, ServicePost | ||
|
|
||
|
|
@@ -41,6 +43,26 @@ async def get_notes_by_filters( | |
|
|
||
| return notes | ||
|
|
||
| @classmethod | ||
| async def update_status(cls, db: Session, id: int) -> Note: | ||
| note = Note.get(session=db.session, id=id) | ||
| group_ids = note.group_ids | ||
| for group_id in group_ids: | ||
| Group.get(session=db.session, id=group_id) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/profcomff/modal-service-api/blob/main/modal_backend/models/base.py#L60 db.session.query(...).filter(...) см пример реализации https://github.com/profcomff/rental-api/blob/main/rental_backend/routes/item.py#L130 То есть если ты пропишешь сперва Group а потом к нему метод get то будет работать наше кастомное решение с дополнительными автоматическими проверками (см самую первую ссылку в этом комменте) |
||
| service_ids = note.service_ids | ||
| for service_id in service_ids: | ||
| Service.get(session=db.session, id=service_id) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. с сервисом аналогично |
||
| end_ts = note.end_ts | ||
| time = datetime.utcnow() | ||
| if note.is_always == False and time >= end_ts: | ||
| raise ForbiddenAction(Note) | ||
| else: | ||
| if note.status == ModalStatus.ACTIVE: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. такая ситуация: time >= end_ts (то есть вчера модалка завершилась) и note.is_always == False (не бесконечное время) |
||
| updated_note = Note.update(id=id, session=db.session, status=ModalStatus.ARCHIVED) | ||
| else: | ||
| updated_note = Note.update(id=id, session=db.session, status=ModalStatus.ACTIVE) | ||
| return updated_note | ||
|
|
||
|
|
||
| class NoteTypeService: | ||
| """ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
хочется добавить достаточно подробную информацию о том, как работает все.
Но делать это надо только в конце, после того, как исправишь логику работы по моим комментам