-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
116 lines (82 loc) · 2.89 KB
/
main.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
109
110
111
112
113
114
115
116
import os
from typing import Any
# libs
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
# imports
from models import Float_Id, Attacker_Model, Defender_Model
from functions.calc_v5 import the_calc
from db.queries import (
get_class_basic_skills_query,
get_class_list_query,
get_class_query,
get_class_skills_query,
get_skill_details_query,
get_zone_list_query,
get_zone_query,
)
# =============================================================================
app = FastAPI()
# -----------------------------------------------------------------------------
origins: list[str] = [
"http://localhost",
"http://127.0.0.1",
]
app.add_middleware(
middleware_class=CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
@app.get("/health")
def health_check() -> dict[str, str]:
return {"Server Status": "You've got Py"}
# -----------------------------------------------------------------------------
@app.get("/class/{class_id}")
async def get_class(class_id):
[data] = get_class_query(class_id=class_id)
return data
# -----------------------------------------------------------------------------
@app.get("/class/{class_id}/skill_list")
def get_class_skill_list(class_id) -> list[dict[str, Any]]:
skill_list: list[dict[str, Any]] = get_class_skills_query(class_id=class_id.id)
return skill_list
# -----------------------------------------------------------------------------
@app.get("/class/{skill_id}")
async def get_class_skill(skill_id):
[skill] = get_skill_details_query(skill_id)
return skill["skill_details"]
# -----------------------------------------------------------------------------
@app.put("/basic_calc")
async def basic_calc(
attacker_in: Attacker_Model,
defender_in: Defender_Model,
skill_id: Float_Id,
):
[skill] = get_skill_details_query(skill_id.id)
return the_calc.simulate_damage(attacker_in, defender_in, skill["skill_details"])
# ------------------------------------------------------------------------------
@app.get("/zones")
def get_zone_list() -> list[dict[str, Any]]:
data = get_zone_list_query()
return data
# ------------------------------------------------------------------------------
@app.get("/zones/{zone_id}")
async def get_zone_info(zone_id) -> dict[str, Any]:
[data] = get_zone_query(zone_id)
return data
# ------------------------------------------------------------------------------
server_config = uvicorn.Config(
"main:app",
host="::",
port=(8321),
reload=True if os.getenv("ENVIRONMENT") == "dev" else False,
)
server = uvicorn.Server(server_config)
if __name__ == "__main__":
server.run()
#