Coverage for app/core/base/base_output_dto.py: 100%
3 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-15 01:44 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-15 01:44 +0000
1from abc import ABCMeta
3from sqlmodel import SQLModel
6class BaseOutputDTO(SQLModel, metaclass=ABCMeta):
7 """UseCaseのBaseOutputDTOベース."""
9# class BaseStreamOutputDTO(SQLModel, metaclass=ABCMeta):
10# """UseCaseのBaseStreamOutputDTOベース."""
12# event: str
13# data: dict[str, Any] | str
15# model_config = SQLModelConfig(
16# populate_by_name=True,
17# alias_generator=to_camel,
18# )
20# def to_sse(self) -> str:
21# """
22# eventとdataをSSEデータ形式に変換する関数。.
24# Returns:
25# str: SSEフォーマットの文字列。.
27# """
28# try:
29# # JSONデータを文字列に変換
30# json_string = json.dumps(self.data, ensure_ascii=False)
31# except (TypeError, ValueError) as e:
32# msg = "Invalid JSON data"
33# raise ValueError(msg) from e
34# else:
35# # SSEフォーマットに変換
36# return f"event: {self.event}\ndata: {json_string}\n\n"