Skip to content

Commit 7a14e0a

Browse files
committed
Additional refactors
1 parent 6b0c535 commit 7a14e0a

File tree

7 files changed

+20
-7
lines changed

7 files changed

+20
-7
lines changed

runtime/chalicelib/external_api/toast_alimtalk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class MessageOption(pydantic.BaseModel):
6161
statsId: str | None = pydantic.Field(max_length=8, default=None)
6262

6363
@pydantic.field_validator("requestDate", mode="before")
64+
@classmethod
6465
def validate_request_date(cls, v: datetime.datetime | None) -> datetime.datetime | None:
6566
if v and v.date() - datetime.date.today() > datetime.timedelta(days=60):
6667
raise ValueError("The request date should not be more than 60 days in the future.")

runtime/chalicelib/send_manager/__interface__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ class SendRequest(pydantic.BaseModel):
1616
class SendManagerInterface:
1717
service_name: typing.ClassVar[str]
1818
template_manager: typing.ClassVar[template_mgr_interface.TemplateManagerInterface]
19+
send_request_cls: typing.ClassVar[type[SendRequest]]
1920

2021
initialized: typing.ClassVar[bool]
2122

2223
def __init_subclass__(cls) -> None:
2324
type_util.check_classvar_initialized(cls, ["service_name", "template_manager"])
2425

25-
def send(self, request: SendRequest) -> dict[str, str | None]: ...
26+
def send(self, request: SendRequest) -> dict[str, str | None]:
27+
raise NotImplementedError("This method must be implemented in the subclass.")

runtime/chalicelib/send_manager/aws_ses.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class AWSSESSendManager(sendmgr_interface.SendManagerInterface):
1010
template_manager = aws_ses_template_mgr.aws_ses_template_manager
11+
send_request_cls = sendmgr_interface.SendRequest
1112

1213
service_name = "aws_ses"
1314
initialized = True

runtime/chalicelib/send_manager/telegram_botmessaging.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
class TelegramBotMessagingSender(sendmgr_interface.SendManagerInterface):
1414
template_manager = telegram_template_mgr.telegram_template_manager
15+
send_request_cls: sendmgr_interface.SendRequest
1516
client = telegram_client.TelegramBotMessagingClient()
1617

1718
service_name = "telegram_botmessaging"

runtime/chalicelib/send_manager/toast_alimtalk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def _send_request_to_toast_request_payload(req: sendmgr_interface.SendRequest) -
2020

2121
class ToastAlimtalkSendManager(sendmgr_interface.SendManagerInterface):
2222
template_manager = toast_alimtalk_template_mgr.toast_alimtalk_template_manager
23+
send_request_cls: sendmgr_interface.SendRequest
2324
client = toast_alimtalk_client.ToastAlimTalkClient()
2425

2526
service_name = "toast_alimtalk"

runtime/chalicelib/sender/firebase_cloudmessaging.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class FirebaseCloudMessaging(pydantic.BaseModel):
5454
model_config = pydantic.ConfigDict(arbitrary_types_allowed=True)
5555

5656
@pydantic.field_validator("data", mode="before")
57+
@classmethod
5758
def validate_data(cls, data: dict) -> dict:
5859
# All keys and values in data must be a string in firebase cloud messaging.
5960
# We'll try to type cast all values to json compatible string.

runtime/chalicelib/template_manager/__interface__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,26 @@ def __init_subclass__(cls, check_classvar_initialized: bool = True) -> None:
4444
type_util.check_classvar_initialized(cls, ["service_name", "template_structure_cls"])
4545

4646
@property
47-
def initialized(self) -> bool: ...
47+
def initialized(self) -> bool:
48+
raise NotImplementedError("This method must be implemented in the subclass.")
4849

4950
def check_template_valid(self, template_data: TemplateType) -> bool:
5051
return bool(self.template_structure_cls.model_validate(template_data))
5152

52-
def list(self) -> list[TemplateInformation]: ...
53+
def list(self) -> list[TemplateInformation]:
54+
raise NotImplementedError("This method must be implemented in the subclass.")
5355

54-
def retrieve(self, template_code: str) -> TemplateInformation | None: ...
56+
def retrieve(self, template_code: str) -> TemplateInformation | None:
57+
raise NotImplementedError("This method must be implemented in the subclass.")
5558

56-
def create(self, template_code: str, template_data: TemplateType) -> TemplateInformation: ...
59+
def create(self, template_code: str, template_data: TemplateType) -> TemplateInformation:
60+
raise NotImplementedError("This method must be implemented in the subclass.")
5761

58-
def update(self, template_code: str, template_data: TemplateType) -> TemplateInformation: ...
62+
def update(self, template_code: str, template_data: TemplateType) -> TemplateInformation:
63+
raise NotImplementedError("This method must be implemented in the subclass.")
5964

60-
def delete(self, template_code: str) -> None: ...
65+
def delete(self, template_code: str) -> None:
66+
raise NotImplementedError("This method must be implemented in the subclass.")
6167

6268
def render(
6369
self,

0 commit comments

Comments
 (0)