-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainBaseModel.py
108 lines (76 loc) · 2.75 KB
/
MainBaseModel.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from Api import SapConnection
from fastapi import FastAPI, HTTPException, Query
from pydantic import BaseModel
from typing import List, Dict
import uvicorn
app = FastAPI()
class RfcRequest(BaseModel):
ROWSKIPS: int = 0
ROWCOUNT: int = 1000
FIELDS: List[str] = []
WHERE: List[Dict[str, str]] = []
CONFIG :Dict[str,str] = []
TABELA: str
class BapiRequest(BaseModel):
BAPI: str
CONFIG :Dict[str,str] = []
KWARGS : Dict[str,str] = {}
class CustomFuncionarios(BaseModel):
LIST_PAYROLL: List[str]
CONFIG :Dict[str,str]
class FuncionarioModel2(BaseModel):
LIST_PAYROLL: List[str]
CONFIG :Dict[str,str]
PAGE: int
@app.get("/")
async def root():
return {"message": "Conexao SAPRFC-PYRFC- Para Swagger: http://seuip:3000/docs "}
@app.post("/bapi")
async def Bapi(request: BapiRequest, parametro: str = Query('')):
try:
call = SapConnection(request.CONFIG)
result = call.GenericABAPI(
BAPI = request.BAPI,
**request.KWARGS
)
return {"result": result, "parametro": parametro}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@app.post("/rfc")
async def Rfc(request: RfcRequest, parametro: str = Query('')):
try:
call = SapConnection(request.CONFIG)
result = call.RFCgenericTable(
QUERY_TABLE = request.TABELA,
ROWSKIPS=request.ROWSKIPS,
ROWCOUNT=request.ROWCOUNT,
FIELDS=request.FIELDS,
OPTIONS=request.WHERE,
)
return {"result": result, "parametro": parametro}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@app.post("/funcionarios")
async def Funcionarios(request: CustomFuncionarios, parametro: str = Query('')):
try:
call = SapConnection(request.CONFIG)
result = call.FuncionariosPayroll(
LIST_PAYROLL=request.LIST_PAYROLL,
)
return {"result": result, "parametro": parametro}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@app.post("/funcionarios2")
async def Funcionarios(request: FuncionarioModel2, parametro: str = Query('')):
try:
call = SapConnection(request.CONFIG)
result = call.FuncionariosPayroll_Modelo2(
LIST_PAYROLL=request.LIST_PAYROLL,
page=request.PAGE,
limit=50
)
return {"result": result, "parametro": parametro}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
if __name__ == '__main__':
uvicorn.run("MainBaseModel:app", port=3000, host='0.0.0.0', reload=True)