first commit

This commit is contained in:
2025-09-17 08:36:17 +03:00
commit c2613de507
22 changed files with 1287 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,87 @@
import sqlite3
class DBApplications:
def __init__(self):
self.db_path = 'instance/dev.db'
self.create_table()
def create_table(self):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS applications (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
name TEXT NOT NULL UNIQUE,
access_code TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
status TEXT NOT NULL DEFAULT 'active'
);
""")
conn.commit()
def insert_application(self, user_id, name, access_code: str) -> bool:
try:
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("""
INSERT INTO applications (user_id, name, access_code)
VALUES (?, ?, ?)
""", (user_id, name, access_code))
conn.commit()
return True
except sqlite3.IntegrityError:
return False
def get_application_by_id(self, id):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("""
SELECT * FROM applications
WHERE id = ?
""", (id,))
row = cursor.fetchone()
if row:
return {
"id": row[0],
"user_id":row[1],
"name": row[2],
"access_code": row[3],
"created_at": row[4],
"status": row[5],
}
else:
return None
def get_applications(self, user_id):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("""
SELECT * FROM applications
WHERE user_id = ?
""", (user_id,))
rows = cursor.fetchall()
all_rows = []
if rows:
for row in rows:
row = {
"id": row[0],
"user_id":row[1],
"name": row[2],
"access_code": row[3],
"created_at": row[4],
"status": row[5],
}
all_rows.append(row)
return all_rows
else:
return all_rows
def delete(self, id):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("""
DELETE FROM applications WHERE id = ?
""", (id,))
conn.commit()

72
client/models/users.py Normal file
View File

@@ -0,0 +1,72 @@
import sqlite3
class Users:
def __init__(self):
self.db_path = 'instance/dev.db'
self.create_table()
def create_table(self):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
status TEXT NOT NULL DEFAULT 'active'
);
""")
conn.commit()
def insert_user(self, email, password: str) -> bool:
try:
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("""
INSERT INTO users (email, password)
VALUES (?, ?)
""", (email, password))
conn.commit()
return True
except sqlite3.IntegrityError:
return False
def get_user_by_id(self, id):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("""
SELECT * FROM users
WHERE id = ?
""", (id,))
row = cursor.fetchone()
if row:
return {
"id": row[0],
"email": row[1],
"password": row[2],
"created_at": row[3],
"status":row[4],
}
else:
return None
def get_user_by_email(self, email):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute("""
SELECT * FROM users
WHERE email = ?
""", (email,))
row = cursor.fetchone()
if row:
return {
"id": row[0],
"email": row[1],
"password": row[2],
"created_at": row[3],
"status":row[4],
}
else:
return None