# This file is for database functions from db.db import get_db conn = get_db() def get_users(): cursor = conn.cursor() cursor.execute("SELECT * FROM Employees") users = cursor.fetchall() return users 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 = ? GROUP BY date ORDER BY date DESC """, (id,)) data = cursor.fetchall() # Check if there's any attendance if not data: 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, "attendance": attendance }