package controller import ( "github.com/gin-gonic/gin" "iot_manager_service/app/middleware" "iot_manager_service/app/multimedia/model" "iot_manager_service/app/multimedia/service" "iot_manager_service/util/common" "math" "net/http" "strconv" ) var PublishLibraries = new(PublishLibrariesCtl) type PublishLibrariesCtl struct{} func (c *PublishLibrariesCtl) List(ctx *gin.Context) { searchValue := ctx.Query("searchValue") current, _ := strconv.Atoi(ctx.Query("current")) size, _ := strconv.Atoi(ctx.Query("size")) if current == 0 { current = 1 } if size <= 0 || size > 100 { size = 10 } value, _ := ctx.Get(middleware.Authorization) claims := value.(*middleware.Claims) libraries, err := service.PublishLibrariesService.List(claims.TenantId, searchValue, current, size) if err != nil { ctx.JSON(http.StatusOK, err) return } pages := math.Ceil(float64(len(libraries)) / float64(size)) rsp := model.RsqPublishLibrariesList{ Current: current, Size: size, Total: len(libraries), Pages: int(pages), Records: libraries, } ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp)) }