from models.database import Database from models.user import User from models.city import City class Search: @staticmethod def search_members(query): cur = Database.connection.cursor() cur.execute(""" SELECT * FROM users WHERE id LIKE ? OR username LIKE ? OR firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR phone LIKE ? """, (f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%")) rows = cur.fetchall() payload = [] for row in rows: user = User(Database.connection)._set_row_values(row) if user.role == "MEMBER": payload.append(user) return payload @staticmethod def search_advisors(query): cur = Database.connection.cursor() cur.execute(""" SELECT * FROM users WHERE id LIKE ? OR username LIKE ? OR firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR phone LIKE ? """, (f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%")) rows = cur.fetchall() payload = [] for row in rows: user = User(Database.connection)._set_row_values(row) if user.role == "ADVISOR": payload.append(user) return payload @staticmethod def search_admins(query): cur = Database.connection.cursor() cur.execute(""" SELECT * FROM users WHERE id LIKE ? OR username LIKE ? OR firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR phone LIKE ? """, (f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%")) rows = cur.fetchall() payload = [] for row in rows: user = User(Database.connection)._set_row_values(row) if user.role == "SYSTEM_ADMIN": payload.append(user) return payload @staticmethod def get_all_cites(): cur = Database.connection.cursor() cur.execute("SELECT * FROM cities") rows = cur.fetchall() payload = [] for row in rows: city = City(Database.connection)._set_row_values(row) payload.append(city) return payload