aiteamutils 0.2.71__tar.gz → 0.2.73__tar.gz
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-0.2.71 → aiteamutils-0.2.73}/PKG-INFO +1 -1
- aiteamutils-0.2.73/aiteamutils/base_service.py +77 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/aiteamutils/database.py +3 -5
- aiteamutils-0.2.73/aiteamutils/version.py +2 -0
- aiteamutils-0.2.71/aiteamutils/base_service.py +0 -47
- aiteamutils-0.2.71/aiteamutils/version.py +0 -2
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/.cursorrules +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/.gitignore +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/README.md +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/aiteamutils/__init__.py +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/aiteamutils/base_model.py +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/aiteamutils/base_repository.py +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/aiteamutils/cache.py +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/aiteamutils/config.py +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/aiteamutils/enums.py +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/aiteamutils/exceptions.py +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/aiteamutils/security.py +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/aiteamutils/validators.py +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/pyproject.toml +0 -0
- {aiteamutils-0.2.71 → aiteamutils-0.2.73}/setup.py +0 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
#기본 라이브러리
|
2
|
+
from fastapi import Request
|
3
|
+
from typing import TypeVar, Generic, Type, Dict, Any, Union, List
|
4
|
+
from sqlalchemy.orm import DeclarativeBase
|
5
|
+
from sqlalchemy.ext.asyncio import AsyncSession
|
6
|
+
from datetime import datetime
|
7
|
+
|
8
|
+
#패키지 라이브러리
|
9
|
+
from .exceptions import ErrorCode, CustomException
|
10
|
+
from .base_repository import BaseRepository
|
11
|
+
from .database import (
|
12
|
+
process_response,
|
13
|
+
build_search_filters
|
14
|
+
)
|
15
|
+
|
16
|
+
ModelType = TypeVar("ModelType", bound=DeclarativeBase)
|
17
|
+
|
18
|
+
class BaseService(Generic[ModelType]):
|
19
|
+
##################
|
20
|
+
# 1. 초기화 영역 #
|
21
|
+
##################
|
22
|
+
def __init__(
|
23
|
+
self,
|
24
|
+
model: Type[ModelType],
|
25
|
+
repository: BaseRepository[ModelType],
|
26
|
+
db_session: AsyncSession,
|
27
|
+
additional_models: Dict[str, Type[DeclarativeBase]] = None,
|
28
|
+
):
|
29
|
+
self.model = model
|
30
|
+
self.repository = repository
|
31
|
+
self.db_session = db_session
|
32
|
+
self.additional_models = additional_models or {},
|
33
|
+
|
34
|
+
async def list(
|
35
|
+
self,
|
36
|
+
skip: int = 0,
|
37
|
+
limit: int = 100,
|
38
|
+
filters: Dict[str, Any] | None = None,
|
39
|
+
search_params: Dict[str, Any] | None = None,
|
40
|
+
model_name: str | None = None,
|
41
|
+
response_model: Any = None
|
42
|
+
) -> List[Dict[str, Any]]:
|
43
|
+
try:
|
44
|
+
# 검색 조건 처리 및 필터 병합
|
45
|
+
if search_params:
|
46
|
+
search_filters = build_search_filters(search_params)
|
47
|
+
if filters:
|
48
|
+
# 기존 filters와 search_filters 병합 (search_filters가 우선 적용)
|
49
|
+
filters.update(search_filters)
|
50
|
+
else:
|
51
|
+
filters = search_filters
|
52
|
+
|
53
|
+
# 모델 이름을 통한 동적 처리
|
54
|
+
if model_name:
|
55
|
+
if model_name not in self.additional_models:
|
56
|
+
raise CustomException(
|
57
|
+
ErrorCode.INVALID_REQUEST,
|
58
|
+
detail=f"Model {model_name} not registered",
|
59
|
+
source_function=f"{self.__class__.__name__}.list"
|
60
|
+
)
|
61
|
+
model = self.additional_models[model_name]
|
62
|
+
return await self.repository.list(skip=skip, limit=limit, filters=filters, model=model)
|
63
|
+
|
64
|
+
return await self.repository.list(skip=skip, limit=limit, filters=filters)
|
65
|
+
except CustomException as e:
|
66
|
+
e.detail = f"Service list error for {self.repository.model.__tablename__}: {e.detail}"
|
67
|
+
e.source_function = f"{self.__class__.__name__}.list -> {e.source_function}"
|
68
|
+
raise e
|
69
|
+
except Exception as e:
|
70
|
+
raise CustomException(
|
71
|
+
ErrorCode.INTERNAL_ERROR,
|
72
|
+
detail=str(e),
|
73
|
+
source_function=f"{self.__class__.__name__}.list",
|
74
|
+
original_error=e
|
75
|
+
)
|
76
|
+
|
77
|
+
|
@@ -120,14 +120,12 @@ def process_response(
|
|
120
120
|
# 조건 처리 #
|
121
121
|
##################
|
122
122
|
def build_search_filters(
|
123
|
-
request: Dict[str, Any],
|
124
123
|
search_params: Dict[str, Dict[str, Any]]
|
125
124
|
) -> Dict[str, Any]:
|
126
125
|
"""
|
127
|
-
|
126
|
+
검색 파라미터를 기반으로 필터 조건을 생성합니다.
|
128
127
|
|
129
128
|
Args:
|
130
|
-
request: 요청 데이터 (key-value 형태).
|
131
129
|
search_params: 검색 조건 설정을 위한 파라미터.
|
132
130
|
|
133
131
|
Returns:
|
@@ -135,9 +133,9 @@ def build_search_filters(
|
|
135
133
|
"""
|
136
134
|
filters = {}
|
137
135
|
for key, param in search_params.items():
|
138
|
-
value =
|
136
|
+
value = param.get("value")
|
139
137
|
if value is not None:
|
140
|
-
if param
|
138
|
+
if param.get("like", False):
|
141
139
|
filters[key] = {"field": param["fields"][0], "operator": "like", "value": f"%{value}%"}
|
142
140
|
else:
|
143
141
|
filters[key] = {"field": param["fields"][0], "operator": "eq", "value": value}
|
@@ -1,47 +0,0 @@
|
|
1
|
-
#기본 라이브러리
|
2
|
-
from fastapi import Request
|
3
|
-
from typing import TypeVar, Generic, Type, Dict, Any, Union, List
|
4
|
-
from sqlalchemy.orm import DeclarativeBase
|
5
|
-
from sqlalchemy.ext.asyncio import AsyncSession
|
6
|
-
from datetime import datetime
|
7
|
-
|
8
|
-
#패키지 라이브러리
|
9
|
-
from .exceptions import ErrorCode, CustomException
|
10
|
-
from .base_repository import BaseRepository
|
11
|
-
from .database import (
|
12
|
-
process_response,
|
13
|
-
build_search_filters
|
14
|
-
)
|
15
|
-
|
16
|
-
ModelType = TypeVar("ModelType", bound=DeclarativeBase)
|
17
|
-
|
18
|
-
class BaseService(Generic[ModelType]):
|
19
|
-
##################
|
20
|
-
# 1. 초기화 영역 #
|
21
|
-
##################
|
22
|
-
def __init__(
|
23
|
-
self,
|
24
|
-
model: Type[ModelType],
|
25
|
-
repository: BaseRepository[ModelType],
|
26
|
-
db_session: AsyncSession,
|
27
|
-
additional_models: Dict[str, Type[DeclarativeBase]] = None,
|
28
|
-
):
|
29
|
-
self.model = model
|
30
|
-
self.repository = repository
|
31
|
-
self.db_session = db_session
|
32
|
-
self.additional_models = additional_models or {},
|
33
|
-
|
34
|
-
async def list(
|
35
|
-
self,
|
36
|
-
skip: int = 0,
|
37
|
-
limit: int = 100,
|
38
|
-
filters: Dict[str, Any] | None =
|
39
|
-
except Exception as e:
|
40
|
-
raise CustomException(
|
41
|
-
ErrorCode.INTERNAL_ERROR,
|
42
|
-
detail=str(e),
|
43
|
-
source_function=f"{self.__class__.__name__}.list",
|
44
|
-
original_error=e
|
45
|
-
)
|
46
|
-
|
47
|
-
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|