Skip to content

Refactoring send_notification and change_subscription#76

Open
JediMode wants to merge 3 commits intoProCharity:developfrom
JediMode:fix/refactoring-and-change-subscription
Open

Refactoring send_notification and change_subscription#76
JediMode wants to merge 3 commits intoProCharity:developfrom
JediMode:fix/refactoring-and-change-subscription

Conversation

@JediMode
Copy link

Изменил send_notification и change_subscription.

@AntonZelinsky
Copy link
Member

logger.info(f"Messages: Passed invalid <has_mailing> parameter. Passed: {has_mailing}")
return make_response(jsonify(result=f"Неверно указан параметр <has_mailing>. "
f"Сообщение не отправлено."), 400)
notifier = TelegramNotification()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Писал прошлый раз по этому, но давай ещё раз переименуем, в название класса и переменной довай добавим слово сервис.


# TODO refactoring https://github.com/python-telegram-bot/python-telegram-bot/wiki/Avoiding-flood-limits
def send_notification(self, message):
def send_notification(self, mailing_type, message):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Другой порядок, сперва сообщение, потом тип. сообщение важнее чем тип.!

class TelegramNotificationRequest(RequestBase):
message: StrictStr = Field()
mailing_type: MailingType = MailingType.subscribed
mailing_number: MailingNumber = MailingNumber.subscribed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем это?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это по документации если при входе попадет значение не из трех значений 'subscribed', 'unsubscribed', 'all', то выдаст ошибку
https://docs.pydantic.dev/usage/types/#enums-and-choices

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не, я про саму переменную, зачем нам нужна mailing_number? Как её использовать и кому?

return make_response(jsonify(result=f"Неверно указан параметр <has_mailing>. "
f"Сообщение не отправлено."), 400)
notifier = TelegramNotification()
notifier.send_notification(mailing_type=notifications, message=message.message)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А тут что происходит? mailing_type=notifications ты в поле ожидающее получить enum передаёшь объект с различнми полями. Подозреваю, ЭТО НЕ РАБОТАЕТ! Перед отправкой на следующее ревью, тебе нужно прогнать 5 кейсов тестирования различного положения флага и убедиться, что всё работает.
И в месте где проверяешь тип, if mailing_type == MailingType.subscribed.value:, везде добавь else, а в самом конце, если это не одно из трёх значений, бросай исключение! Как раз по этому у тебя и отработало всё без ошибок.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants