-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
82 lines (75 loc) · 1.97 KB
/
main.py
File metadata and controls
82 lines (75 loc) · 1.97 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
from fastapi import FastAPI
from schemas.student import Student
from config.db import con
from models.index import students
app=FastAPI()
@app.post('/api/students')
async def store(student: Student):
data=con.execute(students.insert().values(
name=student.name,
email=student.email,
age=student.age,
country=student.country,
))
if data.is_insert:
return {
"success": True,
"msg":"Student Store Successfully"
}
else:
return {
"success": False,
"msg":"Some Problem"
}
@app.get('/api/students')
async def index():
data=con.execute(students.select()).fetchall()
return {
"success": True,
"data":data
}
@app.get('/api/students/{search}')
async def search(search):
data=con.execute(students.select().where(students.c.name.like('%'+search+'%'))).fetchall()
return {
"success": True,
"data":data
}
@app.patch('/api/students/{id}')
async def edit_data(id: int):
data=con.execute(students.select().where(students.c.id==id)).fetchall()
return {
"success": True,
"data":data
}
@app.put('/api/students/{id}')
async def update(id: int, student: Student):
data=con.execute(students.update().values(
name=student.name,
email=student.email,
age=student.age,
country=student.country,
).where(students.c.id==id))
if data:
return {
"success": True,
"msg":"Student Update Successfully"
}
else:
return {
"success": False,
"msg":"Some Problem"
}
@app.delete('/api/students/{id}')
async def delete(id: int):
data=con.execute(students.delete().where(students.c.id==id))
if data:
return {
"success": True,
"msg":"Student Delete Successfully"
}
else:
return {
"success": False,
"msg":"Some Problem"
}