Skip to content

Commit

Permalink
feat: 创建文档模型时进行数据校验
Browse files Browse the repository at this point in the history
  • Loading branch information
FHU-yezi committed Feb 25, 2024
1 parent f9dea3a commit 3b43a8b
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jobs/fetch_article_earning_ranking_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async def process_item(
to_author=item.fp_to_author_anount,
to_voter=item.fp_to_voter_amount,
),
)
).validate()


@flow(
Expand Down
2 changes: 1 addition & 1 deletion jobs/fetch_assets_ranking_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def process_item(
slug=item.user_info.slug,
name=item.user_info.name,
),
)
).validate()


@flow(
Expand Down
2 changes: 1 addition & 1 deletion jobs/fetch_daily_update_ranking_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def process_item(
slug=item.user_info.slug,
name=item.user_info.name,
),
)
).validate()


@flow(
Expand Down
2 changes: 1 addition & 1 deletion jobs/fetch_jianshu_lottery_win_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def process_item(item: JianshuLotteryWinRecord, /) -> JianshuLotteryWinRecordDoc
slug=item.user_info.slug,
name=item.user_info.name,
),
)
).validate()


@flow(
Expand Down
2 changes: 1 addition & 1 deletion jobs/fetch_jpep_ftn_trade_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def process_item(
hashed_name=item.publisher_info.hashed_name,
credit=item.publisher_info.credit,
),
)
).validate()


@flow(
Expand Down
3 changes: 3 additions & 0 deletions utils/document_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class Field(Struct, **FIELD_OBJECT_CONFIG):
class Documemt(Struct, **DOCUMENT_OBJECT_CONFIG):
_id: ObjectId

def validate(self) -> Self:
return convert(to_builtins(self), type=self.__class__)

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> Self:
return convert(data, type=cls)
Expand Down

0 comments on commit 3b43a8b

Please sign in to comment.