aiteamutils 0.2.114__py3-none-any.whl → 0.2.116__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/exceptions.py +2 -0
- aiteamutils/validators.py +38 -36
- aiteamutils/version.py +1 -1
- {aiteamutils-0.2.114.dist-info → aiteamutils-0.2.116.dist-info}/METADATA +1 -1
- {aiteamutils-0.2.114.dist-info → aiteamutils-0.2.116.dist-info}/RECORD +7 -7
- {aiteamutils-0.2.114.dist-info → aiteamutils-0.2.116.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/exceptions.py
CHANGED
@@ -67,6 +67,8 @@ class ErrorCode(Enum):
|
|
67
67
|
REQUIRED_FIELD_MISSING = ErrorResponse(4003, "VALIDATION_REQUIRED_FIELD_MISSING", 400, "필수 필드가 누락되었습니다")
|
68
68
|
FIELD_INVALID_UNIQUE = ErrorResponse(4004, "VALIDATION_FIELD_INVALID_UNIQUE", 400, "중복된 값이 존재합니다")
|
69
69
|
FIELD_INVALID_NOT_EXIST = ErrorResponse(4005, "VALIDATION_FIELD_INVALID_NOT_EXIST", 400, "존재하지 않는 값입니다")
|
70
|
+
INVALID_DATE_FORMAT = ErrorResponse(4006, "VALIDATION_INVALID_DATE_FORMAT", 400, "잘못된 날짜 형식입니다")
|
71
|
+
INVALID_DATETIME_FORMAT = ErrorResponse(4007, "VALIDATION_INVALID_DATETIME_FORMAT", 400, "잘못된 날짜+시간 형식입니다")
|
70
72
|
|
71
73
|
# General 에러: 5000번대
|
72
74
|
NOT_FOUND = ErrorResponse(5001, "GENERAL_NOT_FOUND", 404, "리소스를 찾을 수 없습니다")
|
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,59 +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:
|
247
253
|
field = cls.model_fields.get(field_name)
|
248
254
|
if field:
|
249
|
-
field.annotation = Optional[
|
255
|
+
field.annotation = Optional[field_type]
|
250
256
|
field.default = None
|
251
257
|
|
252
258
|
@field_validator(field_name, mode='before')
|
253
259
|
@classmethod
|
254
260
|
def validate(cls, value: Any, info: Any) -> Any:
|
255
|
-
|
261
|
+
# 빈 값 처리를 가장 먼저, 더 엄격하게
|
262
|
+
if not value or str(value).strip() == "":
|
256
263
|
return None
|
257
264
|
try:
|
258
|
-
return
|
265
|
+
return validate_func(value, field_name)
|
259
266
|
except CustomException as e:
|
260
267
|
raise e
|
261
268
|
except Exception as e:
|
262
269
|
raise CustomException(
|
263
|
-
error_code=
|
270
|
+
error_code=error_code,
|
264
271
|
detail=f"{field_name}|{value}",
|
265
|
-
source_function=f"
|
272
|
+
source_function=f"{source_prefix}.{field_name}",
|
266
273
|
original_error=str(e)
|
267
274
|
)
|
268
275
|
setattr(cls, f'validate_{field_name}', validate)
|
269
276
|
return cls
|
270
277
|
return decorator
|
271
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
|
+
|
272
289
|
def datetime_validator(*field_names: str):
|
273
|
-
"""날짜+시간 필드 유효성 검사 데코레이터
|
274
|
-
|
275
|
-
field_names
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
def validate(cls, value: Any, info: Any) -> Any:
|
282
|
-
try:
|
283
|
-
return Validator.validate_datetime(value, field_name)
|
284
|
-
except CustomException as e:
|
285
|
-
raise e
|
286
|
-
except Exception as e:
|
287
|
-
raise CustomException(
|
288
|
-
error_code=ErrorCode.INVALID_DATETIME_FORMAT,
|
289
|
-
detail=f"{field_name}|{value}",
|
290
|
-
source_function=f"datetime_validator.{field_name}",
|
291
|
-
original_error=str(e)
|
292
|
-
)
|
293
|
-
setattr(cls, f'validate_{field_name}', validate)
|
294
|
-
return cls
|
295
|
-
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.116"
|
@@ -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
|
-
aiteamutils/exceptions.py,sha256=
|
9
|
+
aiteamutils/exceptions.py,sha256=F4bzdS-Z31sgvtFi-aCBKXbITwDZWdzGUU9vsXn9nv0,16292
|
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=-6jnB1sRYpqFykStCMJbQTLKH0qIF38FBYio__WGrJg,43
|
13
|
+
aiteamutils-0.2.116.dist-info/METADATA,sha256=hrb0uNqkR9agW-ArHJCLodUH153WGjTu7eMCoOdXZis,1719
|
14
|
+
aiteamutils-0.2.116.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
15
|
+
aiteamutils-0.2.116.dist-info/RECORD,,
|
File without changes
|