aiteamutils 0.2.108__py3-none-any.whl → 0.2.109__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aiteamutils/validators.py
CHANGED
@@ -7,6 +7,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|
7
7
|
from fastapi import Request
|
8
8
|
from inspect import signature
|
9
9
|
from pydantic import BaseModel, field_validator
|
10
|
+
from datetime import datetime, date
|
10
11
|
import re
|
11
12
|
|
12
13
|
from .exceptions import ErrorCode, CustomException
|
@@ -187,4 +188,36 @@ class Validator:
|
|
187
188
|
ErrorCode.VALIDATION_ERROR,
|
188
189
|
detail=f"{field_name}|{name}",
|
189
190
|
source_function="Validator.validate_name"
|
190
|
-
)
|
191
|
+
)
|
192
|
+
|
193
|
+
@staticmethod
|
194
|
+
def validate_date(value: Any, field_name: str = "date") -> Optional[date]:
|
195
|
+
"""날짜 형식 검증을 수행하는 메서드."""
|
196
|
+
if value is None or isinstance(value, date):
|
197
|
+
return value
|
198
|
+
if value == "":
|
199
|
+
return None
|
200
|
+
try:
|
201
|
+
return datetime.strptime(str(value), '%Y-%m-%d').date()
|
202
|
+
except Exception as e:
|
203
|
+
raise CustomException(
|
204
|
+
error_code=ErrorCode.INVALID_DATE_FORMAT,
|
205
|
+
detail=f"{field_name}|{value}",
|
206
|
+
source_function="Validator.validate_date",
|
207
|
+
original_error=str(e)
|
208
|
+
)
|
209
|
+
|
210
|
+
def date_validator(*field_names: str):
|
211
|
+
"""날짜 필드 유효성 검사 데코레이터
|
212
|
+
Args:
|
213
|
+
field_names: 검증할 필드명들
|
214
|
+
"""
|
215
|
+
def decorator(cls):
|
216
|
+
for field_name in field_names:
|
217
|
+
@field_validator(field_name, mode='before')
|
218
|
+
@classmethod
|
219
|
+
def validate(cls, value: Any, info: Any) -> Any:
|
220
|
+
return Validator.validate_date(value, field_name)
|
221
|
+
setattr(cls, f'validate_{field_name}', validate)
|
222
|
+
return cls
|
223
|
+
return decorator
|
aiteamutils/version.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
"""버전 정보"""
|
2
|
-
__version__ = "0.2.
|
2
|
+
__version__ = "0.2.109"
|
@@ -8,8 +8,8 @@ aiteamutils/database.py,sha256=SmE6JiyQoqCNlrV4AVxrp1tsrNryyZSQWJM0dHN4MQA,19696
|
|
8
8
|
aiteamutils/enums.py,sha256=7WLqlcJqQWtETAga2WAxNp3dJTQIAd2TW-4WzkoHHa8,2498
|
9
9
|
aiteamutils/exceptions.py,sha256=pgf3ersezObyl17wAO3I2fb8m9t2OzWDX1mSjwAWm2Y,16035
|
10
10
|
aiteamutils/security.py,sha256=McUl3t5Z5SyUDVUHymHdDkYyF4YSeg4g9fFMML4W6Kw,11630
|
11
|
-
aiteamutils/validators.py,sha256=
|
12
|
-
aiteamutils/version.py,sha256=
|
13
|
-
aiteamutils-0.2.
|
14
|
-
aiteamutils-0.2.
|
15
|
-
aiteamutils-0.2.
|
11
|
+
aiteamutils/validators.py,sha256=4H65pmH4SeaGY0MlIYmnzNC_RWRIAF4B6kOtxD1hhNw,8940
|
12
|
+
aiteamutils/version.py,sha256=M0lPuKKEr3BkcMhw_Z_nK2KV8aOLBpsJFlxGcoaEUxg,43
|
13
|
+
aiteamutils-0.2.109.dist-info/METADATA,sha256=Gv8cjx0BTr5Q5WntI1GP03IgNzhZZjjBqGwqxBYR5SY,1719
|
14
|
+
aiteamutils-0.2.109.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
15
|
+
aiteamutils-0.2.109.dist-info/RECORD,,
|
File without changes
|