Skip to content

Commit 1cac1a8

Browse files
committed
[ADD] search uniqeid or linkedid
1 parent 39efbb1 commit 1cac1a8

4 files changed

Lines changed: 45 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ uvicorn main:app --host 127.0.0.1 --port 8082 --log-level debug
6464
```
6565
or
6666
```bash
67-
python3 -m uvicorn main:app --host 127.0.0.1 --port 8082 --log-level debug
67+
python3 -m uvicorn main:app --host 127.0.0.1 --port 8082 --log-level debug --workers 2
6868
```
6969

7070
### 2 Variant. Start on docker.

const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "1.0.9"
1+
VERSION = "1.1.0"

routers/history_calls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def calls_history_uniqueid(
2626
req.app.state.connector_database
2727
)
2828

29-
return await connector_database.get_cdr_uniqueid(uniqueid)
29+
return await connector_database.get_cdr_uniqueid_or_linkedid(uniqueid)
3030

3131

3232
@router.get("/api/calls/hisroty/")

services/database.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ async def get_cdr_uniqueid(self, uniqueid):
4949
uniqueid -- id of call in asterisk
5050
"""
5151

52+
async def get_cdr_uniqueid_or_linkedid(self, uniqueid):
53+
"""Return calls history
54+
55+
Arguments:
56+
uniqueid -- id of call in asterisk
57+
"""
58+
5259
async def get_cdr(self, start_date, end_date, uniqueid=None):
5360
"""Return calls history
5461
@@ -102,6 +109,20 @@ async def get_cdr_uniqueid(self, uniqueid):
102109
result.append(row)
103110
return result
104111

112+
async def get_cdr_uniqueid_or_linkedid(self, uniqueid):
113+
import aiosqlite
114+
115+
result = []
116+
async with aiosqlite.connect(self.config.db_host) as database:
117+
database.row_factory = aiosqlite.Row
118+
async with database.execute(
119+
f"SELECT * FROM {self.config.db_table_cdr_name} where uniqueid= %s or linkedid = %s;",
120+
[uniqueid, uniqueid],
121+
) as cursor:
122+
async for row in cursor:
123+
result.append(row)
124+
return result
125+
105126
async def get_cdr(self, start_date, end_date):
106127
import aiosqlite
107128

@@ -202,6 +223,17 @@ async def get_cdr_uniqueid(self, uniqueid):
202223
conn.close()
203224
return rows
204225

226+
async def get_cdr_uniqueid_or_linkedid(self, uniqueid):
227+
conn, cur = await self.get_conn_cur()
228+
await cur.execute(
229+
f"SELECT * FROM {self.config.db_table_cdr_name} where uniqueid = %s or linkedid = %s;",
230+
(uniqueid, uniqueid),
231+
)
232+
rows = await cur.fetchall()
233+
await cur.close()
234+
conn.close()
235+
return rows
236+
205237
async def get_cdr(self, start_date, end_date):
206238
conn, cur = await self.get_conn_cur()
207239
await cur.execute(
@@ -280,6 +312,16 @@ async def get_cdr_uniqueid(self, uniqueid):
280312
await conn.close()
281313
return rows
282314

315+
async def get_cdr_uniqueid_or_linkedid(self, uniqueid):
316+
conn, cur = await self.get_conn_cur()
317+
await cur.execute(
318+
f"SELECT * FROM {self.config.db_table_cdr_name} where uniqueid = %s or linkedid = %s;",
319+
(uniqueid, uniqueid),
320+
)
321+
rows = await cur.fetchall()
322+
await conn.close()
323+
return rows
324+
283325
async def get_cdr(self, start_date, end_date):
284326
conn, cur = await self.get_conn_cur()
285327
await cur.execute(

0 commit comments

Comments
 (0)