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

Commit

Permalink
refactor: name convention remove DTO, Model
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Jan 9, 2025
1 parent 76fcba9 commit 6e39112
Show file tree
Hide file tree
Showing 40 changed files with 364 additions and 310 deletions.
2 changes: 1 addition & 1 deletion config.sample.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/KevinNitroG/check-phat-nguoi/refs/heads/main/docs/schemas/config.json",
"$schema": "https://raw.githubusercontent.com/KevinNitroG/check-phat-nguoi/refs/heads/main/schemas/config.json",
"plates": [
{
"plate": "59XA00000",
Expand Down
66 changes: 41 additions & 25 deletions schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"title": "ApiEnum",
"type": "string"
},
"PlateInfoDTO": {
"PlateInfo": {
"properties": {
"plate": {
"description": "Biển số",
Expand Down Expand Up @@ -74,10 +74,10 @@
"plate",
"type"
],
"title": "PlateInfoDTO",
"title": "Thông tin thiết lập cho biển số",
"type": "object"
},
"TelegramNotificationDTO": {
"TelegramNotificationConfig": {
"properties": {
"enabled": {
"default": true,
Expand All @@ -86,17 +86,17 @@
"type": "boolean"
},
"telegram": {
"$ref": "#/$defs/TelegramNotificationEngineDTO",
"description": "Gửi thông báo đến telegram"
"$ref": "#/$defs/TelegramNotificationEngineConfig",
"description": "Telegram"
}
},
"required": [
"telegram"
],
"title": "TelegramNotificationDTO",
"title": "Telegram và kích hoạt",
"type": "object"
},
"TelegramNotificationEngineDTO": {
"TelegramNotificationEngineConfig": {
"properties": {
"botToken": {
"description": "Bot token Telegram",
Expand All @@ -119,7 +119,7 @@
"botToken",
"chatId"
],
"title": "TelegramNotificationEngineDTO",
"title": "Telegram",
"type": "object"
},
"VehicleTypeEnum": {
Expand All @@ -136,18 +136,26 @@
"plates": {
"description": "Danh sách các biển xe",
"items": {
"$ref": "#/$defs/PlateInfoDTO"
"$ref": "#/$defs/PlateInfo"
},
"title": "Plates",
"title": "Danh sách biển xe",
"type": "array"
},
"notifications": {
"anyOf": [
{
"items": {
"$ref": "#/$defs/TelegramNotificationConfig"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"description": "Danh sách các thiết lập để thông báo",
"items": {
"$ref": "#/$defs/TelegramNotificationDTO"
},
"title": "Notifications",
"type": "array"
"title": "Danh sách thông báo"
},
"api": {
"$ref": "#/$defs/ApiEnum",
Expand All @@ -157,29 +165,38 @@
},
"unpaidOnly": {
"default": true,
"description": "Chỉ hiển thị thông tin vi phạm chưa nộp phạt",
"title": "Unpaidonly",
"description": "Chỉ lọc các thông tin vi phạm chưa nộp phạt",
"title": "Lọc chưa nộp phạt",
"type": "boolean"
},
"verbose": {
"default": false,
"description": "Hiển thị tất cả thông tin có thể hiển thị",
"title": "Verbose",
"title": "Hiển thị đầy đủ thông tin",
"type": "boolean"
},
"requestTimeout": {
"default": 10,
"description": "Thời gian (s) để gửi request đến server API và gửi notify message",
"title": "Requesttimeout",
"title": "Thời gian request",
"type": "integer"
},
"requestPerTime": {
"default": 5,
"description": "Số lượng request tối chạy song song",
"exclusiveMinimum": 0,
"title": "Số lượng request",
"type": "integer"
},
"detailLog": {
"default": true,
"title": "Detaillog",
"default": false,
"description": "Log chi tiết",
"title": "Log chi tiết",
"type": "boolean"
},
"logLevel": {
"default": "WARNING",
"description": "Mức độ log",
"enum": [
"NOTSET",
"DEBUG",
Expand All @@ -188,14 +205,13 @@
"ERROR",
"CRITICAL"
],
"title": "Loglevel",
"title": "Mức độ log",
"type": "string"
}
},
"required": [
"plates",
"notifications"
"plates"
],
"title": "ConfigDTO",
"title": "Config",
"type": "object"
}
7 changes: 5 additions & 2 deletions src/check_phat_nguoi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from .config import ConfigDTO
from check_phat_nguoi.get_data import GetData
from check_phat_nguoi.notify import SendNotifications

__all__ = ["ConfigDTO"]
from .config import Config

__all__ = ["Config", "GetData", "SendNotifications"]
3 changes: 1 addition & 2 deletions src/check_phat_nguoi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

from truststore import inject_into_ssl

from check_phat_nguoi import GetData, SendNotifications
from check_phat_nguoi.config.config_reader import config
from check_phat_nguoi.get_data import GetData
from check_phat_nguoi.notify import SendNotifications

from .utils.setup_logger import setup_logger

Expand Down
30 changes: 14 additions & 16 deletions src/check_phat_nguoi/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
from .dto import (
ApiEnum,
BaseNotificationDTO,
BaseNotificationEngineDTO,
ConfigDTO,
PlateInfoDTO,
TelegramNotificationDTO,
TelegramNotificationEngineDTO,
)
from .exceptions import NoConfigFoundException
from .models import (
BaseNotificationConfig,
BaseNotificationEngineConfig,
Config,
PlateInfo,
TelegramNotificationConfig,
TelegramNotificationEngineConfig,
)

__all__ = [
"ApiEnum",
"NoConfigFoundException",
"BaseNotificationDTO",
"BaseNotificationEngineDTO",
"ConfigDTO",
"PlateInfoDTO",
"TelegramNotificationEngineDTO",
"TelegramNotificationDTO",
"BaseNotificationConfig",
"BaseNotificationEngineConfig",
"Config",
"PlateInfo",
"TelegramNotificationEngineConfig",
"TelegramNotificationConfig",
]
13 changes: 6 additions & 7 deletions src/check_phat_nguoi/config/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@

from check_phat_nguoi.constants.config import CONFIG_PATHS

from .dto import ConfigDTO
from .exceptions import NoConfigFoundException
from .models import Config


def _config_reader() -> ConfigDTO:
def _config_reader() -> Config:
for config_path in CONFIG_PATHS:
if path_exists(config_path):
try:
with open(config_path, encoding="utf8") as config:
data = load(config)
return ConfigDTO(**data)
return Config(**data)
except ValidationError as e:
print("Failed to read the config!")
print(e)
exit(1)
print("No config was found!")
exit(1)

raise NoConfigFoundException()


config: Final[ConfigDTO] = _config_reader()
config: Final[Config] = _config_reader()


__all__ = ["config"]
19 changes: 0 additions & 19 deletions src/check_phat_nguoi/config/dto/__init__.py

This file was deleted.

50 changes: 0 additions & 50 deletions src/check_phat_nguoi/config/dto/config.py

This file was deleted.

11 changes: 0 additions & 11 deletions src/check_phat_nguoi/config/dto/notifications/__init__.py

This file was deleted.

9 changes: 0 additions & 9 deletions src/check_phat_nguoi/config/dto/notifications/base_engine.py

This file was deleted.

15 changes: 0 additions & 15 deletions src/check_phat_nguoi/config/dto/notifications/base_notification.py

This file was deleted.

This file was deleted.

17 changes: 17 additions & 0 deletions src/check_phat_nguoi/config/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from .config import Config
from .notifications import (
BaseNotificationConfig,
BaseNotificationEngineConfig,
TelegramNotificationConfig,
TelegramNotificationEngineConfig,
)
from .plate_info import PlateInfo

__all__ = [
"BaseNotificationConfig",
"BaseNotificationEngineConfig",
"Config",
"PlateInfo",
"TelegramNotificationEngineConfig",
"TelegramNotificationConfig",
]
Loading

0 comments on commit 6e39112

Please sign in to comment.