aiteamutils 0.2.113__py3-none-any.whl → 0.2.115__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/database.py +12 -1
- aiteamutils/validators.py +43 -36
- aiteamutils/version.py +1 -1
- {aiteamutils-0.2.113.dist-info → aiteamutils-0.2.115.dist-info}/METADATA +1 -1
- {aiteamutils-0.2.113.dist-info → aiteamutils-0.2.115.dist-info}/RECORD +6 -6
- {aiteamutils-0.2.113.dist-info → aiteamutils-0.2.115.dist-info}/WHEEL +0 -0
aiteamutils/database.py
CHANGED
@@ -468,7 +468,18 @@ async def list_entities(
|
|
468
468
|
# 정렬 조건 적용
|
469
469
|
if order:
|
470
470
|
for order_item in order:
|
471
|
-
query = query.order_by(
|
471
|
+
query = query.order_by(
|
472
|
+
getattr(
|
473
|
+
model,
|
474
|
+
order_item["field"]
|
475
|
+
).desc()
|
476
|
+
if order_item["direction"] == "desc"
|
477
|
+
else
|
478
|
+
getattr(
|
479
|
+
model,
|
480
|
+
order_item["field"]
|
481
|
+
).asc()
|
482
|
+
)
|
472
483
|
|
473
484
|
# 페이지네이션 적용
|
474
485
|
query = query.limit(limit).offset(skip)
|
aiteamutils/validators.py
CHANGED
@@ -193,14 +193,13 @@ class Validator:
|
|
193
193
|
@staticmethod
|
194
194
|
def validate_date(value: Any, field_name: str = "date") -> Optional[date]:
|
195
195
|
"""날짜 형식 검증을 수행하는 메서드."""
|
196
|
-
|
196
|
+
# 빈 값 처리를 가장 먼저
|
197
|
+
if not value or str(value).strip() == "":
|
197
198
|
return None
|
198
199
|
if isinstance(value, date):
|
199
200
|
return value
|
200
201
|
if isinstance(value, datetime):
|
201
202
|
return value.date()
|
202
|
-
if value == "" or not value:
|
203
|
-
return None
|
204
203
|
try:
|
205
204
|
return datetime.strptime(str(value), '%Y-%m-%d').date()
|
206
205
|
except Exception as e:
|
@@ -214,14 +213,13 @@ class Validator:
|
|
214
213
|
@staticmethod
|
215
214
|
def validate_datetime(value: Any, field_name: str = "datetime") -> Optional[datetime]:
|
216
215
|
"""날짜+시간 형식 검증을 수행하는 메서드."""
|
217
|
-
|
216
|
+
# 빈 값 처리를 가장 먼저
|
217
|
+
if not value or str(value).strip() == "":
|
218
218
|
return None
|
219
219
|
if isinstance(value, datetime):
|
220
220
|
return value
|
221
221
|
if isinstance(value, date):
|
222
222
|
return datetime.combine(value, datetime.min.time())
|
223
|
-
if value == "" or not value:
|
224
|
-
return None
|
225
223
|
try:
|
226
224
|
# ISO 형식 (YYYY-MM-DDTHH:MM:SS) 먼저 시도
|
227
225
|
try:
|
@@ -237,54 +235,63 @@ class Validator:
|
|
237
235
|
original_error=str(e)
|
238
236
|
)
|
239
237
|
|
240
|
-
def
|
241
|
-
|
238
|
+
def _create_validator(field_names: tuple[str, ...],
|
239
|
+
validate_func: Callable,
|
240
|
+
field_type: Type,
|
241
|
+
error_code: ErrorCode,
|
242
|
+
source_prefix: str):
|
243
|
+
"""공통 validator 생성 함수
|
242
244
|
Args:
|
243
245
|
field_names: 검증할 필드명들
|
246
|
+
validate_func: 실제 검증을 수행할 함수
|
247
|
+
field_type: 필드 타입 (date 또는 datetime)
|
248
|
+
error_code: 에러 발생시 사용할 에러 코드
|
249
|
+
source_prefix: 에러 발생시 사용할 source_function 접두사
|
244
250
|
"""
|
245
251
|
def decorator(cls):
|
246
252
|
for field_name in field_names:
|
253
|
+
field = cls.model_fields.get(field_name)
|
254
|
+
if field:
|
255
|
+
field.annotation = Optional[field_type]
|
256
|
+
field.default = None
|
257
|
+
|
247
258
|
@field_validator(field_name, mode='before')
|
248
259
|
@classmethod
|
249
260
|
def validate(cls, value: Any, info: Any) -> Any:
|
261
|
+
# 빈 값 처리를 가장 먼저, 더 엄격하게
|
262
|
+
if not value or str(value).strip() == "":
|
263
|
+
return None
|
250
264
|
try:
|
251
|
-
|
252
|
-
return None
|
253
|
-
return Validator.validate_date(value, field_name)
|
265
|
+
return validate_func(value, field_name)
|
254
266
|
except CustomException as e:
|
255
267
|
raise e
|
256
268
|
except Exception as e:
|
257
269
|
raise CustomException(
|
258
|
-
error_code=
|
270
|
+
error_code=error_code,
|
259
271
|
detail=f"{field_name}|{value}",
|
260
|
-
source_function=f"
|
272
|
+
source_function=f"{source_prefix}.{field_name}",
|
261
273
|
original_error=str(e)
|
262
274
|
)
|
263
275
|
setattr(cls, f'validate_{field_name}', validate)
|
264
276
|
return cls
|
265
277
|
return decorator
|
266
278
|
|
279
|
+
def date_validator(*field_names: str):
|
280
|
+
"""날짜 필드 유효성 검사 데코레이터"""
|
281
|
+
return _create_validator(
|
282
|
+
field_names=field_names,
|
283
|
+
validate_func=Validator.validate_date,
|
284
|
+
field_type=date,
|
285
|
+
error_code=ErrorCode.INVALID_DATE_FORMAT,
|
286
|
+
source_prefix="date_validator"
|
287
|
+
)
|
288
|
+
|
267
289
|
def datetime_validator(*field_names: str):
|
268
|
-
"""날짜+시간 필드 유효성 검사 데코레이터
|
269
|
-
|
270
|
-
field_names
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
def validate(cls, value: Any, info: Any) -> Any:
|
277
|
-
try:
|
278
|
-
return Validator.validate_datetime(value, field_name)
|
279
|
-
except CustomException as e:
|
280
|
-
raise e
|
281
|
-
except Exception as e:
|
282
|
-
raise CustomException(
|
283
|
-
error_code=ErrorCode.INVALID_DATETIME_FORMAT,
|
284
|
-
detail=f"{field_name}|{value}",
|
285
|
-
source_function=f"datetime_validator.{field_name}",
|
286
|
-
original_error=str(e)
|
287
|
-
)
|
288
|
-
setattr(cls, f'validate_{field_name}', validate)
|
289
|
-
return cls
|
290
|
-
return decorator
|
290
|
+
"""날짜+시간 필드 유효성 검사 데코레이터"""
|
291
|
+
return _create_validator(
|
292
|
+
field_names=field_names,
|
293
|
+
validate_func=Validator.validate_datetime,
|
294
|
+
field_type=datetime,
|
295
|
+
error_code=ErrorCode.INVALID_DATETIME_FORMAT,
|
296
|
+
source_prefix="datetime_validator"
|
297
|
+
)
|
aiteamutils/version.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
"""버전 정보"""
|
2
|
-
__version__ = "0.2.
|
2
|
+
__version__ = "0.2.115"
|
@@ -4,12 +4,12 @@ aiteamutils/base_repository.py,sha256=vzBw3g3jCJetTDblZvZenEGXk89Qu_65_02C7QTcf8
|
|
4
4
|
aiteamutils/base_service.py,sha256=nHikjwGp29QrQPr2W8Ye9sKxmVS_8prRG3Nu42TU1Ms,10670
|
5
5
|
aiteamutils/cache.py,sha256=07xBGlgAwOTAdY5mnMOQJ5EBxVwe8glVD7DkGEkxCtw,1373
|
6
6
|
aiteamutils/config.py,sha256=YdalpJb70-txhGJAS4aaKglEZAFVWgfzw5BXSWpkUz4,3232
|
7
|
-
aiteamutils/database.py,sha256=
|
7
|
+
aiteamutils/database.py,sha256=2D4YX8sfxZCvhKoqKSNbxyIZTb9Wc2-jsNBpLA7T7s0,19939
|
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=9JY-92sSj6Bm_AcmZFqPc6hgxS57RzPpLXO1PPkDk3M,11968
|
12
|
+
aiteamutils/version.py,sha256=yOY-U_JbPxKh_qtXMmCE0w-8SQ5lpFBwa4dzb9rXxBY,43
|
13
|
+
aiteamutils-0.2.115.dist-info/METADATA,sha256=NYVmi0mcYhlaEjDGidOl_pF8dXq5wkHEA8jWEr1q61c,1719
|
14
|
+
aiteamutils-0.2.115.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
15
|
+
aiteamutils-0.2.115.dist-info/RECORD,,
|
File without changes
|