Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
fix: add details for fields
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Dec 26, 2024
1 parent 72a1156 commit 97a8e84
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 34 deletions.
44 changes: 36 additions & 8 deletions schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
"PlateInfoModel": {
"properties": {
"plate": {
"title": "Plate",
"description": "Bi\u1ec3n s\u1ed1",
"examples": [
"60A64685",
"98-A-56604",
"30-F88251",
"59XB-00000"
],
"title": "Bi\u1ec3n s\u1ed1",
"type": "string"
},
"owner": {
Expand All @@ -28,7 +35,12 @@
}
],
"default": null,
"title": "Owner"
"description": "Ghi ch\u00fa ch\u1ee7 s\u1edf h\u1eefu (ph\u00f9 h\u1ee3p khi d\u00f9ng notify ai \u0111\u00f3)",
"examples": [
"@kevinnitro",
"dad"
],
"title": "Ghi ch\u00fa ch\u1ee7 s\u1edf h\u1eefu"
}
},
"required": [
Expand All @@ -40,10 +52,18 @@
"TelegramConfigModel": {
"properties": {
"bot_token": {
"description": "Bot token Telegram",
"examples": [
"2780473231:weiruAShGUUx4oLOMoUhd0GiREXSZcCq-uB"
],
"title": "Bot Token",
"type": "string"
},
"chat_id": {
"description": "Chat ID Telegram",
"examples": [
"-1001790012349"
],
"title": "Chat Id",
"type": "string"
}
Expand All @@ -59,6 +79,7 @@
"properties": {
"enabled": {
"default": true,
"description": "K\u00edch ho\u1ea1t",
"title": "Enabled",
"type": "boolean"
},
Expand All @@ -75,34 +96,41 @@
},
"properties": {
"data": {
"default": [],
"description": "Danh s\u00e1ch c\u00e1c bi\u1ec3n xe",
"items": {
"$ref": "#/$defs/PlateInfoModel"
},
"title": "Data",
"type": "array"
},
"notify": {
"default": [],
"description": "Danh s\u00e1ch c\u00e1c thi\u1ebft l\u1eadp \u0111\u1ec3 th\u00f4ng b\u00e1o",
"items": {
"$ref": "#/$defs/TelegramNotifyModel"
},
"title": "Notify",
"type": "array"
},
"havent_paid_only": {
"unpaid_only": {
"default": true,
"title": "Havent Paid Only",
"description": "Ch\u1ec9 hi\u1ec3n th\u1ecb th\u00f4ng tin vi ph\u1ea1m ch\u01b0a n\u1ed9p ph\u1ea1t",
"title": "Unpaid Only",
"type": "boolean"
},
"detail_log": {
"verbose": {
"default": false,
"description": "Hi\u1ec3n th\u1ecb t\u1ea5t c\u1ea3 th\u00f4ng tin c\u00f3 th\u1ec3 hi\u1ec3n th\u1ecb",
"title": "Verbose",
"type": "boolean"
},
"detail_log": {
"default": true,
"title": "Detail Log",
"type": "boolean"
},
"log_level": {
"$ref": "#/$defs/LogLevelModel",
"default": "WARNING"
"default": "INFO"
}
},
"title": "ConfigModel",
Expand Down
21 changes: 15 additions & 6 deletions src/check_phat_nguoi/models/config/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, Field

from check_phat_nguoi.models.log_level import LogLevelModel
from check_phat_nguoi.models.notify.telegram_notify import TelegramNotifyModel
Expand All @@ -8,11 +8,20 @@
class ConfigModel(BaseModel):
model_config = ConfigDict(use_enum_values=True, validate_default=True)

data: list[PlateInfoModel] = []
notify: list[TelegramNotifyModel] = []
havent_paid_only: bool = True
detail_log: bool = False
log_level: LogLevelModel = LogLevelModel.warning
data: list[PlateInfoModel] = Field(
description="Danh sách các biển xe", default_factory=list
)
notify: list[TelegramNotifyModel] = Field(
description="Danh sách các thiết lập để thông báo", default_factory=list
)
unpaid_only: bool = Field(
description="Chỉ hiển thị thông tin vi phạm chưa nộp phạt", default=True
)
verbose: bool = Field(
description="Hiển thị tất cả thông tin có thể hiển thị", default=False
)
detail_log: bool = True
log_level: LogLevelModel = LogLevelModel.info


__all__ = ["ConfigModel"]
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from pydantic import BaseModel
from pydantic import BaseModel, Field

from check_phat_nguoi.models.context.plate_context.plate_info import (
PlateInfoContextModel,
)


class PlatesContextModel(BaseModel):
plates: list[PlateInfoContextModel] = []
plates: list[PlateInfoContextModel] = Field(
description="Danh sách các biển xe", default_factory=list
)


__all__ = ["PlatesContextModel"]
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from pydantic import Field

from check_phat_nguoi.models.context.plate_context.violation import (
ViolationContextModel,
)
from check_phat_nguoi.models.plate_info import PlateInfoModel


class PlateInfoContextModel(PlateInfoModel):
violation: list[ViolationContextModel] = []
violation: list[ViolationContextModel] = Field(
description="Danh sách các vi phạm của 1 biển xe", default_factory=list
)


__all__ = ["PlateInfoContextModel"]
19 changes: 11 additions & 8 deletions src/check_phat_nguoi/models/context/plate_context/violation.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import re
from datetime import datetime
from typing import Dict, Literal

from pydantic import BaseModel, Field, field_validator

import re

from check_phat_nguoi.utils.constants import OFFICE_NAME_PATTERN


class ViolationContextModel(BaseModel):
type: Literal["Ô tô", "Xe máy", "Xe đạp điện"]
date: datetime
location: str
action: str
status: bool
type: Literal["Ô tô", "Xe máy", "Xe đạp điện"] | None = Field(
description="Loại phương tiện giao thông", default=None
)
date: datetime | None = Field(description="Thời điểm vi phạm", default=None)
location: str | None = Field(description="Vị trí vi phạm", default=None)
action: str | None = Field(description="Hành vi vi phạm", default=None)
status: bool | None = Field(
description="Đã nộp phạt (True) / Chưa nộp phạt (False)", default=None
)
enforcement_unit: str | None = Field(
description="Đơn vị phát hiện vi phạm", default=None
)
resolution_office: Dict[str, Dict] = Field(
resolution_office: Dict[str, Dict] | None = Field(
description="Nơi giải quyết vụ việc", default=None
)

Expand Down
4 changes: 2 additions & 2 deletions src/check_phat_nguoi/models/notify/base_notify.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pydantic import BaseModel
from pydantic import BaseModel, Field


class BaseNotifyConfigModel(BaseModel):
enabled: bool = True
enabled: bool = Field(description="Kích hoạt", default=True)


__all__ = ["BaseNotifyConfigModel"]
14 changes: 10 additions & 4 deletions src/check_phat_nguoi/models/notify/telegram.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from re import match as re_match

from pydantic import BaseModel, field_validator
from pydantic import BaseModel, Field, field_validator


class TelegramConfigModel(BaseModel):
bot_token: str
chat_id: str
bot_token: str = Field(
description="Bot token Telegram",
examples=["2780473231:weiruAShGUUx4oLOMoUhd0GiREXSZcCq-uB"],
)
chat_id: str = Field(
description="Chat ID Telegram",
examples=["-1001790012349"],
)

@field_validator("bot_token", mode="after")
@classmethod
Expand All @@ -18,7 +24,7 @@ def validate_bot_token(cls, _bot_token: str) -> str:
@classmethod
def validate_chat_id(cls, _chat_id: str) -> str:
if not re_match(r"^[+-]?[0-9]+$", _chat_id):
raise ValueError("Bot token is not valid")
raise ValueError("Chat ID is not valid")
return _chat_id


Expand Down
15 changes: 12 additions & 3 deletions src/check_phat_nguoi/models/plate_info.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from pydantic import BaseModel
from pydantic import BaseModel, Field


class PlateInfoModel(BaseModel):
plate: str
owner: str | None = None
plate: str = Field(
description="Biển số",
title="Biển số",
examples=["60A64685", "98-A-56604", "30-F88251", "59XB-00000"],
)
owner: str | None = Field(
description="Ghi chú chủ sở hữu (phù hợp khi dùng notify ai đó)",
title="Ghi chú chủ sở hữu",
examples=["@kevinnitro", "dad"],
default=None,
)


__all__ = ["PlateInfoModel"]

0 comments on commit 97a8e84

Please sign in to comment.