api: add item count to /list endpoints (#1813) (#1829)

This commit is contained in:
Alessandro Ros 2023-05-18 20:05:59 +02:00 committed by GitHub
parent 13fb559f5f
commit e10055ad69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 3 deletions

View File

@ -449,6 +449,7 @@ func (a *api) onPathsList(ctx *gin.Context) {
return
}
data.ItemCount = len(data.Items)
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
if err != nil {
ctx.AbortWithStatus(http.StatusBadRequest)
@ -480,6 +481,7 @@ func (a *api) onRTSPConnsList(ctx *gin.Context) {
return
}
data.ItemCount = len(data.Items)
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
if err != nil {
ctx.AbortWithStatus(http.StatusBadRequest)
@ -512,6 +514,7 @@ func (a *api) onRTSPSessionsList(ctx *gin.Context) {
return
}
data.ItemCount = len(data.Items)
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
if err != nil {
ctx.AbortWithStatus(http.StatusBadRequest)
@ -559,6 +562,7 @@ func (a *api) onRTSPSConnsList(ctx *gin.Context) {
return
}
data.ItemCount = len(data.Items)
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
if err != nil {
ctx.AbortWithStatus(http.StatusBadRequest)
@ -591,6 +595,7 @@ func (a *api) onRTSPSSessionsList(ctx *gin.Context) {
return
}
data.ItemCount = len(data.Items)
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
if err != nil {
ctx.AbortWithStatus(http.StatusBadRequest)
@ -638,6 +643,7 @@ func (a *api) onRTMPConnsList(ctx *gin.Context) {
return
}
data.ItemCount = len(data.Items)
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
if err != nil {
ctx.AbortWithStatus(http.StatusBadRequest)
@ -685,6 +691,7 @@ func (a *api) onRTMPSConnsList(ctx *gin.Context) {
return
}
data.ItemCount = len(data.Items)
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
if err != nil {
ctx.AbortWithStatus(http.StatusBadRequest)
@ -732,6 +739,7 @@ func (a *api) onHLSMuxersList(ctx *gin.Context) {
return
}
data.ItemCount = len(data.Items)
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
if err != nil {
ctx.AbortWithStatus(http.StatusBadRequest)
@ -759,6 +767,7 @@ func (a *api) onWebRTCSessionsList(ctx *gin.Context) {
return
}
data.ItemCount = len(data.Items)
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
if err != nil {
ctx.AbortWithStatus(http.StatusBadRequest)

View File

@ -20,6 +20,7 @@ type apiPath struct {
}
type apiPathsList struct {
ItemCount int `json:"itemCount"`
PageCount int `json:"pageCount"`
Items []*apiPath `json:"items"`
}
@ -32,6 +33,7 @@ type apiHLSMuxer struct {
}
type apiHLSMuxersList struct {
ItemCount int `json:"itemCount"`
PageCount int `json:"pageCount"`
Items []*apiHLSMuxer `json:"items"`
}
@ -45,6 +47,7 @@ type apiRTSPConn struct {
}
type apiRTSPConnsList struct {
ItemCount int `json:"itemCount"`
PageCount int `json:"pageCount"`
Items []*apiRTSPConn `json:"items"`
}
@ -59,6 +62,7 @@ type apiRTMPConn struct {
}
type apiRTMPConnsList struct {
ItemCount int `json:"itemCount"`
PageCount int `json:"pageCount"`
Items []*apiRTMPConn `json:"items"`
}
@ -73,6 +77,7 @@ type apiRTSPSession struct {
}
type apiRTSPSessionsList struct {
ItemCount int `json:"itemCount"`
PageCount int `json:"pageCount"`
Items []*apiRTSPSession `json:"items"`
}
@ -90,6 +95,7 @@ type apiWebRTCSession struct {
}
type apiWebRTCSessionsList struct {
ItemCount int `json:"itemCount"`
PageCount int `json:"pageCount"`
Items []*apiWebRTCSession `json:"items"`
}

View File

@ -216,6 +216,7 @@ func TestAPIPathsList(t *testing.T) {
}
type pathList struct {
ItemCount int `json:"itemCount"`
PageCount int `json:"pageCount"`
Items []path `json:"items"`
}
@ -265,6 +266,7 @@ func TestAPIPathsList(t *testing.T) {
var out pathList
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v2/paths/list", nil, &out)
require.Equal(t, pathList{
ItemCount: 1,
PageCount: 1,
Items: []path{{
Name: "mypath",
@ -327,6 +329,7 @@ func TestAPIPathsList(t *testing.T) {
var out pathList
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v2/paths/list", nil, &out)
require.Equal(t, pathList{
ItemCount: 1,
PageCount: 1,
Items: []path{{
Name: "mypath",
@ -353,6 +356,7 @@ func TestAPIPathsList(t *testing.T) {
var out pathList
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v2/paths/list", nil, &out)
require.Equal(t, pathList{
ItemCount: 1,
PageCount: 1,
Items: []path{{
Name: "mypath",
@ -379,6 +383,7 @@ func TestAPIPathsList(t *testing.T) {
var out pathList
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v2/paths/list", nil, &out)
require.Equal(t, pathList{
ItemCount: 1,
PageCount: 1,
Items: []path{{
Name: "mypath",
@ -405,6 +410,7 @@ func TestAPIPathsList(t *testing.T) {
var out pathList
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v2/paths/list", nil, &out)
require.Equal(t, pathList{
ItemCount: 1,
PageCount: 1,
Items: []path{{
Name: "mypath",
@ -673,7 +679,8 @@ func TestAPIProtocolList(t *testing.T) {
}
var out struct {
Items []struct {
ItemCount int `json:"itemCount"`
Items []struct {
State string `json:"state"`
} `json:"items"`
}
@ -685,7 +692,8 @@ func TestAPIProtocolList(t *testing.T) {
case "hls":
var out struct {
Items []struct {
ItemCount int `json:"itemCount"`
Items []struct {
Created string `json:"created"`
LastRequest string `json:"lastRequest"`
} `json:"items"`
@ -708,7 +716,7 @@ func TestAPIProtocolList(t *testing.T) {
}
var out struct {
PageCount int `json:"pageCount"`
ItemCount int `json:"itemCount"`
Items []item `json:"items"`
}
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v2/webrtcsessions/list", nil, &out)