-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (55 loc) · 1.51 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
from fastapi import FastAPI
from service import *
from utils import verify_token
from model import *
app = FastAPI()
@app.post("/api/login")
async def login(item: LoginItem):
"""
用户登陆
:param item:
:return:
"""
return login_service(item.staff_id, item.password)
@app.post("/api/staff")
async def create_staff(token: Token, staff: StaffInfo):
"""
创建用户
:param token:
:param staff:
:return:
"""
staff_id, _ = verify_token(token.access_token)
if staff_id == -1:
return {"msg": "wrong token"}
return create_staff_service(staff_id, staff)
@app.get("/api/staff")
async def get_staff(token: str, staff_id: int):
"""
查询用户
:param token:
:param staff_id:
:return:
"""
user_id, _ = verify_token(token)
if user_id == -1:
return {"msg": "wrong token"}
return select_staff_service(staff_id)
@app.delete("/api/staff/")
async def delete_staff(token: Token, staff_id: StaffID):
"""
删除用户
:param token:
:param staff_id:
:return:
"""
manager_id, _ = verify_token(token.access_token)
if staff_id == -1:
return {"msg": "wrong token"}
return delete_staff_service(staff_id.staff_id, manager_id)
@app.put("/api/staff/{staff_id}")
async def update_staff(token: Token, staff: StaffInfo, staff_id: int):
user_id, _ = verify_token(token.access_token)
if user_id == -1:
return {"msg": "wrong token"}
return update_staff_service(user_id, staff_id, staff)