I think finished?

This commit is contained in:
Leons Aleksandrovs
2025-07-02 22:25:03 +03:00
parent acb81d671d
commit 46dd731eab
9 changed files with 129 additions and 27 deletions

Binary file not shown.

View File

@@ -6,7 +6,6 @@ conn = get_db()
def get_users(search):
# Get search param
search_param = f"%{search}%"
print(search_param)
# Generate cursor
cursor = conn.cursor()
@@ -25,29 +24,26 @@ def get_attendance(id):
# Set up query for worked hours, group by and ordered by date
cursor = conn.cursor()
cursor.execute("""
SELECT date, sum(hours_worked) as hours_worked, e.username
FROM Attendance a
JOIN Employees e ON a.employee_id = e.id
WHERE a.employee_id = ?
SELECT date, sum(hours_worked) as hours_worked
FROM Attendance
WHERE employee_id = ?
GROUP BY date
ORDER BY date DESC
""", (id,))
data = cursor.fetchall()
attendance = cursor.fetchall()
# Check if there's any attendance
if not data:
# Fetch username from database
# I am not using table JOIN because when theres no attendance, the query returns no rows (and shows user doesnt exist)
cursor.execute("SELECT username FROM Employees WHERE id = ?", (id,))
username = cursor.fetchone()
# Check if user exists
if not username:
return {"username": None, "attendance": []}
# Remove repetetive username, and return clean api response
username = data[0]["username"] # get username from first row
attendance = [
{"date": row["date"], "hours_worked": row["hours_worked"]}
for row in data
]
# Return clean api response
return {
"username": username,
"username": username[0],
"attendance": attendance
}

View File

@@ -19,6 +19,6 @@ app.add_middleware(
def list_users(s: str = None):
return get_users(s)
@app.get("/{eployee_id}")
def list_attendance(eployee_id: int):
return get_attendance(eployee_id)
@app.get("/{employee_id}")
def list_attendance(employee_id: int):
return get_attendance(employee_id)