-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock_server.py
More file actions
131 lines (106 loc) · 4.91 KB
/
mock_server.py
File metadata and controls
131 lines (106 loc) · 4.91 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""
Mock Backend Server for PoC Testing
"""
from fastapi import FastAPI, Query
from datetime import date, datetime
from typing import Optional
import random
app = FastAPI(title="Mock Backend API", version="1.0.0")
# ═══════════════════════════════════════════════════════════════════
# Mock Data
# ═══════════════════════════════════════════════════════════════════
NAMES = ["王小明", "李美玲", "張大華", "陳淑芬", "林志偉", "黃雅婷"]
DEPARTMENTS = ["Engineering", "Sales", "HR", "Finance", "Marketing"]
POSITIONS = ["Software Engineer", "Sales Manager", "HR Specialist", "Accountant"]
# ═══════════════════════════════════════════════════════════════════
# HR APIs
# ═══════════════════════════════════════════════════════════════════
@app.get("/api/hr/interviews")
def list_interviews(
start_date: Optional[str] = Query(None),
end_date: Optional[str] = Query(None),
status: Optional[str] = Query(None),
department: Optional[str] = Query(None),
):
"""Get interview list"""
# Generate mock data
count = random.randint(30, 50)
interviews = []
for i in range(count):
interviews.append(
{
"id": 1000 + i,
"candidate_name": random.choice(NAMES),
"position": random.choice(POSITIONS),
"department": random.choice(DEPARTMENTS),
"interview_date": f"2024-12-{random.randint(1,28):02d}",
"status": status
or random.choice(["pending", "completed", "cancelled"]),
"rating": random.randint(1, 5) if status == "completed" else None,
}
)
# Filter
if department:
interviews = [i for i in interviews if i["department"] == department]
if status:
interviews = [i for i in interviews if i["status"] == status]
return {
"total": len(interviews),
"filters": {
"start_date": start_date,
"end_date": end_date,
"status": status,
"department": department,
},
"items": interviews,
}
@app.get("/api/hr/employees")
def list_employees(
keyword: Optional[str] = Query(None),
department: Optional[str] = Query(None),
status: Optional[str] = Query(None),
):
"""Search employees"""
count = random.randint(20, 40)
employees = []
for i in range(count):
employees.append(
{
"id": 2000 + i,
"name": random.choice(NAMES),
"employee_id": f"EMP{2000+i:04d}",
"department": department or random.choice(DEPARTMENTS),
"position": random.choice(POSITIONS),
"status": status or "active",
}
)
return {"total": len(employees), "items": employees}
@app.get("/api/hr/statistics/monthly")
def get_monthly_stats(year: int = Query(...), month: int = Query(..., ge=1, le=12)):
"""Get monthly HR statistics"""
return {
"period": f"{year}-{month:02d}",
"headcount": {
"total": 156,
"new_hires": random.randint(5, 15),
"resignations": random.randint(1, 5),
},
"interviews": {
"total": random.randint(30, 60),
"completed": random.randint(20, 40),
"pending": random.randint(5, 15),
},
"turnover_rate": round(random.uniform(0.01, 0.05), 3),
}
# ═══════════════════════════════════════════════════════════════════
# Health Check
# ═══════════════════════════════════════════════════════════════════
@app.get("/health")
def health():
return {"status": "ok", "timestamp": datetime.now().isoformat()}
# ═══════════════════════════════════════════════════════════════════
# Run Server
# ═══════════════════════════════════════════════════════════════════
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8080)