aiteamutils 0.2.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- aiteamutils/__init__.py +60 -0
- aiteamutils/base_model.py +81 -0
- aiteamutils/base_repository.py +503 -0
- aiteamutils/base_service.py +668 -0
- aiteamutils/cache.py +48 -0
- aiteamutils/config.py +26 -0
- aiteamutils/database.py +823 -0
- aiteamutils/dependencies.py +158 -0
- aiteamutils/enums.py +23 -0
- aiteamutils/exceptions.py +333 -0
- aiteamutils/security.py +396 -0
- aiteamutils/validators.py +188 -0
- aiteamutils-0.2.0.dist-info/METADATA +72 -0
- aiteamutils-0.2.0.dist-info/RECORD +15 -0
- aiteamutils-0.2.0.dist-info/WHEEL +4 -0
aiteamutils/cache.py
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
from typing import Any, Optional
|
2
|
+
from redis.asyncio import Redis
|
3
|
+
from app.config import settings
|
4
|
+
|
5
|
+
class Cache:
|
6
|
+
_instance = None
|
7
|
+
_redis = None
|
8
|
+
|
9
|
+
@classmethod
|
10
|
+
async def get_instance(cls):
|
11
|
+
"""캐시 인스턴스를 가져옵니다.
|
12
|
+
|
13
|
+
Returns:
|
14
|
+
캐시 인스턴스
|
15
|
+
"""
|
16
|
+
if not cls._instance:
|
17
|
+
cls._instance = cls()
|
18
|
+
cls._redis = Redis.from_url(settings.REDIS_URL, encoding="utf-8", decode_responses=True)
|
19
|
+
return cls._instance
|
20
|
+
|
21
|
+
async def get(self, key: str) -> Optional[str]:
|
22
|
+
"""키에 해당하는 값을 가져옵니다.
|
23
|
+
|
24
|
+
Args:
|
25
|
+
key: 캐시 키
|
26
|
+
|
27
|
+
Returns:
|
28
|
+
캐시 값, 없으면 None
|
29
|
+
"""
|
30
|
+
return await self._redis.get(key)
|
31
|
+
|
32
|
+
async def set(self, key: str, value: Any, expire: int = 3600):
|
33
|
+
"""키에 값을 설정하고 만료 시간을 설정합니다.
|
34
|
+
|
35
|
+
Args:
|
36
|
+
key: 캐시 키
|
37
|
+
value: 캐시 값
|
38
|
+
expire: 만료 시간 (기본값: 1시간)
|
39
|
+
"""
|
40
|
+
await self._redis.set(key, value, ex=expire)
|
41
|
+
|
42
|
+
async def delete(self, key: str):
|
43
|
+
"""키에 해당하는 값을 삭제합니다.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
key: 캐시 키
|
47
|
+
"""
|
48
|
+
await self._redis.delete(key)
|
aiteamutils/config.py
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
"""설정 모듈."""
|
2
|
+
from typing import Optional
|
3
|
+
from pydantic_settings import BaseSettings
|
4
|
+
|
5
|
+
class Settings(BaseSettings):
|
6
|
+
"""애플리케이션 설정."""
|
7
|
+
|
8
|
+
# 데이터베이스 설정
|
9
|
+
DB_ECHO: bool = False
|
10
|
+
DB_POOL_SIZE: int = 5
|
11
|
+
DB_MAX_OVERFLOW: int = 10
|
12
|
+
DB_POOL_TIMEOUT: int = 30
|
13
|
+
DB_POOL_RECYCLE: int = 1800
|
14
|
+
|
15
|
+
# JWT 설정
|
16
|
+
JWT_SECRET: str = "your-secret-key"
|
17
|
+
JWT_ALGORITHM: str = "HS256"
|
18
|
+
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
|
19
|
+
TOKEN_ISSUER: str = "ai-team-platform"
|
20
|
+
TOKEN_AUDIENCE: str = "ai-team-users"
|
21
|
+
|
22
|
+
class Config:
|
23
|
+
env_file = ".env"
|
24
|
+
case_sensitive = True
|
25
|
+
|
26
|
+
settings = Settings()
|