-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
47 lines (42 loc) · 1.44 KB
/
Copy pathapi.py
File metadata and controls
47 lines (42 loc) · 1.44 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
from fastapi import FastAPI
from typing import Union
import lookup
from fastapi import HTTPException
from models import Punishment, DataResponse, Username
app = FastAPI()
@app.get(
"/punishments/username/{username}",
responses={
404: {
"description": "Record Not Found",
"content": {
"application/json": {
"examples": {
"No UUID found": {
"value": {"detail": "ERR_PLAYER_NO_UUID"},
"description": "No UUID could be found for this username.",
},
"Player hasn't joined": {
"value": {"detail": "ERR_PLAYER_NEVER_JOIN"},
"description": "This player has never joined the server.",
},
}
}
},
}
},
)
def read_item(username: Username) -> DataResponse:
"""
Retrieves punishment data for a given username.
Returns an overview with the current punishment `status` of the account, and the full known `history` of moderations.
"""
data = lookup.getPunishments(username=username)
if isinstance(data, Exception):
raise HTTPException(status_code=500, detail=data)
return DataResponse(
username=username,
uuid=data["uuid"],
status=data["status"],
history=data["history"],
)