opencode ergebnis V0.1

This commit is contained in:
concierge committed 2026-10-23 00:05:06 +02:00
1 parent 61d86a3d83
commit 7e498ebc3f
71 files changed
+28982 -46

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
from .accounts import AccountModel
from .groups import GroupModel
from .streets import StreetModel
+66
View File
@@ -0,0 +1,66 @@
"""
Account Model - Abstraktionsschicht für Datenbankzugriffe
"""
from cmbnet.db import get_db
class AccountModel:
@staticmethod
def get_all_by_tenant(tenant_id):
db = get_db()
return db.execute(
'SELECT * FROM accounts WHERE tenant_id = ? ORDER BY id',
(tenant_id,)
).fetchall()
@staticmethod
def get_by_id(account_id, tenant_id=None):
db = get_db()
if tenant_id:
return db.execute(
'SELECT * FROM accounts WHERE id = ? AND tenant_id = ?',
(account_id, tenant_id)
).fetchone()
return db.execute('SELECT * FROM accounts WHERE id = ?', (account_id,)).fetchone()
@staticmethod
def get_by_name_and_tenant(name, tenant_id):
db = get_db()
return db.execute(
'SELECT * FROM accounts WHERE name = ? AND tenant_id = ?',
(name, tenant_id)
).fetchone()
@staticmethod
def create(tenant_id, name, password_hash, role):
db = get_db()
cursor = db.execute(
'INSERT INTO accounts (tenant_id, name, password_hash, role) VALUES (?, ?, ?, ?)',
(tenant_id, name, password_hash, role)
)
db.commit()
return cursor.lastrowid
@staticmethod
def update_role(account_id, tenant_id, role):
db = get_db()
db.execute(
'UPDATE accounts SET role = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND tenant_id = ?',
(role, account_id, tenant_id)
)
db.commit()
@staticmethod
def set_password(account_id, tenant_id, password_hash):
db = get_db()
db.execute(
'UPDATE accounts SET password_hash = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND tenant_id = ?',
(password_hash, account_id, tenant_id)
)
db.commit()
@staticmethod
def delete(account_id, tenant_id):
db = get_db()
db.execute('DELETE FROM accounts WHERE id = ? AND tenant_id = ?', (account_id, tenant_id))
db.commit()
+63
View File
@@ -0,0 +1,63 @@
"""
Group Model - Abstraktionsschicht für Datenbankzugriffe
"""
from cmbnet.db import get_db
class GroupModel:
@staticmethod
def get_all_by_tenant(tenant_id):
db = get_db()
return db.execute(
'SELECT * FROM groups WHERE tenant_id = ? ORDER BY id',
(tenant_id,)
).fetchall()
@staticmethod
def get_by_id(group_id, tenant_id):
db = get_db()
return db.execute(
'SELECT * FROM groups WHERE id = ? AND tenant_id = ?',
(group_id, tenant_id)
).fetchone()
@staticmethod
def get_by_account_id(account_id, tenant_id):
db = get_db()
return db.execute(
'SELECT * FROM groups WHERE account_id = ? AND tenant_id = ?',
(account_id, tenant_id)
).fetchone()
@staticmethod
def create(tenant_id, aliasname, account_id=None, state='offen'):
db = get_db()
cursor = db.execute(
'INSERT INTO groups (tenant_id, aliasname, account_id, state) VALUES (?, ?, ?, ?)',
(tenant_id, aliasname, account_id, state)
)
db.commit()
return cursor.lastrowid
@staticmethod
def update(group_id, tenant_id, **kwargs):
db = get_db()
allowed = ['aliasname', 'state', 'account_id', 'last_lat', 'last_lon', 'last_pos_at']
updates = []
values = []
for k, v in kwargs.items():
if k in allowed:
updates.append(f'{k} = ?')
values.append(v)
if not updates:
return
updates.append('updated_at = CURRENT_TIMESTAMP')
values.extend([group_id, tenant_id])
db.execute(f'UPDATE groups SET {", ".join(updates)} WHERE id = ? AND tenant_id = ?', values)
db.commit()
@staticmethod
def delete(group_id, tenant_id):
db = get_db()
db.execute('DELETE FROM groups WHERE id = ? AND tenant_id = ?', (group_id, tenant_id))
db.commit()
+63
View File
@@ -0,0 +1,63 @@
"""
Street Model - Abstraktionsschicht für Datenbankzugriffe
"""
from cmbnet.db import get_db
class StreetModel:
@staticmethod
def get_all_by_tenant(tenant_id):
db = get_db()
return db.execute(
'SELECT * FROM streets WHERE tenant_id = ? ORDER BY name',
(tenant_id,)
).fetchall()
@staticmethod
def get_by_id(street_id, tenant_id):
db = get_db()
return db.execute(
'SELECT * FROM streets WHERE id = ? AND tenant_id = ?',
(street_id, tenant_id)
).fetchone()
@staticmethod
def get_by_group_id(group_id, tenant_id):
db = get_db()
return db.execute(
'SELECT * FROM streets WHERE group_id = ? AND tenant_id = ?',
(group_id, tenant_id)
).fetchall()
@staticmethod
def create(tenant_id, name, hn_min=None, hn_max=None, bbox=None, state='unbearbeitet', group_id=None):
db = get_db()
cursor = db.execute(
'INSERT INTO streets (tenant_id, name, hn_min, hn_max, bbox, state, group_id) VALUES (?, ?, ?, ?, ?, ?, ?)',
(tenant_id, name, hn_min, hn_max, bbox, state, group_id)
)
db.commit()
return cursor.lastrowid
@staticmethod
def update(street_id, tenant_id, **kwargs):
db = get_db()
allowed = ['name', 'state', 'group_id', 'hn_min', 'hn_max', 'bbox']
updates = []
values = []
for k, v in kwargs.items():
if k in allowed:
updates.append(f'{k} = ?')
values.append(v)
if not updates:
return
updates.append('updated_at = CURRENT_TIMESTAMP')
values.extend([street_id, tenant_id])
db.execute(f'UPDATE streets SET {", ".join(updates)} WHERE id = ? AND tenant_id = ?', values)
db.commit()
@staticmethod
def delete(street_id, tenant_id):
db = get_db()
db.execute('DELETE FROM streets WHERE id = ? AND tenant_id = ?', (street_id, tenant_id))
db.commit()