Implemented search funcionality
This commit is contained in:
@@ -3,9 +3,21 @@ from db.db import get_db
|
|||||||
|
|
||||||
conn = get_db()
|
conn = get_db()
|
||||||
|
|
||||||
def get_users():
|
def get_users(search):
|
||||||
|
# Get search param
|
||||||
|
search_param = f"%{search}%"
|
||||||
|
print(search_param)
|
||||||
|
|
||||||
|
# Generate cursor
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("SELECT * FROM Employees")
|
|
||||||
|
# Search if needed
|
||||||
|
if search:
|
||||||
|
cursor.execute("SELECT * FROM Employees WHERE username LIKE ?", (search_param,))
|
||||||
|
else:
|
||||||
|
cursor.execute("SELECT * FROM Employees")
|
||||||
|
|
||||||
|
# Fetch users from database
|
||||||
users = cursor.fetchall()
|
users = cursor.fetchall()
|
||||||
return users
|
return users
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ app.add_middleware(
|
|||||||
)
|
)
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
def list_users():
|
def list_users(s: str = None):
|
||||||
return get_users()
|
return get_users(s)
|
||||||
|
|
||||||
@app.get("/{eployee_id}")
|
@app.get("/{eployee_id}")
|
||||||
def list_attendance(eployee_id: int):
|
def list_attendance(eployee_id: int):
|
||||||
|
|||||||
Reference in New Issue
Block a user