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

+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()