NOISSUE - Fix fetching connected clients
Property Based Tests / api-test (push) Has been cancelled
Continuous Delivery / lint-and-build (push) Has been cancelled
Deploy GitHub Pages / swagger-ui (push) Has been cancelled
CI Pipeline / Check Certs (push) Has been cancelled
CI Pipeline / Lint Proto (push) Has been cancelled
CI Pipeline / Detect Changes (push) Has been cancelled
Continuous Delivery / Build and Push Docker Images (push) Has been cancelled
CI Pipeline / lint-and-build (push) Has been cancelled
CI Pipeline / Test ${{ matrix.module }} (push) Has been cancelled
CI Pipeline / Upload Coverage (push) Has been cancelled

Signed-off-by: dusan <borovcanindusan1@gmail.com>
This commit is contained in:
dusan
2026-03-11 17:25:47 +01:00
parent df2446c2cc
commit 9c6ad9744e
2 changed files with 50 additions and 6 deletions
+9 -6
View File
@@ -538,9 +538,10 @@ func (repo *clientRepo) retrieveClients(ctx context.Context, domainID, userID st
final_clients c
`
connCountJoinQuery := connJoinQuery
if pm.Channel != "" {
connJoinQuery = `
,conn.connection_types
connCountJoinQuery = `
FROM
final_clients c
LEFT JOIN (
@@ -554,6 +555,8 @@ func (repo *clientRepo) retrieveClients(ctx context.Context, domainID, userID st
conn.client_id, conn.channel_id
) conn ON c.id = conn.client_id
`
connJoinQuery = `
,conn.connection_types` + connCountJoinQuery
}
dbPage, err := ToDBClientsPage(pm)
@@ -566,9 +569,9 @@ func (repo *clientRepo) retrieveClients(ctx context.Context, domainID, userID st
if pm.OnlyTotal {
cq := fmt.Sprintf(`%s
SELECT COUNT(*) AS total_count
FROM final_clients c
%s
%s;
`, bq, pageQuery)
`, bq, connCountJoinQuery, pageQuery)
total, err := postgres.Total(ctx, repo.DB, cq, dbPage)
if err != nil {
@@ -644,9 +647,9 @@ func (repo *clientRepo) retrieveClients(ctx context.Context, domainID, userID st
if len(items) == 0 {
cq := fmt.Sprintf(`%s
SELECT COUNT(*) AS total_count
FROM final_clients c
%s
%s;
`, bq, pageQuery)
`, bq, connCountJoinQuery, pageQuery)
total, err = postgres.Total(ctx, repo.DB, cq, dbPage)
if err != nil {
+41
View File
@@ -2783,6 +2783,47 @@ func TestRetrieveUserClients(t *testing.T) {
},
},
},
{
desc: "retrieve clients connected to a channel with only total",
domainID: domain.ID,
userID: userID,
pm: clients.Page{
Offset: 0,
Limit: 10,
Channel: channelID,
Status: clients.AllStatus,
OnlyTotal: true,
},
response: clients.ClientsPage{
Page: clients.Page{
Total: 1,
Offset: 0,
Limit: 10,
},
Clients: []clients.Client(nil),
},
},
{
desc: "retrieve clients connected to a non-existent channel",
domainID: domain.ID,
userID: userID,
pm: clients.Page{
Offset: 0,
Limit: 10,
Channel: testsutil.GenerateUUID(t),
Status: clients.AllStatus,
Order: defOrder,
Dir: ascDir,
},
response: clients.ClientsPage{
Page: clients.Page{
Total: 0,
Offset: 0,
Limit: 10,
},
Clients: []clients.Client(nil),
},
},
}
for _, tc := range cases {