feat(api): Added email api
This commit is contained in:
1 parent
b21d2bb031
commit
df627d4afe
3 files changed
+32
-4
No files matched your search
@@ -0,0 +1,29 @@
|
|||||||
|
from flask import jsonify, request
|
||||||
|
from utils.mail import send_lead_to_email
|
||||||
|
from flask import Blueprint
|
||||||
|
|
||||||
|
# Создаем blueprint для API
|
||||||
|
api_email = Blueprint('api_email', __name__, url_prefix='/api/email')
|
||||||
|
|
||||||
|
@api_email.route('/', methods=['POST'])
|
||||||
|
def post_email():
|
||||||
|
if not request.is_json:
|
||||||
|
return jsonify({"error": "Content-Type must be application/json"}), 400
|
||||||
|
|
||||||
|
data = request.get_json()
|
||||||
|
|
||||||
|
# Извлекаем поля с проверкой наличия
|
||||||
|
name = data.get('name')
|
||||||
|
phone = data.get('phone')
|
||||||
|
email = data.get('email')
|
||||||
|
|
||||||
|
if not name or not phone or not email:
|
||||||
|
return jsonify({"error": "Missing required fields: name, phone, email"}), 400
|
||||||
|
|
||||||
|
# Отправляем заявку на почту
|
||||||
|
success = send_lead_to_email(name, phone, email)
|
||||||
|
|
||||||
|
if success:
|
||||||
|
return jsonify({"status": "success", "message": "Lead sent successfully"}), 200
|
||||||
|
else:
|
||||||
|
return jsonify({"status": "error", "message": "Failed to send email"}), 500
|
||||||
@@ -6,6 +6,7 @@ from db.InitializeDBData import init_tables
|
|||||||
from utils.loadDotENV import initializeENV
|
from utils.loadDotENV import initializeENV
|
||||||
from api.categories import api_category
|
from api.categories import api_category
|
||||||
from api.product import api_product
|
from api.product import api_product
|
||||||
|
from api.email import api_email
|
||||||
|
|
||||||
# Инициализация
|
# Инициализация
|
||||||
initializeENV()
|
initializeENV()
|
||||||
@@ -19,6 +20,7 @@ CORS(app)
|
|||||||
# Регистрируем blueprint
|
# Регистрируем blueprint
|
||||||
app.register_blueprint(api_category)
|
app.register_blueprint(api_category)
|
||||||
app.register_blueprint(api_product)
|
app.register_blueprint(api_product)
|
||||||
|
app.register_blueprint(api_email)
|
||||||
|
|
||||||
@app.route('/health', methods=['GET'])
|
@app.route('/health', methods=['GET'])
|
||||||
def health_check():
|
def health_check():
|
||||||
|
|||||||
+1
-4
@@ -1,12 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
import smtplib
|
import smtplib
|
||||||
import logging
|
from loguru import logger
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
|
||||||
# Настройка логирования
|
|
||||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
def send_lead_to_email(name, phone, email):
|
def send_lead_to_email(name, phone, email):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in new issue
Block a user