forked from KeithGalli/python-api-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
67 lines (52 loc) · 1.89 KB
/
app.py
File metadata and controls
67 lines (52 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from flask import Flask, jsonify, request
from flask_restful import Api, Resource
from flasgger import Swagger
from repositories.price_repository import PriceRepository
import json
from services.price import PriceServices # Si usas JSON
from services.products import ProductsServices
from infraestructure.email.email_service import EmailService
from utils.factory import ServiceFactory
# Crear instancias de servicios
products_service = ProductsServices()
email_service = EmailService()
crm_service = ServiceFactory.get_service("CRM")
# Inyectar dependencias al repositorio
price_repository = PriceRepository(products_service, email_service, crm_service)
price_service = PriceServices(price_repository)
app = Flask(__name__)
api = Api(app)
# Cargar el template desde un archivo JSON
with open('./config/swagger_template.json', 'r') as f:
template = json.load(f)
# Configurar Swagger con el template cargado
swagger = Swagger(app, template=template)
class CreatePrice(Resource):
def post(self):
"""
Este método responde a una solicitud POST para procesar un arreglo de objetos tipo Product.
---
tags:
- Products
parameters:
- in: body
name: body
required: true
schema:
type: array
items:
$ref: '#/definitions/OrderRequest' # Cambia de "#/components/schemas/Product" a "#/definitions/Product"
responses:
200:
description: Solicitud POST exitosa
schema:
type: object
properties:
message:
type: string
description: Mensaje de éxito
"""
return price_service.create_price(request.json)
api.add_resource(CreatePrice, "/price")
if __name__ == "__main__":
app.run(debug=True)