Bank Services tested and completed

This commit is contained in:
2025-04-21 14:33:25 +03:00
parent 2c5f00ab1d
commit 35aab0ba11
31 changed files with 1751 additions and 15 deletions

View File

@@ -10,19 +10,18 @@ class Configs(BaseSettings):
USERNAME: str = ""
PASSWORD: str = ""
PORT: int = 0
SEND: bool = False
SEND: bool = 0
@property
def is_send(self):
return bool(self.SEND)
@classmethod
def as_dict(cls):
def as_dict(self):
return dict(
host=cls.EMAIL_HOST,
port=cls.EMAIL_PORT,
username=cls.EMAIL_USERNAME,
password=cls.EMAIL_PASSWORD,
host=self.HOST,
port=self.PORT,
username=self.USERNAME,
password=self.PASSWORD,
)
model_config = SettingsConfigDict(env_prefix="EMAIL_")

View File

@@ -1,8 +1,8 @@
from redmail import EmailSender
from typing import List, Optional, Dict
from pydantic import BaseModel
from config import Configs
from contextlib import contextmanager
from .config import email_configs
class EmailSendModel(BaseModel):
@@ -23,11 +23,10 @@ class EmailSession:
def send(self, params: EmailSendModel) -> bool:
"""Send email using this session."""
if not Configs.is_send:
if not email_configs.is_send:
print("Email sending is disabled", params)
return False
receivers = [Configs.USERNAME]
receivers = [email_configs.USERNAME]
self.email_sender.send(
subject=params.subject,
receivers=receivers,
@@ -53,7 +52,7 @@ class EmailService:
@contextmanager
def new_session(cls):
"""Create and yield a new email session with active connection."""
email_sender = EmailSender(**Configs.as_dict())
email_sender = EmailSender(**email_configs.as_dict())
session = EmailSession(email_sender)
try:
email_sender.connect()

View File

@@ -216,6 +216,7 @@ class CRUDModel:
cls,
db: Session,
exclude_args: Optional[list[InstrumentedAttribute]] = None,
include_args: Optional[list[InstrumentedAttribute]] = None,
**kwargs,
):
"""
@@ -224,6 +225,7 @@ class CRUDModel:
Args:
db: Database session
exclude_args: Keys to exclude from search
include_args: Keys to specifically include in search (if provided, only these will be used)
**kwargs: Search/creation criteria
Returns:
@@ -238,10 +240,18 @@ class CRUDModel:
exclude_args = exclude_args or []
exclude_args = [exclude_arg.key for exclude_arg in exclude_args]
include_args = include_args or []
include_args = [include_arg.key for include_arg in include_args]
# If include_args is provided, only use those fields for matching
# Otherwise, use all fields except those in exclude_args
for key, value in kwargs.items():
if hasattr(cls, key) and key not in exclude_args:
query = query.filter(getattr(cls, key) == value)
if hasattr(cls, key):
if include_args and key in include_args:
query = query.filter(getattr(cls, key) == value)
elif not include_args and key not in exclude_args:
query = query.filter(getattr(cls, key) == value)
already_record = query.first()
if already_record: # Handle existing record