forked from lnbits/jitsi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crud.py
119 lines (92 loc) · 2.89 KB
/
crud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# TODO(nochiel) API responses should be json so that we can get named fields in the client.
from base64 import urlsafe_b64encode
from uuid import uuid4
from typing import List, Optional, Union
from lnbits.core.crud import (
create_account,
create_wallet,
get_user,
)
from . import db
from .models import Conference, Participant
async def createConference(
conference: str,
admin: str,
) -> Conference:
assert conference != '', 'a conference id was not given'
print('crud.py.createConference: ', conference)
await db.execute(
'''
INSERT INTO jitsi.conferences (name, admin)
VALUES (? , ?)
''',
(conference, admin),
)
conference = await getConference(conference, admin)
assert conference, 'createConference failed'
return conference
async def getConference(
name: str,
admin: str
) -> Conference:
assert name != '', 'conference id is null'
assert admin != '', 'admin id is null'
row = await db.fetchone(
'''
SELECT * FROM jitsi.conferences
WHERE name = ? AND admin = ?
''',
(name, admin))
result = Conference(**row) if row else None
print('crud.py.getConference: result: ', result)
return result
async def getAllParticipants(
conference: str,
) -> List[Participant]:
rows = await db.fetchall(
'''
SELECT * FROM jitsi.participants
'''
)
# print('crud.py.getAllParticipants: rows', rows)
result = [Participant(**row) for row in rows]
return result
async def getParticipant(
conference: str,
participant: str
) -> Participant:
# print('crud.py.getParticipant')
# rows = await db.fetchall(
# '''
# SELECT * FROM jitsi.participants
# '''
# )
# print('crud.py.getParticipant: rows', rows)
row = await db.fetchone(
'''
SELECT * FROM jitsi.participants
WHERE id = ? AND conference = ?
''',
(participant, conference))
# print('crud.py.getParticipant: row: ', row)
return Participant(**row) if row else None
async def createParticipant(*,
participantId: str,
userId: str,
conferenceId : str,
walletId: str
) -> Participant:
assert participantId
assert userId
assert conferenceId
assert walletId
await db.execute(
"""
INSERT INTO jitsi.participants (id, user, conference, wallet)
VALUES (?, ?, ?, ?)
""",
(participantId, userId, conferenceId, walletId),
)
participant = await getParticipant(conferenceId, participantId)
assert participant, "newly created participant couldn't be retrieved"
return participant